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); }
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); }
public void HuffmanTreeRightLeafNull() { HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9); HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(a, null); }
public void HuffmanTreeLeftLeafNull() { HuffmanTreeLeaf<int> a = new HuffmanTreeLeaf<int>(5, 9); HuffmanTreeInternalNode<int> i1 = new HuffmanTreeInternalNode<int>(null, a); }
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 })); }