Пример #1
0
        public void BuildTree_SimpleTree()
        {
            //Arrange
            var processor = new InputProcessorMockup();
            var leafTree  = processor.BuildSimpleTree();
            var builder   = new TreeBuilder(leafTree);

            //Act
            builder.BuildTree();

            //Assert
            Assert.AreEqual(builder.tree.Count, 1);
            var root = builder.tree.First();

            Assert.IsTrue(root.GetType() != typeof(Leaf));
            Assert.AreEqual(root.frequency, 6);
            Assert.AreEqual(root.creationId, 2);

            Assert.IsTrue(root.left.GetType() == typeof(Leaf));
            Assert.AreEqual(root.left.character, Convert.ToByte('a'));
            Assert.AreEqual(root.left.frequency, 3);

            Assert.IsTrue(root.right.GetType() != typeof(Leaf));
            Assert.AreEqual(root.right.frequency, 3);
            Assert.AreEqual(root.right.creationId, 1);

            Assert.IsTrue(root.right.left.GetType() == typeof(Leaf));
            Assert.AreEqual(root.right.left.character, Convert.ToByte('c'));
            Assert.AreEqual(root.right.left.frequency, 1);

            Assert.IsTrue(root.right.right.GetType() == typeof(Leaf));
            Assert.AreEqual(root.right.right.character, Convert.ToByte('b'));
            Assert.AreEqual(root.right.right.frequency, 2);
        }
Пример #2
0
        public void PrintTree_PrintSimpleTree()
        {
            //Arrange
            var processor = new InputProcessorMockup();
            var leafTree  = processor.BuildSimpleTree();
            var builder   = new TreeBuilder(leafTree);

            using (StringWriter stringWriter = new StringWriter())
            {
                //Act
                builder.BuildTree();
                Console.SetOut(stringWriter);
                builder.PrintTree(builder.tree.First());

                //Assert
                Assert.AreEqual("6 *97:3 3 *99:1 *98:2", stringWriter.ToString());
            }
        }