Mercurial > dedupe
view TestBitDecoder.cpp @ 38:7905fa8a3f1b
Test for empty string.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 07 Sep 2012 13:07:46 +0200 |
| parents | bf3dce7fedcb |
| children | 7348d4efa4f6 |
line wrap: on
line source
#include "BitDecoder.hpp" #include "TestFramework.hpp" #include "Exception/InvalidDataException.hpp" QBitArray bitsFromString(const QString& str) { QBitArray bits(str.size()); for (int i = 0; i < str.size(); ++i) { if (str[i] == '1') bits[i] = true; else if (str[i] == '0') bits[i] = false; else throw InvalidDataException(); } return bits; } BOOST_AUTO_TEST_CASE( TestSimple ) { BitDecoder* up = new BitDecoder("a"); BitDecoder* down = new BitDecoder("b"); BitDecoder* full = BitDecoder::merge(down, up); BOOST_REQUIRE(full->data().isNull()); BOOST_REQUIRE_EQUAL(up->data(), "a"); BOOST_REQUIRE_EQUAL(down->data(), "b"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1")), "a"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0")), "b"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("0000")), "bbbb"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1101")), "aaba"); BOOST_REQUIRE_EQUAL(full->decode(bitsFromString("1111")), "aaaa"); }
