コード例 #1
0
        public void NonRootLL()
        {
            t = new Models.Spells.SpellTree.RBTree(s5);//e
            t.insert(s6);
            t.insert(s4);
            t.insert(s3);

            RootCheck(t);
            BlackCheck(t.Root.Right);
            BlackCheck(t.Root.Left);
            RedCheck(t.Root.Left.Left);

            Assert.AreEqual("e", t.Root.Value.Name);
            Assert.AreEqual("f", t.Root.Right.Value.Name);
            Assert.IsNull(t.Root.Right.Left);
            Assert.IsNull(t.Root.Right.Right);
            Assert.AreEqual("d", t.Root.Left.Value.Name);
            Assert.AreEqual("c", t.Root.Left.Left.Value.Name);
            Assert.IsNull(t.Root.Left.Right);

            t.insert(s2);

            Assert.AreEqual("e", t.Root.Value.Name);
            Assert.AreEqual("f", t.Root.Right.Value.Name);
            Assert.AreEqual("c", t.Root.Left.Value.Name);
            Assert.AreEqual("d", t.Root.Left.Right.Value.Name);
            Assert.AreEqual("b", t.Root.Left.Left.Value.Name);

            BlackCheck(t.Root);
            BlackCheck(t.Root.Right);
            RedCheck(t.Root.Left.Right);
            RedCheck(t.Root.Left.Left);
            BlackCheck(t.Root.Left);
        }
コード例 #2
0
        public void printTreeTest_SingleElement()
        {
            t = new Models.Spells.SpellTree.RBTree(s);
            t.printTree();

            Assert.AreEqual("Beast Sense ", t.Order);
        }
コード例 #3
0
 public void printTreeTest_ThreeElements()
 {
     t = new Models.Spells.SpellTree.RBTree(s2);
     t.insert(s1);
     t.insert(s3);
     t.printTree();
     Assert.AreEqual("a b c ", t.Order);
 }
コード例 #4
0
 public void RootRecolorationTest()
 {
     t = new Models.Spells.SpellTree.RBTree(s2);
     Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
     t = new Models.Spells.SpellTree.RBTree();
     t.insert(s2);
     Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
 }
コード例 #5
0
 public void UncleRecolorationTestLR()
 {
     t = new Models.Spells.SpellTree.RBTree(s6);
     t.insert(s3);
     t.insert(s7);
     t.insert(s4);// grandchild: LR uncle: R
     Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Left.Color);
     Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Right.Color);
     Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Left.Right.Color);
     Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
 }
コード例 #6
0
        public void treeConstructorTest()
        {
            t = new Models.Spells.SpellTree.RBTree();

            t = new Models.Spells.SpellTree.RBTree(s);
            Models.Spells.SpellTree.Node root = t.Root;
            Assert.AreSame(root, t.Root);
            root.Color = (int)Models.Spells.SpellTree.color.red;
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Color);
            t.Root.Color = (int)Models.Spells.SpellTree.color.black;
            Assert.AreEqual((int)Models.Spells.SpellTree.color.black, root.Color);
        }
コード例 #7
0
        public void lineRotationLeftTest()
        {
            t = new Models.Spells.SpellTree.RBTree(s5); //e
            t.insert(s4);                               //d
            t.insert(s3);                               //c
            Assert.AreEqual("d", t.Root.Value.Name);
            Assert.AreEqual("c", t.Root.Left.Value.Name);
            Assert.AreEqual("e", t.Root.Right.Value.Name);

            Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Left.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Right.Color);
        }
コード例 #8
0
        public void lineRotationRightTest()
        {
            t = new Models.Spells.SpellTree.RBTree(s1);
            t.insert(s2);
            t.insert(s3);
            Assert.AreEqual("b", t.Root.Value.Name);
            Assert.AreEqual("a", t.Root.Left.Value.Name);
            Assert.AreEqual("c", t.Root.Right.Value.Name);

            Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Left.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Right.Color);
        }
コード例 #9
0
        public void TriangleRotationLRTest()
        {
            t = new Models.Spells.SpellTree.RBTree(s5); //e
            RootCheck(t);
            t.insert(s3);                               //c
            t.insert(s4);                               //d

            Assert.AreEqual("d", t.Root.Value.Name);
            Assert.AreEqual("c", t.Root.Left.Value.Name);
            Assert.AreEqual("e", t.Root.Right.Value.Name);

            Assert.AreEqual((int)Models.Spells.SpellTree.color.black, t.Root.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Left.Color);
            Assert.AreEqual((int)Models.Spells.SpellTree.color.red, t.Root.Right.Color);
        }
コード例 #10
0
        public void PrintTreeTest_6_ordered()
        {
            t = new Models.Spells.SpellTree.RBTree();
            String orderTest = "";

            foreach (Spell spell in spellList())
            {
                t.insert(spell);
                orderTest += spell.Name + " ";
                t.Order    = "";
                t.printTree();
                Assert.AreEqual(orderTest, t.Order);
            }
            t.Order = "";
            t.printTree();
        }
コード例 #11
0
        public void PrintTreeTest_8_ReverseOrdered()
        {
            t = new Models.Spells.SpellTree.RBTree();
            String orderTest = "";
            List <Models.Spells.Spell> spells = spellList();

            spells.Reverse();
            foreach (Spell spell in spells)
            {
                t.insert(spell);
            }

            NodeCheck(t.Root, 1, "e");
            NodeCheck(t.Root.Right, 0, "g");
            NodeCheck(t.Root.Right.Left, 1, "f");
            NodeCheck(t.Root.Right.Right, 1, "h");
            NodeCheck(t.Root.Left, 0, "c");
            NodeCheck(t.Root.Left.Right, 1, "d");
            NodeCheck(t.Root.Left.Left, 1, "b");
            NodeCheck(t.Root.Left.Left.Left, 0, "a");
        }
コード例 #12
0
        public void PrintTreeTest_8_ordered()
        {
            t = new Models.Spells.SpellTree.RBTree();
            String orderTest = "";

            foreach (Spell spell in spellList())
            {
                t.insert(spell);
                orderTest += spell.Name + " ";
                t.Order    = "";
                t.printTree();
                Assert.AreEqual(orderTest, t.Order);
            }

            NodeCheck(t.Root, 1, "d");
            NodeCheck(t.Root.Right, 0, "f");
            NodeCheck(t.Root.Right.Left, 1, "e");
            NodeCheck(t.Root.Right.Right, 1, "g");
            NodeCheck(t.Root.Right.Right.Right, 0, "h");
            NodeCheck(t.Root.Left, 0, "b");
            NodeCheck(t.Root.Left.Right, 1, "c");
            NodeCheck(t.Root.Left.Left, 1, "a");
        }
コード例 #13
0
 public void RootCheck(Models.Spells.SpellTree.RBTree tree)
 {
     Assert.AreEqual(1, tree.Root.Color);
 }