public void EmptyTest7()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     Assert.AreEqual(1, t.Size);
     t.RemoveDependency("x", "y");
     Assert.AreEqual(0, t.Size);
 }
Esempio n. 2
0
        public void SimpleTest5()
        {
            DependencyGraph dg = new DependencyGraph();

            Assert.IsFalse(dg.GetDependents("a").GetEnumerator().MoveNext());
        }
Esempio n. 3
0
            public void EmptyTest5()
            {
                DependencyGraph t = new DependencyGraph();

                t.RemoveDependency("x", "y");
            }
Esempio n. 4
0
            public void StressTest1()
            {
                // Dependency graph
                DependencyGraph t = new 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]))));
                }
            }
Esempio n. 5
0
        public void TestHasDependeesNull()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.HasDependents(null);
        }
 public void EmptyTest12()
 {
     DependencyGraph t = new 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>());
 }
Esempio n. 7
0
        public void Null2()
        {
            DependencyGraph d = new DependencyGraph();

            d.HasDependees(null);
        }
 public void Copy4()
 {
     var d1 = new DependencyGraph();
     d1.AddDependency("a", "b");
     var d2 = new DependencyGraph(d1);
     Assert.IsTrue(d1.HasDependees("b"));
     Assert.IsTrue(d2.HasDependees("b"));
 }
 public void EmptyTest3()
 {
     DependencyGraph t = new DependencyGraph();
     Assert.IsFalse(t.GetDependees("x").GetEnumerator().MoveNext());
     Assert.IsFalse(t.GetDependents("x").GetEnumerator().MoveNext());
 }
Esempio n. 10
0
 public void NonEmptyTest13()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("a", "d");
     t.AddDependency("c", "b");
     t.RemoveDependency("a", "d");
     t.AddDependency("e", "b");
     t.AddDependency("b", "d");
     t.RemoveDependency("e", "b");
     t.RemoveDependency("x", "y");
     Assert.IsTrue(t.HasDependents("a"));
     Assert.IsFalse(t.HasDependees("a"));
     Assert.IsTrue(t.HasDependents("b"));
     Assert.IsTrue(t.HasDependees("b"));
 }
Esempio n. 11
0
 public void NonEmptyTest11()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("a", "d");
     t.AddDependency("c", "b");
     t.RemoveDependency("a", "d");
     t.AddDependency("e", "b");
     t.AddDependency("b", "d");
     t.RemoveDependency("e", "b");
     t.RemoveDependency("x", "y");
     Assert.AreEqual(4, t.Size);
 }
Esempio n. 12
0
 public void EmptyTest2()
 {
     DependencyGraph t = new DependencyGraph();
     Assert.IsFalse(t.HasDependees("x"));
     Assert.IsFalse(t.HasDependents("x"));
 }
Esempio n. 13
0
 public void EmptyTest1()
 {
     DependencyGraph t = new DependencyGraph();
     Assert.AreEqual(0, t.Size);
 }
Esempio n. 14
0
 public void StaticTest1()
 {
     DependencyGraph t1 = new DependencyGraph();
     DependencyGraph t2 = new DependencyGraph();
     t1.AddDependency("x", "y");
     Assert.AreEqual(1, t1.Size);
     Assert.AreEqual(0, t2.Size);
 }
Esempio n. 15
0
 public void Null2()
 {
     DependencyGraph d = new DependencyGraph();
     d.HasDependees(null);
 }
Esempio n. 16
0
 public void Copy2()
 {
     var d1 = new DependencyGraph();
     var d2 = new DependencyGraph(d1);
     d1.AddDependency("a", "b");
     Assert.AreEqual(1, d1.Size);
     Assert.AreEqual(0, d2.Size);
 }
Esempio n. 17
0
            public void NonEmptyTest15()
            {
                DependencyGraph t = new DependencyGraph();
                t.AddDependency("x", "y");
                t.AddDependency("a", "b");
                t.AddDependency("a", "c");
                t.AddDependency("a", "d");
                t.AddDependency("c", "b");
                t.RemoveDependency("a", "d");
                t.AddDependency("e", "b");
                t.AddDependency("b", "d");
                t.RemoveDependency("e", "b");
                t.RemoveDependency("x", "y");

                IEnumerator<string> e = t.GetDependents("a").GetEnumerator();
                Assert.IsTrue(e.MoveNext());
                String s1 = e.Current;
                Assert.IsTrue(e.MoveNext());
                String s2 = e.Current;
                Assert.IsFalse(e.MoveNext());
                Assert.IsTrue(((s1 == "b") && (s2 == "c")) || ((s1 == "c") && (s2 == "b")));

                e = t.GetDependents("b").GetEnumerator();
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual("d", e.Current);
                Assert.IsFalse(e.MoveNext());

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

                e = t.GetDependents("d").GetEnumerator();
                Assert.IsFalse(e.MoveNext());
            }
