Esempio n. 1
0
        public void IsValidRedBlackTree_ForValidTree_ReturnsTrue()
        {
            //proper rbt
            RedBlackTree tree = TreeFactory.CreateValidRBT();



            Assert.IsTrue(tree.IsValidRedBlackTree());
        }
Esempio n. 2
0
        public void Delete_Always_MaintainsRBTProperties()
        {
            //proper bst
            RedBlackTree tree = TreeFactory.CreateValidRBT();

            tree.DeleteNode(tree.Root);
            //Assumption- IsValidRedBlackTree works properly, its tested in other method

            Assert.IsTrue(tree.IsValidRedBlackTree(), "Delete doesnt maintain bst or IsValidRBT failed");
        }
Esempio n. 3
0
        public void Insert_Always_MaintainsRBTProperties()
        {
            //proper rbt
            RedBlackTree tree = TreeFactory.CreateValidRBT();

            tree.InsertNode(8);
            //Assumption- IsValidBinarySearchTree works properly, its tested in other method

            Assert.IsTrue(tree.IsValidRedBlackTree(), "Insert doesnt maintain bst or IsValidRBT failed");
        }
Esempio n. 4
0
        public void ToSigmaJson_WithValidInput_CreatesValidGraph()
        {
            var tree = TreeFactory.CreateValidRBT();
            TreeToJsonConverter converter = new TreeToJsonConverter();

            var graph = new SigmaGraph(converter.ToSigmaJson(tree));

            Assert.IsTrue(graph.edges.Count == 4);
            Assert.IsTrue(graph.edges.Any(x => x.source == "0" && x.target == "1"));
            Assert.IsTrue(graph.edges.Any(x => x.source == "0" && x.target == "2"));
            Assert.IsTrue(graph.edges.Any(x => x.source == "1" && x.target == "3"));
            Assert.IsTrue(graph.edges.Any(x => x.source == "1" && x.target == "4"));
        }
Esempio n. 5
0
        public void ConvertToTree_InvertsToSigmaJson()
        {
            var tree = TreeFactory.CreateValidRBT();
            TreeToJsonConverter converter = new TreeToJsonConverter();
            var graph      = new SigmaGraph(converter.ToSigmaJson(tree));
            var treeParsed = converter.ConvertToTree(graph);

            Assert.AreEqual(tree.Root.Value, treeParsed.Root.Value);
            Assert.AreEqual(tree.Root.id, treeParsed.Root.id);


            foreach (var node in tree)
            {
                var nodeParsed = treeParsed.FindNode(node.id);
                Assert.AreEqual(node.Value, nodeParsed.Value);
            }
        }