public void BuildTreeLengthTest() { var data1 = new byte[] { 0, 2, 2, 2, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; var data2 = new byte[] { 0, 5, 3, 6, 7, 2, 8, 0, 1, 9, 10, 11, 12, 13, 15 }; var lengths = new byte[] { 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, 10, 11 }; var dictionary = HuffmanTable.BuildTree(data1, data2); CollectionAssert.AreEqual(lengths, dictionary.Values.Select(key => key.Length).ToArray()); }
public void BuildTreeKeysTest() { var data1 = new byte[] { 0, 2, 2, 2, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; var data2 = new byte[] { 0, 5, 3, 6, 7, 2, 8, 0, 1, 9, 10, 11, 12, 13, 15 }; var keys = new[] { 0, 1, 4, 5, 12, 13, 28, 29, 30, 62, 126, 254, 510, 1022, 2046 }; var dictionary = HuffmanTable.BuildTree(data1, data2); CollectionAssert.AreEqual(keys, dictionary.Keys); }
public void BuildTreeCodesTest() { var data1 = new byte[] { 0, 2, 2, 2, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; var data2 = new byte[] { 0, 5, 3, 6, 7, 2, 8, 0, 1, 9, 10, 11, 12, 13, 15 }; var codes = new byte[] { 0, 5, 3, 6, 7, 2, 8, 0, 1, 9, 10, 11, 12, 13, 15 }; var dictionary = HuffmanTable.BuildTree(data1, data2); CollectionAssert.AreEqual(codes, dictionary.Values.Select(key => key.Code).ToArray()); }