示例#1
0
        public void ReplaceMethodsOnEmpty()
        {
            DependencyGraph g = new DependencyGraph();

            g.AddDependency("Dependee", "Dependent");

            List <string> stringList = new List <string>();

            for (int i = 1; i < 11; i++)
            {
                stringList.Add(i + "");
            }

            Assert.IsFalse(g.HasDependees("Dependee"));
            g.ReplaceDependees("Dependee", stringList);
            Assert.IsTrue(g.HasDependees("Dependee"));

            Assert.IsFalse(g.HasDependents("Dependent"));
            g.ReplaceDependents("Dependent", stringList);
            Assert.IsTrue(g.HasDependents("Dependent"));
            Console.WriteLine(g.ToString());
        }
示例#2
0
        public void replaceDependents()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.AddDependency("a1", "a2");
            dg.AddDependency("a1", "a2");
            dg.AddDependency("a1", "a3");
            dg.AddDependency("a1", "a4");
            dg.AddDependency("a1", "a5");

            dg.ReplaceDependents("a1", new HashSet <string>()
            {
                "a7", "a8", "a9", "a10", "a11", "a12"
            });
            HashSet <String> testDependentsHashTable = new HashSet <string>(dg.GetDependents("a1"));

            Assert.IsTrue(testDependentsHashTable.Contains("a8"));
            Assert.IsTrue(testDependentsHashTable.Contains("a9"));
            Assert.IsTrue(testDependentsHashTable.Contains("a10"));
            Assert.IsTrue(testDependentsHashTable.Contains("a11"));
            Assert.IsTrue(testDependentsHashTable.Contains("a12"));
            Assert.IsTrue(testDependentsHashTable.Contains("a7"));
        }
示例#3
0
        public void PassingNullTests()
        {
            DependencyGraph g = new DependencyGraph();

            g.AddDependency("A", "B");
            List <string> stringList = new List <string>();

            stringList.Add("1a");
            stringList.Add(null);

            try {
                g.AddDependency("A", null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.AddDependency(null, "B");
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.AddDependency(null, null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.GetDependees(null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.GetDependents(null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.HasDependees(null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.HasDependents(null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.RemoveDependency("A", null);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.RemoveDependency(null, "B");
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.ReplaceDependees(null, stringList);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                stringList = null;
                g.ReplaceDependees("A", stringList);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                g.ReplaceDependents(null, stringList);
                Assert.Fail();
            } catch (Exception) {
            }

            try {
                stringList = null;
                g.ReplaceDependents("A", stringList);
                Assert.Fail();
            } catch (Exception) {
            }
        }
示例#4
0
            public void StressTest8()
            {
                // Dependency graph
                DependencyGraph t = new DependencyGraph();

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

                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 dependents
                for (int i = 0; i < SIZE; i += 2)
                {
                    HashSet <string> newDents = new HashSet <String>();
                    for (int j = 0; j < SIZE; j += 5)
                    {
                        newDents.Add(letters[j]);
                    }
                    t.ReplaceDependents(letters[i], newDents);

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

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

                    dents[i] = newDents;
                }

                // 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]))));
                }
            }
            public void StressTest8()
            {
                // Dependency graph
                DependencyGraph t = new DependencyGraph();

                // A bunch of strings to use
                const int SIZE = 400;
                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 dependents
                for (int i = 0; i < SIZE; i += 2)
                {
                    HashSet<string> newDents = new HashSet<String>();
                    for (int j = 0; j < SIZE; j += 5)
                    {
                        newDents.Add(letters[j]);
                    }
                    t.ReplaceDependents(letters[i], newDents);

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

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

                    dents[i] = newDents;
                }

                // 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]))));
                }
            }
示例#6
0
        public void TestReplaceDependents1()
        {
            DependencyGraph dg = new DependencyGraph();

            dg.ReplaceDependents(null, new HashSet <string>());
        }
 public void EmptyTest6()
 {
     DependencyGraph t = new DependencyGraph();
     t.ReplaceDependents("x", new HashSet<string>());
     t.ReplaceDependees("y", new HashSet<string>());
 }
            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());
            }
 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"));
 }
示例#10
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);
 }
示例#11
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>());
 }