Exemple #1
0
        public void EnumeratorTest()
        {
            DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
            t.AddDependency("a", "b");
            t.AddDependency("a", "c");
            t.AddDependency("c", "b");
            t.AddDependency("b", "d");

            IEnumerator <string> e = t.GetDependees("a").GetEnumerator();

            Assert.IsFalse(e.MoveNext());

            e = t.GetDependees("b").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            String s1 = e.Current;

            Assert.IsTrue(e.MoveNext());
            String s2 = e.Current;

            Assert.IsFalse(e.MoveNext());
            Assert.IsTrue(((s1 == "a") && (s2 == "c")) || ((s1 == "c") && (s2 == "a")));

            e = t.GetDependees("c").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("a", e.Current);
            Assert.IsFalse(e.MoveNext());

            e = t.GetDependees("d").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("b", e.Current);
            Assert.IsFalse(e.MoveNext());
        }
Exemple #2
0
 public void StaticTest()
 {
     DependencyGraph.DependencyGraph t1 = new DependencyGraph.DependencyGraph();
     DependencyGraph.DependencyGraph t2 = new DependencyGraph.DependencyGraph();
     t1.AddDependency("x", "y");
     Assert.AreEqual(1, t1.Size);
     Assert.AreEqual(0, t2.Size);
 }
Exemple #3
0
 public void SimpleEmptyRemoveTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("x", "y");
     Assert.AreEqual(1, t.Size);
     t.RemoveDependency("x", "y");
     Assert.AreEqual(0, t.Size);
 }
Exemple #4
0
 public void HashSetSizeTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("a", "b");
     Assert.AreEqual(1, t["b"]);
 }
Exemple #5
0
 public void SimpleReplaceTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("x", "y");
     Assert.AreEqual(t.Size, 1);
     t.RemoveDependency("x", "y");
     t.ReplaceDependents("x", new HashSet <string>());
     t.ReplaceDependees("y", new HashSet <string>());
 }
Exemple #6
0
 public void SizeTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("c", "b");
     t.AddDependency("b", "d");
     Assert.AreEqual(4, t.Size);
 }
Exemple #7
0
 public void ReplaceDependentTest1()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("a", "b");
     t.ReplaceDependents("b", new HashSet <string>()
     {
         "c", "d"
     });
     Assert.AreEqual(3, t.Size);
 }
Exemple #8
0
 public void ReplaceDependeesTest2()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.ReplaceDependees("d", new HashSet <string>()
     {
         "e", "d"
     });
     Assert.AreEqual(2, t["d"]);
 }
Exemple #9
0
 public void HasDependentDependeesTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("a", "b");
     Assert.AreEqual(2, t.Size);
     Assert.AreEqual(true, t.HasDependents("a"));
     Assert.AreEqual(false, t.HasDependents("c"));
     Assert.AreEqual(false, t.HasDependees("a"));
     Assert.AreEqual(true, t.HasDependees("c"));
 }
Exemple #10
0
        public void EmptyEnumeratorTest()
        {
            DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
            t.AddDependency("x", "y");
            IEnumerator <string> e1 = t.GetDependees("y").GetEnumerator();

            Assert.IsTrue(e1.MoveNext());
            Assert.AreEqual("x", e1.Current);
            IEnumerator <string> e2 = t.GetDependents("x").GetEnumerator();

            Assert.IsTrue(e2.MoveNext());
            Assert.AreEqual("y", e2.Current);
            t.RemoveDependency("x", "y");
            Assert.IsFalse(t.GetDependees("y").GetEnumerator().MoveNext());
            Assert.IsFalse(t.GetDependents("x").GetEnumerator().MoveNext());
        }
Exemple #11
0
        public void ReplaceThenEnumerate()
        {
            DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
            t.AddDependency("x", "b");
            t.AddDependency("a", "z");
            t.ReplaceDependents("b", new HashSet <string>());
            t.AddDependency("y", "b");
            t.ReplaceDependents("a", new HashSet <string>()
            {
                "c"
            });
            t.AddDependency("w", "d");
            t.ReplaceDependees("b", new HashSet <string>()
            {
                "a", "c"
            });
            t.ReplaceDependees("d", new HashSet <string>()
            {
                "b"
            });

            IEnumerator <string> e = t.GetDependees("a").GetEnumerator();

            Assert.IsFalse(e.MoveNext());

            e = t.GetDependees("b").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            String s1 = e.Current;

            Assert.IsTrue(e.MoveNext());
            String s2 = e.Current;

            Assert.IsFalse(e.MoveNext());
            Assert.IsTrue(((s1 == "a") && (s2 == "c")) || ((s1 == "c") && (s2 == "a")));

            e = t.GetDependees("c").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("a", e.Current);
            Assert.IsFalse(e.MoveNext());

            e = t.GetDependees("d").GetEnumerator();
            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("b", e.Current);
            Assert.IsFalse(e.MoveNext());
        }
Exemple #12
0
 public void SimpleEmptyTest()
 {
     DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();
     Assert.AreEqual(0, t.Size);
 }
Exemple #13
0
        public void StressTest()
        {
            // Dependency graph
            DependencyGraph.DependencyGraph t = new DependencyGraph.DependencyGraph();

            // A bunch of strings to use
            const int SIZE = 200;

            string[] letters = new string[SIZE];
            for (int i = 0; i < SIZE; i++)
            {
                letters[i] = ("" + (char)('a' + i));
            }

            // The correct answers
            HashSet <string>[] dents = new HashSet <string> [SIZE];
            HashSet <string>[] dees  = new HashSet <string> [SIZE];
            for (int i = 0; i < SIZE; i++)
            {
                dents[i] = new HashSet <string>();
                dees[i]  = new HashSet <string>();
            }

            // Add a bunch of dependencies
            for (int i = 0; i < SIZE; i++)
            {
                for (int j = i + 1; j < SIZE; j++)
                {
                    t.AddDependency(letters[i], letters[j]);
                    dents[i].Add(letters[j]);
                    dees[j].Add(letters[i]);
                }
            }

            // Remove a bunch of dependencies
            for (int i = 0; i < SIZE; i++)
            {
                for (int j = i + 4; j < SIZE; j += 4)
                {
                    t.RemoveDependency(letters[i], letters[j]);
                    dents[i].Remove(letters[j]);
                    dees[j].Remove(letters[i]);
                }
            }

            // Add some back
            for (int i = 0; i < SIZE; i++)
            {
                for (int j = i + 1; j < SIZE; j += 2)
                {
                    t.AddDependency(letters[i], letters[j]);
                    dents[i].Add(letters[j]);
                    dees[j].Add(letters[i]);
                }
            }

            // Remove some more
            for (int i = 0; i < SIZE; i += 2)
            {
                for (int j = i + 3; j < SIZE; j += 3)
                {
                    t.RemoveDependency(letters[i], letters[j]);
                    dents[i].Remove(letters[j]);
                    dees[j].Remove(letters[i]);
                }
            }

            // Make sure everything is right
            for (int i = 0; i < SIZE; i++)
            {
                Assert.IsTrue(dents[i].SetEquals(new HashSet <string>(t.GetDependents(letters[i]))));
                Assert.IsTrue(dees[i].SetEquals(new HashSet <string>(t.GetDependees(letters[i]))));
            }
        }