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

This commit is contained in:
Charles Kerr
2008-08-13 18:55:27 +00:00
parent e8946b8691
commit 540c68ee01

View File

@@ -22,8 +22,7 @@ static int test = 0;
if( VERBOSE ) \
fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
} else { \
if( VERBOSE ) \
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
return test; \
} \
}
@@ -35,43 +34,39 @@ test_bitfields( void )
int bitcount = 5000000;
tr_bitfield * field = tr_bitfieldNew( bitcount );
/* make every seventh one true */
/* test tr_bitfieldAdd */
for( i=0; i<bitcount; ++i )
if( !( i % 7 ) )
tr_bitfieldAdd( field, i );
/* check to see if `has' has the right bits */
for( i=0; i<bitcount; ++i )
check( tr_bitfieldHas( field, i ) == (!(i%7)) );
#if 0
/* testing the "find next" function */
check( tr_bitfieldFindTrue( field, 0, &pos ) );
check( pos == 0 );
check( tr_bitfieldFindTrue( field, 1, &pos ) );
check( pos == 7 );
check( tr_bitfieldFindTrue( field, 2, &pos ) );
check( pos == 7 );
check( tr_bitfieldFindTrue( field, 7, &pos ) );
check( pos == 7 );
check( tr_bitfieldFindTrue( field, 8, &pos ) );
check( pos == 14 );
check( tr_bitfieldFindTrue( field, 13, &pos ) );
check( pos == 14 );
check( tr_bitfieldFindTrue( field, 14, &pos ) );
check( pos == 14 );
check( tr_bitfieldFindTrue( field, 15, &pos ) );
check( pos == 21 );
check( tr_bitfieldFindTrue( field, 16, &pos ) );
check( pos == 21 );
#endif
/* test tr_bitfieldAddRange */
tr_bitfieldAddRange( field, 0, bitcount );
for( i=0; i<bitcount; ++i )
check( tr_bitfieldHas( field, i ) );
/* test tr_bitfieldRemRange in the middle of a boundary */
tr_bitfieldRemRange( field, 4, 21 );
for( i=0; i<64; ++i )
check( tr_bitfieldHas( field, i ) == ( ( i < 4 ) || ( i >= 21 ) ) );
/* test tr_bitfieldRemRange on the boundaries */
tr_bitfieldAddRange( field, 0, 64 );
tr_bitfieldRemRange( field, 8, 24 );
for( i=0; i<64; ++i )
check( tr_bitfieldHas( field, i ) == ( ( i < 8 ) || ( i >= 24 ) ) );
/* test tr_bitfieldRemRange when begin & end is on the same word */
tr_bitfieldAddRange( field, 0, 64 );
tr_bitfieldRemRange( field, 4, 5 );
for( i=0; i<64; ++i )
check( tr_bitfieldHas( field, i ) == ( ( i < 4 ) || ( i >= 5 ) ) );
tr_bitfieldFree( field );
return 0;
}
int
main( void )
{