Ejemplo n.º 1
0
 //Checks tree for "aaabbc" which is "6 *97:3 3 *99:1 *98:2"
 public void CheckSimpleTree(HuffmansTree.Node root)
 {
     Assert.IsNotNull(root);
     Assert.IsNull(root.Left.Left);
     Assert.IsNull(root.Left.Right);
     Assert.IsNull(root.Right.Left.Left);
     Assert.IsNull(root.Right.Left.Right);
     Assert.IsNull(root.Right.Right.Left);
     Assert.IsNull(root.Right.Right.Right);
     Assert.AreEqual((ulong)6, root.Sum);
     Assert.AreEqual((ulong)3, root.Left.Sum);
     Assert.AreEqual((ulong)3, root.Right.Sum);
     Assert.AreEqual((ulong)1, root.Right.Left.Sum);
     Assert.AreEqual((ulong)2, root.Right.Right.Sum);
     Assert.AreEqual((ulong)0, root.Code);
     Assert.AreEqual((byte)97, root.Left.Code);
     Assert.AreEqual((byte)0, root.Right.Code);
     Assert.AreEqual((byte)99, root.Right.Left.Code);
     Assert.AreEqual((byte)98, root.Right.Right.Code);
     Assert.AreNotEqual((ulong)0, root.Order);
     Assert.AreEqual((ulong)0, root.Left.Order);
     Assert.AreNotEqual((ulong)0, root.Right.Order);
     Assert.AreEqual((ulong)0, root.Right.Left.Order);
     Assert.AreEqual((ulong)0, root.Right.Right.Order);
 }
Ejemplo n.º 2
0
        public void ReCreateNode_list()
        {
            HuffmansTree.Node actual = HuffmansTree.ReCreateNode(12);

            Assert.IsNotNull(actual);
            Assert.AreEqual((ulong)1, actual.Order);
            Assert.AreEqual((ulong)6, actual.Sum);
            Assert.AreEqual((byte)0, actual.Code);
        }
Ejemplo n.º 3
0
        public void ReCreateNode_inner()
        {
            // From 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62
            HuffmansTree.Node actual = HuffmansTree.ReCreateNode(7061644215716937733);

            Assert.IsNotNull(actual);
            Assert.AreEqual((ulong)0, actual.Order);
            Assert.AreEqual((ulong)2, actual.Sum);
            Assert.AreEqual((byte)98, actual.Code);
        }
Ejemplo n.º 4
0
        public void ReCreateTree_simple()
        {
            byte[] fileInBytes = new byte[] { 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                              0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61,
                                              0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                              0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
                                              0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62,
                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            BinaryReader fileIn = new BinaryReader(new MemoryStream(fileInBytes));

            HuffmansTree.Node actual = HuffmansTree.ReCreateTree(fileIn);
            CheckSimpleTree(actual);
        }
Ejemplo n.º 5
0
        public void FromFile_simple()
        {
            byte[] fileInBytes = new byte[] { 0x7B, 0x68, 0x75, 0x7C, 0x6D, 0x7D, 0x66, 0x66,
                                              0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                              0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61,
                                              0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                              0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
                                              0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62,
                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            BinaryReader fileIn = new BinaryReader(new MemoryStream(fileInBytes));
            TextWriter   stdOut = new StringWriter();;

            HuffmansTree.Node actual = HuffmansTree.FromFile(fileIn);

            CheckSimpleTree(actual);
        }
Ejemplo n.º 6
0
        public void Node_CompareTo_GreaterLesser()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node()
            {
                Code  = 0,
                Sum   = 3,
                Order = 0
            };
            HuffmansTree.Node greater = new HuffmansTree.Node()
            {
                Code  = 0,
                Sum   = 2,
                Order = 0
            };

            int expected = 1;
            int actual   = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void Node_CompareTo_EqualsBothInnerOrderGreaterLesser()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node()
            {
                Code  = 3,
                Sum   = 2,
                Order = 3
            };
            HuffmansTree.Node greater = new HuffmansTree.Node()
            {
                Code  = 2,
                Sum   = 2,
                Order = 2
            };

            int expected = 1;
            int actual   = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void Node_CompareTo_EqualsListInner()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node()
            {
                Code  = 3,
                Sum   = 2,
                Order = 0
            };
            HuffmansTree.Node greater = new HuffmansTree.Node()
            {
                Code  = 2,
                Sum   = 2,
                Order = 1
            };

            int expected = -1;
            int actual   = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
 public void ReCreateNode_zero()
 {
     HuffmansTree.Node actual = HuffmansTree.ReCreateNode(0);
     Assert.IsNull(actual);
 }
Ejemplo n.º 10
0
        public void Node_CompareTo_LesserGreater()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node() {
                Code = 0,
                Sum = 1,
                Order = 0
            };
            HuffmansTree.Node greater = new HuffmansTree.Node() {
                Code = 0,
                Sum = 2,
                Order = 0
            };

            int expected = -1;
            int actual = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void Node_CompareTo_EqualsListsCodesGreaterLesser()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node() {
                Code = 3,
                Sum = 2,
                Order = 0
            };
            HuffmansTree.Node greater = new HuffmansTree.Node() {
                Code = 2,
                Sum = 2,
                Order = 0
            };

            int expected = 1;
            int actual = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void Node_CompareTo_EqualsBothInnerOrderLesserGreater()
        {
            HuffmansTree.Node lesser = new HuffmansTree.Node() {
                Code = 3,
                Sum = 2,
                Order = 1
            };
            HuffmansTree.Node greater = new HuffmansTree.Node() {
                Code = 2,
                Sum = 2,
                Order = 2
            };

            int expected = -1;
            int actual = lesser.CompareTo(greater);

            Assert.AreEqual(expected, actual);
        }