Example #1
0
        public void HuffmanTreeInternal()
        {
            HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9);
            HuffmanTreeLeaf<int> b = new HuffmanTreeLeaf<int>(7, 21);
            HuffmanTreeLeaf<int> c = new HuffmanTreeLeaf<int>(2, 125);

            HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(a, b);
            Assert.AreEqual(30, i1.Frequency);

            HuffmanTreeInternalNode<int> i2 = new HuffmanTreeInternalNode<int>(c, i1);
            Assert.AreEqual(155, i2.Frequency);
        }
Example #2
0
        public void HuffmanTreeCast()
        {
            HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9);
            HuffmanTreeLeaf<int> b = new HuffmanTreeLeaf<int>(7, 21);
            HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(a, b);

            HuffmanTree<int> castA = a as HuffmanTree<int>;
            Assert.NotNull(castA);
            Assert.AreEqual(9, castA.Frequency);

            HuffmanTree<int> castI1 = i1 as HuffmanTree<int>;
            Assert.NotNull(castI1);
            Assert.AreEqual(30, castI1.Frequency);
        }
Example #3
0
 public void HuffmanTreeRightLeafNull()
 {
     HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9);
     HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(a, null);
 }
Example #4
0
 public void HuffmanTreeLeftLeafNull()
 {
     HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9);
     HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(null, a);
 }
Example #5
0
        public void HuffmanTreeToEncodingTree()
        {
            HuffmanTree<char> a = new HuffmanTreeInternalNode<char>(new HuffmanTreeLeaf<char>('a', 1111111), new HuffmanTreeLeaf<char>('b', 1));

            EncodingTree<char> b = a.ToEncodingTree();
            Assert.AreEqual('a', b.Resolve(new[] { false }));
            Assert.AreEqual('b', b.Resolve(new[] { true }));
        }