changeset 51:0bd3c1c46251

More extensive testing of BitArray.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Thu, 13 Sep 2012 23:14:40 +0200
parents f9fa7ea71d37
children 725b0d776f3c
files TestBitArray.cpp
diffstat 1 files changed, 138 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/TestBitArray.cpp	Thu Sep 13 23:08:07 2012 +0200
+++ b/TestBitArray.cpp	Thu Sep 13 23:14:40 2012 +0200
@@ -1,7 +1,7 @@
 #include "BitArray.hpp"
 #include "TestFramework.hpp"
 
-#include <QtCore/QDebug>
+#include "BitDecoder.hpp"
 
 BOOST_AUTO_TEST_CASE( TestBasic )
 {
@@ -50,3 +50,140 @@
   }
 
 }
+
+BOOST_AUTO_TEST_CASE( TestSetBit2 )
+{
+  BitArray tbits(8, true);
+  BitArray fbits(8, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("11111111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000"));
+
+  tbits.setBit(0, false);
+  fbits.setBit(0, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("00000000"));
+
+  tbits.setBit(1, true);
+  fbits.setBit(1, true);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01111111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000"));
+
+  tbits.setBit(2, false);
+  fbits.setBit(2, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01011111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000"));
+
+  tbits.setBit(3, false);
+  fbits.setBit(3, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01001111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000"));
+
+  tbits.setBit(4, false);
+  fbits.setBit(4, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000000"));
+
+  tbits.setBit(5, true);
+  fbits.setBit(5, true);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000100"));
+
+  tbits.setBit(6, true);
+  fbits.setBit(6, true);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000111"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110"));
+
+  tbits.setBit(7, false);
+  fbits.setBit(7, false);
+  BOOST_REQUIRE_EQUAL(tbits, BitDecoder::bitsFromString("01000110"));
+  BOOST_REQUIRE_EQUAL(fbits, BitDecoder::bitsFromString("01000110"));
+
+
+}
+
+BOOST_AUTO_TEST_CASE( TestPaddedChar )
+{
+  BitArray bits = BitDecoder::bitsFromString("0100011011");
+
+  BOOST_REQUIRE_EQUAL(bits.size(), 10u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 70);
+
+  bits = BitDecoder::bitsFromString("0000000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 10u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 1u);
+
+  bits = BitDecoder::bitsFromString("0000000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 10u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 3u);
+
+  bits = BitDecoder::bitsFromString("000000000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 12u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 3u);
+
+  bits = BitDecoder::bitsFromString("0000000000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 13u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 3u);
+
+  bits = BitDecoder::bitsFromString("00000000000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 14u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 3u);
+
+  bits = BitDecoder::bitsFromString("000000000000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 15u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 3u);
+
+  bits = BitDecoder::bitsFromString("10000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 8u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 129u);
+ 
+  bits = BitDecoder::bitsFromString("010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 9u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(1), 129u);
+
+  bits = BitDecoder::bitsFromString("0010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 10u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 129u);
+
+  bits = BitDecoder::bitsFromString("00010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 11u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(3), 129u);
+
+  bits = BitDecoder::bitsFromString("000010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 12u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(4), 129u);
+
+  bits = BitDecoder::bitsFromString("0000010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 13u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(5), 129u);
+
+  bits = BitDecoder::bitsFromString("00000010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 14u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(6), 129u);
+
+  bits = BitDecoder::bitsFromString("000000010000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 15u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(7), 129u);
+
+
+  bits = BitDecoder::bitsFromString("0100011011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 10u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(2), 27u);
+}
+
+BOOST_AUTO_TEST_CASE( TestCorrectChar )
+{
+  BitArray bits = BitDecoder::bitsFromString("00000001");
+  BOOST_REQUIRE_EQUAL(bits.size(), 8u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 1u);
+
+  bits = BitDecoder::bitsFromString("00000011");
+  BOOST_REQUIRE_EQUAL(bits.size(), 8u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 3u);
+
+  bits = BitDecoder::bitsFromString("10000000");
+  BOOST_REQUIRE_EQUAL(bits.size(), 8u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 128u);
+  bits = BitDecoder::bitsFromString("11000000");
+  BOOST_REQUIRE_EQUAL(bits.size(), 8u);
+  BOOST_REQUIRE_EQUAL(bits.getPaddedChar(0), 192u);
+}