#include "sys.h" #include "debug.h" #include "bitsetTest.h" static char const* const sb_str[] = { "1", // bit 0 "40", // bit 6 "1000", // bit 12 "40000", // bit 18 "1000000", // bit 24 "40000000", // bit 30 "1000000000", // bit 36 "40000000000", // bit 42 "1000000000000", // bit 48 "40000000000000", // bit 54 "1000000000000000", // bit 60 "40000000000000000", // bit 66 "1000000000000000000", // bit 72 "40000000000000000000", // bit 78 "1000000000000000000000", // bit 84 "40000000000000000000000", // bit 90 "1000000000000000000000000", // bit 96 "40000000000000000000000000", // bit 102 "1000000000000000000000000000", // bit 108 "40000000000000000000000000000", // bit 114 "1000000000000000000000000000000", // bit 120 "40000000000000000000000000000000", // bit 126 }; template void bitsetTest::testBitOpsLevel3(void) { if (b >= n) return; libecc::bitset const zeros("0"); libecc::bitset const ones("FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF"); libecc::bitset const tmp1(sb_str[b / 6]); libecc::bitset tmp2 = zeros; CPPUNIT_ASSERT( !tmp2.template test() ); CPPUNIT_ASSERT( !tmp2.any() ); tmp2.template set(); CPPUNIT_ASSERT( tmp1 == tmp2 ); CPPUNIT_ASSERT( tmp2.template test() ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.template clear(); CPPUNIT_ASSERT( tmp2 == zeros ); tmp2.template flip(); CPPUNIT_ASSERT( tmp2 == tmp1 ); tmp2.template flip(); CPPUNIT_ASSERT( tmp2 == zeros ); tmp2 = ones; CPPUNIT_ASSERT( tmp2.template test() ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.template clear(); libecc::bitset tmp3 = ones ^ tmp1; CPPUNIT_ASSERT( tmp2 == tmp3 ); CPPUNIT_ASSERT( !tmp2.template test() ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.template set(); CPPUNIT_ASSERT( tmp2 == ones ); tmp2.template flip(); CPPUNIT_ASSERT( tmp2 == tmp3 ); tmp2.template flip(); CPPUNIT_ASSERT( tmp2 == ones ); } template void bitsetTest::testBitOpsLevel2(void) { libecc::bitset const zeros("0"); libecc::bitset const ones("FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF"); for (unsigned int b = 0; b < n; b += 6) { libecc::bitset const tmp1(sb_str[b / 6]); libecc::bitset tmp2 = zeros; CPPUNIT_ASSERT( !tmp2.test(b) ); CPPUNIT_ASSERT( !tmp2.any() ); tmp2.set(b); CPPUNIT_ASSERT( tmp1 == tmp2 ); CPPUNIT_ASSERT( tmp2.test(b) ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.clear(b); CPPUNIT_ASSERT( tmp2 == zeros ); tmp2.flip(b); CPPUNIT_ASSERT( tmp2 == tmp1 ); tmp2.flip(b); CPPUNIT_ASSERT( tmp2 == zeros ); tmp2 = ones; CPPUNIT_ASSERT( tmp2.test(b) ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.clear(b); libecc::bitset tmp3 = ones ^ tmp1; CPPUNIT_ASSERT( tmp2 == tmp3 ); CPPUNIT_ASSERT( !tmp2.test(b) ); CPPUNIT_ASSERT( tmp2.any() ); tmp2.set(b); CPPUNIT_ASSERT( tmp2 == ones ); tmp2.flip(b); CPPUNIT_ASSERT( tmp2 == tmp3 ); tmp2.flip(b); CPPUNIT_ASSERT( tmp2 == ones ); } #ifndef FASTTEST testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); #endif testBitOpsLevel3(); #ifndef FASTTEST testBitOpsLevel3(); testBitOpsLevel3(); testBitOpsLevel3(); #endif } void bitsetTest::testBitOps(void) { #ifndef FASTTEST testBitOpsLevel2<13>(); testBitOpsLevel2<32>(); testBitOpsLevel2<45>(); testBitOpsLevel2<64>(); testBitOpsLevel2<77>(); testBitOpsLevel2<96>(); #endif testBitOpsLevel2<109>(); #ifndef FASTTEST testBitOpsLevel2<128>(); #endif }