Esempio n. 18
0
        public void Copy7()
        {
            var d1 = new DependencyGraph();
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    d1.AddDependency(i.ToString(), j.ToString());
                }
            }
            var d2 = new DependencyGraph(d1);

            for (int i = 0; i < 100; i++)
            {
                d1.RemoveDependency(i.ToString(), i.ToString());
                d2.AddDependency(i.ToString(), "x");
            }

            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(i, new List<string>(d1.GetDependents(i.ToString())).Count);
                Assert.AreEqual(i + 2, new List<string>(d2.GetDependents(i.ToString())).Count);
            }

            for (int j = 0; j <= 50; j++)
            {
                Assert.AreEqual(99 - j, new List<string>(d1.GetDependees(j.ToString())).Count);
                Assert.AreEqual(100 - j, new List<string>(d2.GetDependees(j.ToString())).Count);
            }

            Assert.AreEqual(100, new List<string>(d2.GetDependees("x")).Count);

            Assert.AreEqual(5050 - 100, d1.Size);
            Assert.AreEqual(5050 + 100, d2.Size);
        }
Esempio n. 19
0
 public void NonEmptyTest16()
 {
     DependencyGraph t = new 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" });
     Assert.AreEqual(4, t.Size);
 }
Esempio n. 20
0
        public void EmptyTest1()
        {
            DependencyGraph dg = new DependencyGraph();

            Assert.AreEqual(0, dg.Size);
        }
Esempio n. 21
0
 public void NonEmptyTest18()
 {
     DependencyGraph t = new 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" });
     Assert.IsTrue(t.HasDependents("a"));
     Assert.IsFalse(t.HasDependees("a"));
     Assert.IsTrue(t.HasDependents("b"));
     Assert.IsTrue(t.HasDependees("b"));
 }
Esempio n. 22
0
        public void TestRemoveDependency1()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.RemoveDependency("s", null);
        }
Esempio n. 23
0
 public void EmptyTest5()
 {
     DependencyGraph t = new DependencyGraph();
     t.RemoveDependency("x", "y");
 }
Esempio n. 24
0
        public void TestRemoveDependency()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.RemoveDependency(null, "T");
        }
Esempio n. 25
0
            public void NonEmptyTest20()
            {
                DependencyGraph t = new 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.GetDependents("a").GetEnumerator();
                Assert.IsTrue(e.MoveNext());
                String s1 = e.Current;
                Assert.IsTrue(e.MoveNext());
                String s2 = e.Current;
                Assert.IsFalse(e.MoveNext());
                Assert.IsTrue(((s1 == "b") && (s2 == "c")) || ((s1 == "c") && (s2 == "b")));

                e = t.GetDependents("b").GetEnumerator();
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual("d", e.Current);
                Assert.IsFalse(e.MoveNext());

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

                e = t.GetDependents("d").GetEnumerator();
                Assert.IsFalse(e.MoveNext());
            }
Esempio n. 26
0
            public void StressTest15()
            {
                // Dependency graph
                DependencyGraph t = new DependencyGraph();

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

                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 + 2; j < SIZE; j += 3)
                    {
                        t.RemoveDependency(letters[i], letters[j]);
                        dents[i].Remove(letters[j]);
                        dees[j].Remove(letters[i]);
                    }
                }

                // Replace a bunch of dependees
                for (int i = 0; i < SIZE; i += 2)
                {
                    HashSet <string> newDees = new HashSet <String>();
                    for (int j = 0; j < SIZE; j += 9)
                    {
                        newDees.Add(letters[j]);
                    }
                    t.ReplaceDependees(letters[i], newDees);

                    foreach (string s in dees[i])
                    {
                        dents[s[0] - 'a'].Remove(letters[i]);
                    }

                    foreach (string s in newDees)
                    {
                        dents[s[0] - 'a'].Add(letters[i]);
                    }

                    dees[i] = newDees;
                }

                // 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]))));
                }
            }
Esempio n. 27
0
            public void StressTest1()
            {
                // Dependency graph
                DependencyGraph t = new 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]))));
                }
            }
