Ejemplo n.º 1
0
        public void GetHuffmanTree_NotEmptyText_HuffmanTree()
        {
            var algo = new AlgorithmHuffman();

            var text = "I was here last summer.";

            var tree = algo.GetHuffmanTree(text);

            var symbols = tree.GetAllSymbol();

            var expected = new List <(string, string, int)>
            {
                ("r", "000", 2),
                (".", "0010", 1),
                ("w", "0011", 1),
                ("u", "0100", 1),
                ("t", "0101", 1),
                ("l", "0110", 1),
                ("I", "01110", 1),
                ("h", "01111", 1),
                ("e", "100", 3),
                ("s", "101", 3),
                (" ", "110", 4),
                ("m", "1110", 2),
                ("a", "1111", 2),
            };

            Assert.IsTrue(AreEqual(symbols, expected));
        }
Ejemplo n.º 2
0
        public void GetHuffmanTree_EmptyText_Exception()
        {
            var algo = new AlgorithmHuffman();

            var text = string.Empty;

            Assert.Throws <Exception>(() => algo.GetHuffmanTree(text));
        }