Changeset 6506


Ignore:
Timestamp:
Aug 13, 2008, 6:55:27 PM (13 years ago)
Author:
charles
Message:

update the regression tests to hammer tr_bitfieldRemRange() a little harder

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r6490 r6506  
    2323            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
    2424    } else { \
    25         if( VERBOSE ) \
    26             fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
     25        fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
    2726        return test; \
    2827    } \
     
    3635    tr_bitfield * field = tr_bitfieldNew( bitcount );
    3736
    38     /* make every seventh one true */
     37    /* test tr_bitfieldAdd */
    3938    for( i=0; i<bitcount; ++i )
    4039        if( !( i % 7 ) )
    4140            tr_bitfieldAdd( field, i );
    42 
    43     /* check to see if `has' has the right bits */
    4441    for( i=0; i<bitcount; ++i )
    4542        check( tr_bitfieldHas( field, i ) == (!(i%7)) );
    4643
    47 #if 0
    48     /* testing the "find next" function */
    49     check( tr_bitfieldFindTrue( field, 0, &pos ) );
    50     check( pos == 0 );
    51     check( tr_bitfieldFindTrue( field, 1, &pos ) );
    52     check( pos == 7 );
    53     check( tr_bitfieldFindTrue( field, 2, &pos ) );
    54     check( pos == 7 );
    55     check( tr_bitfieldFindTrue( field, 7, &pos ) );
    56     check( pos == 7 );
    57     check( tr_bitfieldFindTrue( field, 8, &pos ) );
    58     check( pos == 14 );
    59     check( tr_bitfieldFindTrue( field, 13, &pos ) );
    60     check( pos == 14 );
    61     check( tr_bitfieldFindTrue( field, 14, &pos ) );
    62     check( pos == 14 );
    63     check( tr_bitfieldFindTrue( field, 15, &pos ) );
    64     check( pos == 21 );
    65     check( tr_bitfieldFindTrue( field, 16, &pos ) );
    66     check( pos == 21 );
    67 #endif
     44    /* test tr_bitfieldAddRange */
     45    tr_bitfieldAddRange( field, 0, bitcount );
     46    for( i=0; i<bitcount; ++i )
     47        check( tr_bitfieldHas( field, i ) );
     48
     49    /* test tr_bitfieldRemRange in the middle of a boundary */
     50    tr_bitfieldRemRange( field, 4, 21 );
     51    for( i=0; i<64; ++i )
     52        check( tr_bitfieldHas( field, i ) == ( ( i < 4 ) || ( i >= 21 ) ) );
     53
     54    /* test tr_bitfieldRemRange on the boundaries */
     55    tr_bitfieldAddRange( field, 0, 64 );
     56    tr_bitfieldRemRange( field, 8, 24 );
     57    for( i=0; i<64; ++i )
     58        check( tr_bitfieldHas( field, i ) == ( ( i < 8 ) || ( i >= 24 ) ) );
     59
     60    /* test tr_bitfieldRemRange when begin & end is on the same word */
     61    tr_bitfieldAddRange( field, 0, 64 );
     62    tr_bitfieldRemRange( field, 4, 5 );
     63    for( i=0; i<64; ++i )
     64        check( tr_bitfieldHas( field, i ) == ( ( i < 4 ) || ( i >= 5 ) ) );
    6865
    6966    tr_bitfieldFree( field );
    7067    return 0;
    7168}
    72 
    73 
    7469
    7570int
Note: See TracChangeset for help on using the changeset viewer.