Mercurial > dedupe
comparison TestBitDecoder.cpp @ 45:41cc0d8ac77f
Decode directly from bitString.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 21:29:43 +0200 |
| parents | 7348d4efa4f6 |
| children | f9fa7ea71d37 |
comparison
equal
deleted
inserted
replaced
| 44:7348d4efa4f6 | 45:41cc0d8ac77f |
|---|---|
| 1 #include "BitDecoder.hpp" | 1 #include "BitDecoder.hpp" |
| 2 #include "TestFramework.hpp" | 2 #include "TestFramework.hpp" |
| 3 | 3 |
| 4 #include "Exception/InvalidDataException.hpp" | |
| 5 | 4 |
| 6 | |
| 7 QBitArray bitsFromString(const QString& str) | |
| 8 { | |
| 9 QBitArray bits(str.size()); | |
| 10 for (int i = 0; i < str.size(); ++i) { | |
| 11 if (str[i] == '1') | |
| 12 bits[i] = true; | |
| 13 else if (str[i] == '0') | |
| 14 bits[i] = false; | |
| 15 else | |
| 16 throw InvalidDataException(); | |
| 17 } | |
| 18 return bits; | |
| 19 } | |
| 20 | 5 |
| 21 BOOST_AUTO_TEST_CASE( TestSimple ) | 6 BOOST_AUTO_TEST_CASE( TestSimple ) |
| 22 { | 7 { |
| 23 BitDecoder* up = new BitDecoder("a"); | 8 BitDecoder* up = new BitDecoder("a"); |
| 24 BitDecoder* down = new BitDecoder("b"); | 9 BitDecoder* down = new BitDecoder("b"); |
| 27 | 12 |
| 28 BOOST_REQUIRE(full->data().isNull()); | 13 BOOST_REQUIRE(full->data().isNull()); |
| 29 BOOST_REQUIRE_EQUAL(up->data(), "a"); | 14 BOOST_REQUIRE_EQUAL(up->data(), "a"); |
| 30 BOOST_REQUIRE_EQUAL(down->data(), "b"); | 15 BOOST_REQUIRE_EQUAL(down->data(), "b"); |
| 31 | 16 |
| 32 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1")), "a"); | 17 BOOST_REQUIRE_EQUAL(full->decode("1"), "a"); |
| 33 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0")), "b"); | 18 BOOST_REQUIRE_EQUAL(full->decode("0"), "b"); |
| 34 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); | 19 BOOST_REQUIRE_EQUAL(full->decode("1111"), "aaaa"); |
| 35 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000")), "bbbb"); | 20 BOOST_REQUIRE_EQUAL(full->decode("0000"), "bbbb"); |
| 36 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1101")), "aaba"); | 21 BOOST_REQUIRE_EQUAL(full->decode("1101"), "aaba"); |
| 37 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); | 22 BOOST_REQUIRE_EQUAL(full->decode("1111"), "aaaa"); |
| 38 } | 23 } |
| 39 | 24 |
| 40 BOOST_AUTO_TEST_CASE( TestLong ) | 25 BOOST_AUTO_TEST_CASE( TestLong ) |
| 41 { | 26 { |
| 42 BitDecoder* up = new BitDecoder("b"); | 27 BitDecoder* up = new BitDecoder("b"); |
| 47 } | 32 } |
| 48 | 33 |
| 49 BitDecoder* full = BitDecoder::merge(down, up); | 34 BitDecoder* full = BitDecoder::merge(down, up); |
| 50 | 35 |
| 51 BOOST_REQUIRE(full->data().isNull()); | 36 BOOST_REQUIRE(full->data().isNull()); |
| 52 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1")), "n"); | 37 BOOST_REQUIRE_EQUAL(full->decode("1"), "n"); |
| 53 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("01")), "m"); | 38 BOOST_REQUIRE_EQUAL(full->decode("01"), "m"); |
| 54 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("001")), "l"); | 39 BOOST_REQUIRE_EQUAL(full->decode("001"), "l"); |
| 55 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0001")), "k"); | 40 BOOST_REQUIRE_EQUAL(full->decode("0001"), "k"); |
| 56 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("00001")), "j"); | 41 BOOST_REQUIRE_EQUAL(full->decode("00001"), "j"); |
| 57 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("000001")), "i"); | 42 BOOST_REQUIRE_EQUAL(full->decode("000001"), "i"); |
| 58 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000001")), "h"); | 43 BOOST_REQUIRE_EQUAL(full->decode("0000001"), "h"); |
| 59 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("00000001")), "g"); | 44 BOOST_REQUIRE_EQUAL(full->decode("00000001"), "g"); |
| 60 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("000000001")), "f"); | 45 BOOST_REQUIRE_EQUAL(full->decode("000000001"), "f"); |
| 61 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000000001")), "e"); | 46 BOOST_REQUIRE_EQUAL(full->decode("0000000001"), "e"); |
| 62 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("00000000001")), "d"); | 47 BOOST_REQUIRE_EQUAL(full->decode("00000000001"), "d"); |
| 63 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("000000000001")), "c"); | 48 BOOST_REQUIRE_EQUAL(full->decode("000000000001"), "c"); |
| 64 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000000000001")), "b"); | 49 BOOST_REQUIRE_EQUAL(full->decode("0000000000001"), "b"); |
| 65 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000000000000")), "a"); | 50 BOOST_REQUIRE_EQUAL(full->decode("0000000000000"), "a"); |
| 66 | 51 |
| 67 } | 52 } |
