diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestFastBitDecoder.cpp	Mon Sep 10 21:31:10 2012 +0200
@@ -0,0 +1,58 @@
+#include "FastBitDecoder.hpp"
+#include "TestFramework.hpp"
+
+#include "BitDecoder.hpp"
+
+
+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");
+
+  FastBitDecoder fast(full->createEncoder());
+
+  BOOST_REQUIRE_EQUAL(fast.decode("1"), "a");
+  BOOST_REQUIRE_EQUAL(fast.decode("0"), "b");
+  BOOST_REQUIRE_EQUAL(fast.decode("1111"), "aaaa");
+  BOOST_REQUIRE_EQUAL(fast.decode("0000"), "bbbb");
+  BOOST_REQUIRE_EQUAL(fast.decode("1101"), "aaba");
+  BOOST_REQUIRE_EQUAL(fast.decode("1111"), "aaaa");
+}
+
+BOOST_AUTO_TEST_CASE( TestLong )
+{
+  BitDecoder* up = new BitDecoder("b");
+  BitDecoder* down = new BitDecoder("a");
+  for (int i = 0; i < 12; ++i) {
+    down = BitDecoder::merge(down, up);
+    up = new BitDecoder(QString('c' + i));
+  }
+
+  BitDecoder* full = BitDecoder::merge(down, up);
+
+  BOOST_REQUIRE(full->data().isNull());
+
+  FastBitDecoder fast(full->createEncoder());
+
+  BOOST_REQUIRE_EQUAL(fast.decode("1"), "n");
+  BOOST_REQUIRE_EQUAL(fast.decode("01"), "m");
+  BOOST_REQUIRE_EQUAL(fast.decode("001"), "l");
+  BOOST_REQUIRE_EQUAL(fast.decode("0001"), "k");
+  BOOST_REQUIRE_EQUAL(fast.decode("00001"), "j");
+  BOOST_REQUIRE_EQUAL(fast.decode("000001"), "i");
+  BOOST_REQUIRE_EQUAL(fast.decode("0000001"), "h");
+  BOOST_REQUIRE_EQUAL(fast.decode("00000001"), "g");
+  BOOST_REQUIRE_EQUAL(fast.decode("000000001"), "f");
+  BOOST_REQUIRE_EQUAL(fast.decode("0000000001"), "e");
+  BOOST_REQUIRE_EQUAL(fast.decode("00000000001"), "d");
+  BOOST_REQUIRE_EQUAL(fast.decode("000000000001"), "c");
+  BOOST_REQUIRE_EQUAL(fast.decode("0000000000001"), "b");
+  BOOST_REQUIRE_EQUAL(fast.decode("0000000000000"), "a");
+
+}