public void AddTest2Test()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("A3", "A2");
     t.AddDependency("A1", "A2");
     Assert.AreEqual(2, t.Size);
 }
 public void AddTest1Test()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("A1", "A2");
     t.AddDependency("A1", "A3");
     t.RemoveDependency("A1", "A2");
     Assert.AreEqual(1, t.Size);
     t.AddDependency("A1", "A4");
     Assert.AreEqual(2, t.Size);
     HashSet<string> test = new HashSet<string>();
     test.Add("A3");
     test.Add("A4");
     Assert.AreEqual(true, test.SetEquals(t.GetDependents("A1")));
 }
Exemplo n.º 3
0
 public void EmptyTest11()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     Assert.AreEqual(t.Size, 1);
     t.RemoveDependency("x", "y");
     t.RemoveDependency("x", "y");
 }
Exemplo n.º 4
0
 public void EmptyTest10()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("x", "y");
     Assert.AreEqual(1, t["y"]);
     t.RemoveDependency("x", "y");
     Assert.AreEqual(0, t["y"]);
 }
 public void PrivateDataTest()
 {
     try
     {
         DependencyGraph dg = new DependencyGraph();
         dg.AddDependency("a", "b");
         dg.AddDependency("a", "c");
         ICollection<string> temp = (ICollection<string>)dg.GetDependents("a");
         temp.Add("d");
         Assert.IsTrue(new HashSet<string> { "b", "c", "d" }.SetEquals(temp));
         Assert.IsTrue(new HashSet<string> { "b", "c" }.SetEquals(dg.GetDependents("a")));
     }
     catch (Exception e)
     {
         if (!(e is NotSupportedException || e is InvalidCastException))
             Assert.Fail();
     }
 }
Exemplo n.º 6
0
 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>());
 }
Exemplo n.º 7
0
        public void NonEmptyTest9()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("a", "b");
            t.AddDependency("a", "c");
            t.AddDependency("a", "b");
            t.AddDependency("c", "b");
            t.AddDependency("b", "d");
            t.AddDependency("c", "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());
        }
Exemplo n.º 8
0
 public void NonEmptyTest7()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("a", "b");
     t.AddDependency("c", "b");
     t.AddDependency("b", "d");
     t.AddDependency("c", "b");
     Assert.AreEqual(2, t["b"]);
 }
Exemplo n.º 9
0
 public void nonEmptyCirclesAToB()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("b", "a");
     Assert.AreEqual(2, t.Size);
 }
Exemplo n.º 10
0
 public void NonEmptyTest6()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     t.RemoveDependency("a", "b");
     Assert.AreEqual(2, t.Size);
 }
Exemplo n.º 11
0
        public void StressTest15()
        {
            // Dependency graph
            DependencyGraph t = new DependencyGraph();

            // A bunch of strings to use
            const int SIZE = 100;
            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 += 2)
                {
                    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 += 4)
            {
                HashSet<string> newDees = new HashSet<String>();
                for (int j = 0; j < SIZE; j += 7)
                {
                    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]))));
            }
        }
Exemplo n.º 12
0
 public void NonEmptyTest2()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "b");
     Assert.AreEqual(1, t.Size);
 }
Exemplo n.º 13
0
 public void NonEmptyReplacingDependents()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     t.ReplaceDependents("a", new HashSet<string>() { "x", "y", "z" });
     HashSet<String> aPends = new HashSet<string>(t.GetDependents("a"));
     Assert.IsTrue(aPends.SetEquals(new HashSet<string>() { "x", "y", "z" }));
 }
Exemplo n.º 14
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);
 }
Exemplo n.º 15
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"));
 }
Exemplo n.º 16
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());
 }
Exemplo n.º 17
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"));
 }
Exemplo n.º 18
0
 public void nonEmptySelfReference()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "a");
     Assert.AreEqual(1, t.Size);
 }
Exemplo n.º 19
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);
 }
Exemplo n.º 20
0
 public void NonEmptyTest4()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     HashSet<String> aDents = new HashSet<String>(t.GetDependents("a"));
     HashSet<String> bDents = new HashSet<String>(t.GetDependents("b"));
     HashSet<String> cDents = new HashSet<String>(t.GetDependents("c"));
     HashSet<String> dDents = new HashSet<String>(t.GetDependents("d"));
     HashSet<String> eDents = new HashSet<String>(t.GetDependents("e"));
     HashSet<String> aDees = new HashSet<String>(t.GetDependees("a"));
     HashSet<String> bDees = new HashSet<String>(t.GetDependees("b"));
     HashSet<String> cDees = new HashSet<String>(t.GetDependees("c"));
     HashSet<String> dDees = new HashSet<String>(t.GetDependees("d"));
     HashSet<String> eDees = new HashSet<String>(t.GetDependees("e"));
     Assert.IsTrue(aDents.Count == 2 && aDents.Contains("b") && aDents.Contains("c"));
     Assert.IsTrue(bDents.Count == 0);
     Assert.IsTrue(cDents.Count == 0);
     Assert.IsTrue(dDents.Count == 1 && dDents.Contains("c"));
     Assert.IsTrue(eDents.Count == 0);
     Assert.IsTrue(aDees.Count == 0);
     Assert.IsTrue(bDees.Count == 1 && bDees.Contains("a"));
     Assert.IsTrue(cDees.Count == 2 && cDees.Contains("a") && cDees.Contains("d"));
     Assert.IsTrue(dDees.Count == 0);
     Assert.IsTrue(dDees.Count == 0);
 }
Exemplo n.º 21
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]))));
            }
        }
Exemplo n.º 22
0
 public void nonEmptyRedundantStore()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "b");
     t.AddDependency("a", "b");
     Assert.AreEqual(1, t.Size);
 }
Exemplo n.º 23
0
 public void NonEmptyTest3()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     Assert.IsFalse(t.HasDependees("a"));
     Assert.IsTrue(t.HasDependees("b"));
     Assert.IsTrue(t.HasDependents("a"));
     Assert.IsTrue(t.HasDependees("c"));
 }
Exemplo n.º 24
0
 public void NonEmptyTest17()
 {
     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(2, t["b"]);
 }
Exemplo n.º 25
0
 public void NonEmptyTest5()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     Assert.AreEqual(0, t["a"]);
     Assert.AreEqual(1, t["b"]);
     Assert.AreEqual(2, t["c"]);
     Assert.AreEqual(0, t["d"]);
     Assert.AreEqual(0, t["e"]);
 }
Exemplo n.º 26
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"));
 }
Exemplo n.º 27
0
 public void NonEmptyTest8()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     t.ReplaceDependees("c", new HashSet<string>() { "x", "y", "z" });
     HashSet<String> cDees = new HashSet<string>(t.GetDependees("c"));
     Assert.IsTrue(cDees.SetEquals(new HashSet<string>() { "x", "y", "z" }));
 }
Exemplo n.º 28
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());
        }
Exemplo n.º 29
0
 public void EmptyTest8()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
 }
Exemplo n.º 30
0
        public void MyTest11()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("b", "b");
            t.ReplaceDependents("b", new HashSet<string>() { "c" });
            Assert.IsTrue(t.HasDependees("c"));

        }