Mercurial > dedupe
comparison TestBitArray.cpp @ 51:0bd3c1c46251
More extensive testing of BitArray.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 13 Sep 2012 23:14:40 +0200 |
| parents | b23f04d4a276 |
| children | bd7ca4ceefec |
comparison
equal
deleted
inserted
replaced
| 50:f9fa7ea71d37 | 51:0bd3c1c46251 |
|---|---|
| 1 #include "BitArray.hpp" | 1 #include "BitArray.hpp" |
| 2 #include "TestFramework.hpp" | 2 #include "TestFramework.hpp" |
| 3 | 3 |
| 4 #include <QtCore/QDebug> | 4 #include "BitDecoder.hpp" |
| 5 | 5 |
| 6 BOOST_AUTO_TEST_CASE( TestBasic ) | 6 BOOST_AUTO_TEST_CASE( TestBasic ) |
| 7 { | 7 { |
| 8 { | 8 { |
| 9 BitArray tbits(16, true); | 9 BitArray tbits(16, true); |
| 48 BOOST_REQUIRE_EQUAL(fbits.testBit(j), i == j); | 48 BOOST_REQUIRE_EQUAL(fbits.testBit(j), i == j); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 } | 52 } |
| 53 | |
| 54 BOOST_AUTO_TEST_CASE( TestSetBit2 ) | |
| 55 { | |
| 56 BitArray tbits(8, true); | |
| 57 BitArray fbits(8, false); | |
| 58 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("11111111")); | |
| 59 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); | |
| 60 | |
| 61 tbits.setBit(0, false); | |
| 62 fbits.setBit(0, false); | |
| 63 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); | |
| 64 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000")); | |
| 65 | |
| 66 tbits.setBit(1, true); | |
| 67 fbits.setBit(1, true); | |
| 68 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111")); | |
| 69 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 70 | |
| 71 tbits.setBit(2, false); | |
| 72 fbits.setBit(2, false); | |
| 73 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01011111")); | |
| 74 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 75 | |
| 76 tbits.setBit(3, false); | |
| 77 fbits.setBit(3, false); | |
| 78 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01001111")); | |
| 79 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 80 | |
| 81 tbits.setBit(4, false); | |
| 82 fbits.setBit(4, false); | |
| 83 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 84 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000")); | |
| 85 | |
| 86 tbits.setBit(5, true); | |
| 87 fbits.setBit(5, true); | |
| 88 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 89 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000100")); | |
| 90 | |
| 91 tbits.setBit(6, true); | |
| 92 fbits.setBit(6, true); | |
| 93 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111")); | |
| 94 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); | |
| 95 | |
| 96 tbits.setBit(7, false); | |
| 97 fbits.setBit(7, false); | |
| 98 BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000110")); | |
| 99 BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110")); | |
| 100 | |
| 101 | |
| 102 } | |
| 103 | |
| 104 BOOST_AUTO_TEST_CASE( TestPaddedChar ) | |
| 105 { | |
| 106 BitArray bits = BitDecoder::bitsFromString("0100011011"); | |
| 107 | |
| 108 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 109 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 70); | |
| 110 | |
| 111 bits = BitDecoder::bitsFromString("0000000001"); | |
| 112 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 113 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 1u); | |
| 114 | |
| 115 bits = BitDecoder::bitsFromString("0000000011"); | |
| 116 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 117 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 3u); | |
| 118 | |
| 119 bits = BitDecoder::bitsFromString("000000000011"); | |
| 120 BOOST_REQUIRE_EQUAL(bits.size(), 12u); | |
| 121 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 3u); | |
| 122 | |
| 123 bits = BitDecoder::bitsFromString("0000000000011"); | |
| 124 BOOST_REQUIRE_EQUAL(bits.size(), 13u); | |
| 125 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 3u); | |
| 126 | |
| 127 bits = BitDecoder::bitsFromString("00000000000011"); | |
| 128 BOOST_REQUIRE_EQUAL(bits.size(), 14u); | |
| 129 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 3u); | |
| 130 | |
| 131 bits = BitDecoder::bitsFromString("000000000000011"); | |
| 132 BOOST_REQUIRE_EQUAL(bits.size(), 15u); | |
| 133 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 3u); | |
| 134 | |
| 135 bits = BitDecoder::bitsFromString("10000001"); | |
| 136 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 137 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 129u); | |
| 138 | |
| 139 bits = BitDecoder::bitsFromString("010000001"); | |
| 140 BOOST_REQUIRE_EQUAL(bits.size(), 9u); | |
| 141 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(1), 129u); | |
| 142 | |
| 143 bits = BitDecoder::bitsFromString("0010000001"); | |
| 144 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 145 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 129u); | |
| 146 | |
| 147 bits = BitDecoder::bitsFromString("00010000001"); | |
| 148 BOOST_REQUIRE_EQUAL(bits.size(), 11u); | |
| 149 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(3), 129u); | |
| 150 | |
| 151 bits = BitDecoder::bitsFromString("000010000001"); | |
| 152 BOOST_REQUIRE_EQUAL(bits.size(), 12u); | |
| 153 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 129u); | |
| 154 | |
| 155 bits = BitDecoder::bitsFromString("0000010000001"); | |
| 156 BOOST_REQUIRE_EQUAL(bits.size(), 13u); | |
| 157 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 129u); | |
| 158 | |
| 159 bits = BitDecoder::bitsFromString("00000010000001"); | |
| 160 BOOST_REQUIRE_EQUAL(bits.size(), 14u); | |
| 161 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 129u); | |
| 162 | |
| 163 bits = BitDecoder::bitsFromString("000000010000001"); | |
| 164 BOOST_REQUIRE_EQUAL(bits.size(), 15u); | |
| 165 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 129u); | |
| 166 | |
| 167 | |
| 168 bits = BitDecoder::bitsFromString("0100011011"); | |
| 169 BOOST_REQUIRE_EQUAL(bits.size(), 10u); | |
| 170 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 27u); | |
| 171 } | |
| 172 | |
| 173 BOOST_AUTO_TEST_CASE( TestCorrectChar ) | |
| 174 { | |
| 175 BitArray bits = BitDecoder::bitsFromString("00000001"); | |
| 176 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 177 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 1u); | |
| 178 | |
| 179 bits = BitDecoder::bitsFromString("00000011"); | |
| 180 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 181 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 3u); | |
| 182 | |
| 183 bits = BitDecoder::bitsFromString("10000000"); | |
| 184 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 185 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 128u); | |
| 186 bits = BitDecoder::bitsFromString("11000000"); | |
| 187 BOOST_REQUIRE_EQUAL(bits.size(), 8u); | |
| 188 BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 192u); | |
| 189 } |
