public void FileCondense(string path) { var w = File.ReadAllText(path); HuffmanChain chain; HuffmanTree tree; string cW, cT; var condenser = new SingleCondenser(); (cW, chain) = condenser.Condense(w); (cT, tree) = condenser.CondenseToTree(w); Assert.NotNull(chain); Assert.NotNull(tree); Assert.LessOrEqual(cW.Length, w.Length); Assert.LessOrEqual(cT.Length, w.Length); Assert.LessOrEqual(cW.Length, cT.Length); Assert.LessOrEqual((double)cW.Length / cT.Length, .95); var expander = new SingleExpander(); var expanded = expander.Expand(cW, chain, w.Length); TestContext.WriteLine( $"Chain vs Tree Efficiency: cW/cT = {(double) cW.Length / cT.Length:P} size decrease"); TestContext.WriteLine($"Chain Overall Efficiency: cW/w = {(double) cW.Length / w.Length:P} size decrease"); TestContext.WriteLine($"Tree Overall Efficiency: cW/w = {(double) cT.Length / w.Length:P} size decrease"); var output = new HuffmanChain.HuffmanChainOutputService().CreateOutput(chain); TestContext.WriteLine(output); Assert.AreEqual(w, expanded); }
public void ChainEfficiency() { var dict = HuffmanTreeTests.NumberCharacterGenerator(200); var w = HuffmanTreeTests.GenerateString(dict); HuffmanChain chain; HuffmanTree tree; string cW, cT; var condenser = new SingleCondenser(); (cW, chain) = condenser.Condense(w); (cT, tree) = condenser.CondenseToTree(w); Assert.NotNull(chain); Assert.NotNull(tree); Assert.LessOrEqual(cW.Length, cT.Length); Assert.LessOrEqual((double)cW.Length / cT.Length, .95); TestContext.WriteLine( $"Chain vs Tree Efficiency: cW/cT = {(double) cW.Length / cT.Length:P} size decrease"); TestContext.WriteLine($"Chain Overall Efficiency: cW/w = {(double) cW.Length / w.Length:P} size decrease"); TestContext.WriteLine($"Tree Overall Efficiency: cW/w = {(double) cT.Length / w.Length:P} size decrease"); TestContext.WriteLine(); }