Mercurial > dedupe
view TestBitArray.cpp @ 115:404795616b1e default tip
Added a lot of common files to ignore
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Sat, 25 Mar 2017 17:43:57 +0100 |
| parents | 247adcbbaf8b |
| children |
line wrap: on
line source
#include "TestFramework.hpp" #include "BitDecoder.hpp" BOOST_AUTO_TEST_CASE( TestBasic ) { { BitArray tbits(16, true); BitArray fbits(16, false); for (uint i = 0; i < tbits.size(); ++i) { BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); } } { BitArray tbits(9, true); BitArray fbits(9, false); for (uint i = 0; i < tbits.size(); ++i) { BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); } } { BitArray tbits(13, true); BitArray fbits(13, false); for (uint i = 0; i < tbits.size(); ++i) { BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); } } } BOOST_AUTO_TEST_CASE( TestSetBit ) { for (uint i = 0; i < 13; ++i) { BitArray tbits(13, true); BitArray fbits(13, false); tbits.setBit(i, false); fbits.setBit(i, true); for (uint j = 0; j < tbits.size(); ++j) { BOOST_REQUIRE_EQUAL(tbits.testBit(j), i != j); BOOST_REQUIRE_EQUAL(fbits.testBit(j), i == j); } } } BOOST_AUTO_TEST_CASE( TestSetBit2 ) { BitArray tbits(8, true); BitArray fbits(8, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("11111111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); tbits.setBit(0, false); fbits.setBit(0, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); tbits.setBit(1, true); fbits.setBit(1, true); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); tbits.setBit(2, false); fbits.setBit(2, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01011111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); tbits.setBit(3, false); fbits.setBit(3, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01001111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); tbits.setBit(4, false); fbits.setBit(4, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); tbits.setBit(5, true); fbits.setBit(5, true); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000100")); tbits.setBit(6, true); fbits.setBit(6, true); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); tbits.setBit(7, false); fbits.setBit(7, false); BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000110")); BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); } BOOST_AUTO_TEST_CASE( TestPaddedChar ) { BitArray bits = BitDecoder::bitsFromString("0100011011"); BOOST_REQUIRE_EQUAL(bits.size(), 10u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 70); bits = BitDecoder::bitsFromString("0000000001"); BOOST_REQUIRE_EQUAL(bits.size(), 10u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 1u); bits = BitDecoder::bitsFromString("0000000011"); BOOST_REQUIRE_EQUAL(bits.size(), 10u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 3u); bits = BitDecoder::bitsFromString("000000000011"); BOOST_REQUIRE_EQUAL(bits.size(), 12u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 3u); bits = BitDecoder::bitsFromString("0000000000011"); BOOST_REQUIRE_EQUAL(bits.size(), 13u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 3u); bits = BitDecoder::bitsFromString("00000000000011"); BOOST_REQUIRE_EQUAL(bits.size(), 14u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 3u); bits = BitDecoder::bitsFromString("000000000000011"); BOOST_REQUIRE_EQUAL(bits.size(), 15u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 3u); bits = BitDecoder::bitsFromString("10000001"); BOOST_REQUIRE_EQUAL(bits.size(), 8u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 129u); bits = BitDecoder::bitsFromString("010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 9u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(1), 129u); bits = BitDecoder::bitsFromString("0010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 10u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 129u); bits = BitDecoder::bitsFromString("00010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 11u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(3), 129u); bits = BitDecoder::bitsFromString("000010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 12u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 129u); bits = BitDecoder::bitsFromString("0000010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 13u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 129u); bits = BitDecoder::bitsFromString("00000010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 14u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 129u); bits = BitDecoder::bitsFromString("000000010000001"); BOOST_REQUIRE_EQUAL(bits.size(), 15u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 129u); bits = BitDecoder::bitsFromString("0100011011"); BOOST_REQUIRE_EQUAL(bits.size(), 10u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 27u); } BOOST_AUTO_TEST_CASE( TestCorrectChar ) { BitArray bits = BitDecoder::bitsFromString("00000001"); BOOST_REQUIRE_EQUAL(bits.size(), 8u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 1u); bits = BitDecoder::bitsFromString("00000011"); BOOST_REQUIRE_EQUAL(bits.size(), 8u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 3u); bits = BitDecoder::bitsFromString("10000000"); BOOST_REQUIRE_EQUAL(bits.size(), 8u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 128u); bits = BitDecoder::bitsFromString("11000000"); BOOST_REQUIRE_EQUAL(bits.size(), 8u); BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 192u); }