Esempio n. 28
0
        public void SimpleTest3()
        {
            DependencyGraph dg = new DependencyGraph();

            Assert.AreEqual(false, dg.HasDependents("m"));
        }
Esempio n. 29
0
 public void EmptyTest6()
 {
     DependencyGraph t = new DependencyGraph();
     t.ReplaceDependents("x", new HashSet<string>());
     t.ReplaceDependees("y", new HashSet<string>());
 }
Esempio n. 30
0
 public void Null1()
 {
     DependencyGraph d = new DependencyGraph();
     d.AddDependency("a", null);
 }
Esempio n. 31
0
            public void StressTest15()
            {
                // Dependency graph
                DependencyGraph t = new DependencyGraph();

                // A bunch of strings to use
                const int SIZE = 800;
                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 + 2; j < SIZE; j += 3)
                    {
                        t.RemoveDependency(letters[i], letters[j]);
                        dents[i].Remove(letters[j]);
                        dees[j].Remove(letters[i]);
                    }
                }

                // Replace a bunch of dependees
                for (int i = 0; i < SIZE; i += 2)
                {
                    HashSet<string> newDees = new HashSet<String>();
                    for (int j = 0; j < SIZE; j += 9)
                    {
                        newDees.Add(letters[j]);
                    }
                    t.ReplaceDependees(letters[i], newDees);

                    foreach (string s in dees[i])
                    {
                        dents[s[0] - 'a'].Remove(letters[i]);
                    }

                    foreach (string s in newDees)
                    {
                        dents[s[0] - 'a'].Add(letters[i]);
                    }

                    dees[i] = newDees;
                }

                // 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]))));
                }
            }
Esempio n. 32
0
 public void Copy1()
 {
     var d1 = new DependencyGraph();
     var d2 = new DependencyGraph(d1);
     Assert.AreEqual(0, d1.Size);
     Assert.AreEqual(0, d2.Size);
 }
Esempio n. 33
0
 public void EmptyTest8()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     Assert.IsTrue(t.HasDependees("y"));
     Assert.IsTrue(t.HasDependents("x"));
     t.RemoveDependency("x", "y");
     Assert.IsFalse(t.HasDependees("y"));
     Assert.IsFalse(t.HasDependents("x"));
 }
Esempio n. 34
0
 public void Copy3()
 {
     var d1 = new DependencyGraph();
     var d2 = new DependencyGraph(d1);
     d1.AddDependency("a", "b");
     d2.AddDependency("c", "d");
     Assert.IsTrue(d1.HasDependents("a"));
     Assert.IsFalse(d1.HasDependents("c"));
     Assert.IsFalse(d2.HasDependents("a"));
     Assert.IsTrue(d2.HasDependents("c"));
 }
Esempio n. 35
0
        public void TestReplaceDependents1()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.ReplaceDependents(null, new HashSet <string>());
        }
Esempio n. 36
0
 public void Copy6()
 {
     var d1 = new DependencyGraph();
     d1.AddDependency("b", "a");
     d1.AddDependency("e", "d");
     var d2 = new DependencyGraph(d1);
     d1.AddDependency("c", "a");
     d2.AddDependency("f", "d");
     Assert.AreEqual(2, new List<string>(d1.GetDependees("a")).Count);
     Assert.AreEqual(1, new List<string>(d1.GetDependees("d")).Count);
     Assert.AreEqual(2, new List<string>(d2.GetDependees("d")).Count);
     Assert.AreEqual(1, new List<string>(d2.GetDependees("a")).Count);
 }
Esempio n. 37
0
        public void TestGetDependeesNull()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.GetDependees(null);
        }
Esempio n. 38
0
        public void Null1()
        {
            DependencyGraph d = new DependencyGraph();

            d.AddDependency("a", null);
        }
Esempio n. 39
0
        public void TestAddDependency1()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.AddDependency("S", null);
        }
Esempio n. 40
0
 public DependencyGraph(DependencyGraph dg)
 {
     head = CreateNewNode(dg.head);
 }
Esempio n. 41
0
        public void TestAddDependency2()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.AddDependency(null, "t");
        }
Esempio n. 42
0
        public void HasDependees1()
        {
            DependencyGraph dg = new DependencyGraph();

            Assert.IsFalse(dg.HasDependees("a"));
        }
Esempio n. 43
0
 public void EmptyTest9()
 {
     DependencyGraph t = new 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());
 }