Mercurial > dedupe
comparison BurnBitArray.cpp @ 76:8136057988bc
Fixes to automatic report generating system.
A lot of new unittests.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Sat, 16 Feb 2013 15:32:20 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 75:aaf0a2878f67 | 76:8136057988bc |
|---|---|
| 1 #include "TestFramework.hpp" | |
| 2 | |
| 3 #include "BitDecoder.hpp" | |
| 4 | |
| 5 #define BURN_MAX 100000 | |
| 6 #define BURN for(size_t burn_counter = BURN_MAX; burn_counter > 0; --burn_counter) | |
| 7 | |
| 8 BOOST_AUTO_TEST_CASE( TestBasic ) | |
| 9 { | |
| 10 BURN { | |
| 11 BitArray tbits(16, true); | |
| 12 BitArray fbits(16, false); | |
| 13 for (uint i = 0; i < tbits.size(); ++i) { | |
| 14 BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); | |
| 15 BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); | |
| 16 } | |
| 17 } | |
| 18 | |
| 19 BURN { | |
| 20 BitArray tbits(9, true); | |
| 21 BitArray fbits(9, false); | |
| 22 for (uint i = 0; i < tbits.size(); ++i) { | |
| 23 BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); | |
| 24 BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 BURN { | |
| 29 BitArray tbits(13, true); | |
| 30 BitArray fbits(13, false); | |
| 31 for (uint i = 0; i < tbits.size(); ++i) { | |
| 32 BOOST_REQUIRE_EQUAL(tbits.testBit(i), true); | |
| 33 BOOST_REQUIRE_EQUAL(fbits.testBit(i), false); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 } | |
| 38 | |
| 39 | |
| 40 BOOST_AUTO_TEST_CASE( TestSetBit ) | |
| 41 { | |
| 42 | |
| 43 BURN { | |
| 44 for (uint i = 0; i < 13; ++i) { | |
| 45 BitArray tbits(13, true); | |
| 46 BitArray fbits(13, false); | |
| 47 tbits.setBit(i, false); | |
| 48 fbits.setBit(i, true); | |
| 49 for (uint j = 0; j < tbits.size(); ++j) { | |
| 50 BOOST_REQUIRE_EQUAL(tbits.testBit(j), i != j); | |
| 51 BOOST_REQUIRE_EQUAL(fbits.testBit(j), i == j); | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 } | |
| 57 | |
| 58 BOOST_AUTO_TEST_CASE( TestSetBit2 ) | |
| 59 { | |
| 60 BURN { | |
| 61 BitArray tbits(8, true); | |
| 62 BitArray fbits(8, false); | |
| 63 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("11111111")); | |
| 64 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); | |
| 65 | |
| 66 tbits.setBit(0, false); | |
| 67 fbits.setBit(0, false); | |
| 68 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); | |
| 69 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); | |
| 70 | |
| 71 tbits.setBit(1, true); | |
| 72 fbits.setBit(1, true); | |
| 73 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); | |
| 74 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 75 | |
| 76 tbits.setBit(2, false); | |
| 77 fbits.setBit(2, false); | |
| 78 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01011111")); | |
| 79 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 80 | |
| 81 tbits.setBit(3, false); | |
| 82 fbits.setBit(3, false); | |
| 83 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01001111")); | |
| 84 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 85 | |
| 86 tbits.setBit(4, false); | |
| 87 fbits.setBit(4, false); | |
| 88 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 89 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 90 | |
| 91 tbits.setBit(5, true); | |
| 92 fbits.setBit(5, true); | |
| 93 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 94 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000100")); | |
| 95 | |
| 96 tbits.setBit(6, true); | |
| 97 fbits.setBit(6, true); | |
| 98 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 99 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); | |
| 100 | |
| 101 tbits.setBit(7, false); | |
| 102 fbits.setBit(7, false); | |
| 103 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000110")); | |
| 104 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); | |
| 105 | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 BOOST_AUTO_TEST_CASE( TestPaddedChar ) | |
| 110 { | |
| 111 BURN { | |
| 112 BitArray bits = BitDecoder::bitsFromString("0100011011"); | |
| 113 | |
| 114 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 115 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 70); | |
| 116 | |
| 117 bits = BitDecoder::bitsFromString("0000000001"); | |
| 118 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 119 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 1u); | |
| 120 | |
| 121 bits = BitDecoder::bitsFromString("0000000011"); | |
| 122 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 123 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 3u); | |
| 124 | |
| 125 bits = BitDecoder::bitsFromString("000000000011"); | |
| 126 BOOST_REQUIRE_EQUAL(bits.size(), 12u); | |
| 127 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 3u); | |
| 128 | |
| 129 bits = BitDecoder::bitsFromString("0000000000011"); | |
| 130 BOOST_REQUIRE_EQUAL(bits.size(), 13u); | |
| 131 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 3u); | |
| 132 | |
| 133 bits = BitDecoder::bitsFromString("00000000000011"); | |
| 134 BOOST_REQUIRE_EQUAL(bits.size(), 14u); | |
| 135 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 3u); | |
| 136 | |
| 137 bits = BitDecoder::bitsFromString("000000000000011"); | |
| 138 BOOST_REQUIRE_EQUAL(bits.size(), 15u); | |
| 139 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 3u); | |
| 140 | |
| 141 bits = BitDecoder::bitsFromString("10000001"); | |
| 142 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 143 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 129u); | |
| 144 | |
| 145 bits = BitDecoder::bitsFromString("010000001"); | |
| 146 BOOST_REQUIRE_EQUAL(bits.size(), 9u); | |
| 147 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(1), 129u); | |
| 148 | |
| 149 bits = BitDecoder::bitsFromString("0010000001"); | |
| 150 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 151 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 129u); | |
| 152 | |
| 153 bits = BitDecoder::bitsFromString("00010000001"); | |
| 154 BOOST_REQUIRE_EQUAL(bits.size(), 11u); | |
| 155 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(3), 129u); | |
| 156 | |
| 157 bits = BitDecoder::bitsFromString("000010000001"); | |
| 158 BOOST_REQUIRE_EQUAL(bits.size(), 12u); | |
| 159 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 129u); | |
| 160 | |
| 161 bits = BitDecoder::bitsFromString("0000010000001"); | |
| 162 BOOST_REQUIRE_EQUAL(bits.size(), 13u); | |
| 163 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 129u); | |
| 164 | |
| 165 bits = BitDecoder::bitsFromString("00000010000001"); | |
| 166 BOOST_REQUIRE_EQUAL(bits.size(), 14u); | |
| 167 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 129u); | |
| 168 | |
| 169 bits = BitDecoder::bitsFromString("000000010000001"); | |
| 170 BOOST_REQUIRE_EQUAL(bits.size(), 15u); | |
| 171 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 129u); | |
| 172 | |
| 173 | |
| 174 bits = BitDecoder::bitsFromString("0100011011"); | |
| 175 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 176 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 27u); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 BOOST_AUTO_TEST_CASE( TestCorrectChar ) | |
| 181 { | |
| 182 BURN { | |
| 183 BitArray bits = BitDecoder::bitsFromString("00000001"); | |
| 184 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 185 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 1u); | |
| 186 | |
| 187 bits = BitDecoder::bitsFromString("00000011"); | |
| 188 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 189 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 3u); | |
| 190 | |
| 191 bits = BitDecoder::bitsFromString("10000000"); | |
| 192 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 193 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 128u); | |
| 194 bits = BitDecoder::bitsFromString("11000000"); | |
| 195 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 196 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 192u); | |
| 197 } | |
| 198 } |
