Ejemplo n.º 1
0
/* =============================================================================
 * bitmap_getNumClear
 * =============================================================================
 */
long
bitmap_getNumClear (bitmap_t* bitmapPtr)
{
    long numBit = bitmapPtr->numBit;

    return (numBit - bitmap_getNumSet(bitmapPtr));
}
Ejemplo n.º 2
0
int
main ()
{
    long numNode = 100;

    puts("Starting tests...");

    bool_t status;

    net_t* netPtr = net_alloc(numNode);
    assert(netPtr);
    bitmap_t* visitedBitmapPtr = bitmap_alloc(numNode);
    assert(visitedBitmapPtr);
    queue_t* workQueuePtr = queue_alloc(-1);
    assert(workQueuePtr);

    assert(!net_isCycle(netPtr));

    long aId = 31;
    long bId = 14;
    long cId = 5;
    long dId = 92;

    net_applyOperation(netPtr, OPERATION_INSERT, aId, bId);
    assert(net_isPath(netPtr, aId, bId, visitedBitmapPtr, workQueuePtr));
    assert(!net_isPath(netPtr, bId, aId, visitedBitmapPtr, workQueuePtr));
    assert(!net_isPath(netPtr, aId, cId, visitedBitmapPtr, workQueuePtr));
    assert(!net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr));
    assert(!net_isCycle(netPtr));

    net_applyOperation(netPtr, OPERATION_INSERT, bId, cId);
    net_applyOperation(netPtr, OPERATION_INSERT, aId, cId);
    net_applyOperation(netPtr, OPERATION_INSERT, dId, aId);
    assert(!net_isCycle(netPtr));
    net_applyOperation(netPtr, OPERATION_INSERT, cId, dId);
    assert(net_isCycle(netPtr));
    net_applyOperation(netPtr, OPERATION_REVERSE, cId, dId);
    assert(!net_isCycle(netPtr));
    net_applyOperation(netPtr, OPERATION_REVERSE, dId, cId);
    assert(net_isCycle(netPtr));
    assert(net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr));
    net_applyOperation(netPtr, OPERATION_REMOVE, cId, dId);
    assert(!net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr));

    bitmap_t* ancestorBitmapPtr = bitmap_alloc(numNode);
    assert(ancestorBitmapPtr);
    status = net_findAncestors(netPtr, cId, ancestorBitmapPtr, workQueuePtr);
    assert(status);
    assert(bitmap_isSet(ancestorBitmapPtr, aId));
    assert(bitmap_isSet(ancestorBitmapPtr, bId));
    assert(bitmap_isSet(ancestorBitmapPtr, dId));
    assert(bitmap_getNumSet(ancestorBitmapPtr) == 3);

    bitmap_t* descendantBitmapPtr = bitmap_alloc(numNode);
    assert(descendantBitmapPtr);
    status = net_findDescendants(netPtr, aId, descendantBitmapPtr, workQueuePtr);
    assert(status);
    assert(bitmap_isSet(descendantBitmapPtr, bId));
    assert(bitmap_isSet(descendantBitmapPtr, cId));
    assert(bitmap_getNumSet(descendantBitmapPtr) == 2);

    bitmap_free(visitedBitmapPtr);
    queue_free(workQueuePtr);
    bitmap_free(ancestorBitmapPtr);
    bitmap_free(descendantBitmapPtr);
    net_free(netPtr);

    random_t* randomPtr = random_alloc();
    assert(randomPtr);
    netPtr = net_alloc(numNode);
    assert(netPtr);
    net_generateRandomEdges(netPtr, 10, 10, randomPtr);
    net_free(netPtr);

    puts("All tests passed.");

    return 0;
}
Ejemplo n.º 3
0
int
main ()
{
    bitmap_t* bitmapPtr;
    long numBit = 32;
    long i;
    long j;

    srand(0);

    puts("Starting...");

    bitmapPtr = bitmap_alloc(numBit);

    assert(bitmapPtr->numBit == numBit);
    assert(bitmapPtr->numWord == (DIVIDE_AND_ROUND_UP(numBit, NUM_BIT_PER_WORD)));

    /* Check that initial is all clear */
    for (i = 0; i < numBit; i++) {
        assert(bitmap_isClear(bitmapPtr, i));
        assert(!bitmap_isSet(bitmapPtr, i));
    }
    assert(bitmap_getNumClear(bitmapPtr) == numBit);
    assert(bitmap_getNumSet(bitmapPtr) == 0);

    /* Check bounds */
    assert(!bitmap_clear(bitmapPtr, -1));
    assert(!bitmap_set(bitmapPtr, -1));
    assert(!bitmap_clear(bitmapPtr, numBit+1));
    assert(!bitmap_set(bitmapPtr, numBit+1));

    /* Set random bits */
    for (i = 0, j = 0; i < numBit; i+=(rand() % 5 + 1)) {
        assert(bitmap_set(bitmapPtr, i));
        assert(bitmap_set(bitmapPtr, i));
        assert(bitmap_clear(bitmapPtr, i));
        assert(bitmap_set(bitmapPtr, i));
        assert(bitmap_set(bitmapPtr, i));
        assert(bitmap_isSet(bitmapPtr, i));
        j++;
    }
    assert(bitmap_getNumClear(bitmapPtr) == (numBit - j));
    assert(bitmap_getNumSet(bitmapPtr) == j);

    /* Clear set bits */
    while ((i = bitmap_findSet(bitmapPtr, -1)) >= 0) {
        assert(bitmap_clear(bitmapPtr, i));
        i++;
    }
    assert(bitmap_getNumClear(bitmapPtr) == numBit);
    assert(bitmap_getNumSet(bitmapPtr) == 0);
    assert(bitmap_findSet(bitmapPtr, -1) == -1);

    /* Set all bits */
    i = -1;
    while ((i = bitmap_findClear(bitmapPtr, i)) >= 0) {
        assert(bitmap_set(bitmapPtr, i));
        i++;
    }
    assert(bitmap_getNumClear(bitmapPtr) == 0);
    assert(bitmap_getNumSet(bitmapPtr) == numBit);
    assert(bitmap_findClear(bitmapPtr, -1) == -1);

    /* Clear random bits */
    for (i = 0, j = 0; i < numBit; i+=(rand() % 5 + 1)) {
        assert(bitmap_clear(bitmapPtr, i));
        assert(bitmap_clear(bitmapPtr, i));
        assert(bitmap_set(bitmapPtr, i));
        assert(bitmap_clear(bitmapPtr, i));
        assert(bitmap_clear(bitmapPtr, i));
        assert(bitmap_isClear(bitmapPtr, i));
        j++;
    }
    assert(bitmap_getNumClear(bitmapPtr) == j);
    assert(bitmap_getNumSet(bitmapPtr) == (numBit - j));

    bitmap_free(bitmapPtr);

    puts("All tests passed.");

    return 0;
}