Mercurial > dedupe
comparison TestBitDecoder.cpp @ 20:754e12c927b3
Class for decoding binary datarepresentations, eg. Huffman trees.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 05 Sep 2012 21:54:18 +0200 |
| parents | |
| children | b2c2c2bf2bbd |
comparison
equal
deleted
inserted
replaced
| 19:1ad6fa6dc039 | 20:754e12c927b3 |
|---|---|
| 1 #include "BitDecoder.hpp" | |
| 2 #include "TestFramework.hpp" | |
| 3 | |
| 4 #include "InvalidDataException.hpp" | |
| 5 #include <QtCore/QDebug> | |
| 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 | |
| 21 BOOST_AUTO_TEST_CASE( TestSimple ) | |
| 22 { | |
| 23 BitDecoder* up = new BitDecoder("a"); | |
| 24 BitDecoder* down = new BitDecoder("b"); | |
| 25 | |
| 26 BitDecoder* full = BitDecoder::merge(down, up); | |
| 27 | |
| 28 BOOST_REQUIRE(full->data().isNull()); | |
| 29 BOOST_REQUIRE_EQUAL(up->data(), "a"); | |
| 30 BOOST_REQUIRE_EQUAL(down->data(), "b"); | |
| 31 | |
| 32 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1")), "a"); | |
| 33 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0")), "b"); | |
| 34 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); | |
| 35 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000")), "bbbb"); | |
| 36 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1101")), "aaba"); | |
| 37 BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); | |
| 38 } |
