comparison TestFastBitDecoder.cpp @ 46:877327e9061a

N-Tree for decoding.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Mon, 10 Sep 2012 21:31:10 +0200
parents
children f9fa7ea71d37
comparison
equal deleted inserted replaced
45:41cc0d8ac77f 46:877327e9061a
1 #include "FastBitDecoder.hpp"
2 #include "TestFramework.hpp"
3
4 #include "BitDecoder.hpp"
5
6
7 BOOST_AUTO_TEST_CASE( TestSimple )
8 {
9 BitDecoder* up = new BitDecoder("a");
10 BitDecoder* down = new BitDecoder("b");
11
12 BitDecoder* full = BitDecoder::merge(down, up);
13
14 BOOST_REQUIRE(full->data().isNull());
15 BOOST_REQUIRE_EQUAL(up->data(), "a");
16 BOOST_REQUIRE_EQUAL(down->data(), "b");
17
18 FastBitDecoder fast(full->createEncoder());
19
20 BOOST_REQUIRE_EQUAL(fast.decode("1"), "a");
21 BOOST_REQUIRE_EQUAL(fast.decode("0"), "b");
22 BOOST_REQUIRE_EQUAL(fast.decode("1111"), "aaaa");
23 BOOST_REQUIRE_EQUAL(fast.decode("0000"), "bbbb");
24 BOOST_REQUIRE_EQUAL(fast.decode("1101"), "aaba");
25 BOOST_REQUIRE_EQUAL(fast.decode("1111"), "aaaa");
26 }
27
28 BOOST_AUTO_TEST_CASE( TestLong )
29 {
30 BitDecoder* up = new BitDecoder("b");
31 BitDecoder* down = new BitDecoder("a");
32 for (int i = 0; i < 12; ++i) {
33 down = BitDecoder::merge(down, up);
34 up = new BitDecoder(QString('c' + i));
35 }
36
37 BitDecoder* full = BitDecoder::merge(down, up);
38
39 BOOST_REQUIRE(full->data().isNull());
40
41 FastBitDecoder fast(full->createEncoder());
42
43 BOOST_REQUIRE_EQUAL(fast.decode("1"), "n");
44 BOOST_REQUIRE_EQUAL(fast.decode("01"), "m");
45 BOOST_REQUIRE_EQUAL(fast.decode("001"), "l");
46 BOOST_REQUIRE_EQUAL(fast.decode("0001"), "k");
47 BOOST_REQUIRE_EQUAL(fast.decode("00001"), "j");
48 BOOST_REQUIRE_EQUAL(fast.decode("000001"), "i");
49 BOOST_REQUIRE_EQUAL(fast.decode("0000001"), "h");
50 BOOST_REQUIRE_EQUAL(fast.decode("00000001"), "g");
51 BOOST_REQUIRE_EQUAL(fast.decode("000000001"), "f");
52 BOOST_REQUIRE_EQUAL(fast.decode("0000000001"), "e");
53 BOOST_REQUIRE_EQUAL(fast.decode("00000000001"), "d");
54 BOOST_REQUIRE_EQUAL(fast.decode("000000000001"), "c");
55 BOOST_REQUIRE_EQUAL(fast.decode("0000000000001"), "b");
56 BOOST_REQUIRE_EQUAL(fast.decode("0000000000000"), "a");
57
58 }