Esempio n. 1
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>());
 }
Esempio n. 2
0
        public void StressTest8()
        {
            // 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 dependents
            for (int i = 0; i < SIZE; i += 4)
            {
                HashSet<string> newDents = new HashSet<String>();
                for (int j = 0; j < SIZE; j += 7)
                {
                    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]))));
            }
        }
Esempio n. 3
0
 public void NonEmptyTest7()
 {
     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" }));
 }
Esempio n. 4
0
 public void EmptyTest9()
 {
     DependencyGraph t = new DependencyGraph();
     t.ReplaceDependents("a", new HashSet<string>());
     Assert.AreEqual(0, t.Size);
 }
Esempio n. 5
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. 6
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"]);
 }
Esempio n. 7
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. 8
0
 public void EmptyReplaceDependentsWithSomething()
 {
     DependencyGraph t = new DependencyGraph();
     t.ReplaceDependents("a", new HashSet<string>() { "x", "y", "z" });
     Assert.AreEqual(3, t.Size);
 }
Esempio n. 9
0
 public void EmptyTest6()
 {
     DependencyGraph t = new DependencyGraph();
     t.ReplaceDependents("x", new HashSet<string>());
     t.ReplaceDependees("y", new HashSet<string>());
 }
Esempio n. 10
0
        public void MyTest3()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("a", "b");
            t.AddDependency("b", "c");
            t.AddDependency("b", "d");
            t.AddDependency("c", "d");
            t.RemoveDependency("b", "c");
            t.ReplaceDependents("b", new HashSet<string>() {"c"});
            Assert.AreEqual(3, t.Size);

        }
Esempio n. 11
0
        public void MyTest11()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("b", "b");
            t.ReplaceDependents("b", new HashSet<string>() { "c" });
            Assert.IsTrue(t.HasDependees("c"));

        }
 public void mytest15()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("d", "b");
     t.AddDependency("d", "c");
     t.AddDependency("a", "c");
     t.ReplaceDependents("a", new HashSet<string>() { "g", "a", "b", "e" });
     HashSet<String> aPends = new HashSet<string>(t.GetDependents("a"));
     Assert.IsTrue(aPends.SetEquals(new HashSet<string>() { "g", "a", "b", "e" }));
 }
Esempio n. 13
0
 public void ReplaceWithSameDependents()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     t.ReplaceDependents("a", new HashSet<string>() { "b", "c" });
     HashSet<String> cDees = new HashSet<string>(t.GetDependents("a"));
     Assert.IsTrue(cDees.SetEquals(new HashSet<string>() { "b", "c" }));
 }
Esempio n. 14
0
 public void ReplaceNonExistDependent()
 {
     DependencyGraph t = new DependencyGraph();
     t.AddDependency("a", "b");
     t.AddDependency("a", "c");
     t.AddDependency("d", "c");
     t.ReplaceDependents("e", new HashSet<string>() { "x", "y", "z" });
     HashSet<String> cDees = new HashSet<string>(t.GetDependents("e"));
     Assert.IsTrue(cDees.SetEquals(new HashSet<string>() { "x", "y", "z" }));
 }
Esempio n. 15
0
        public void MyTest()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("a", "b");
            t.AddDependency("a", "c");
            t.AddDependency("b", "d");
            t.AddDependency("d", "d");
            Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet<string>() { "b", "c" }));
            Assert.IsTrue(t.GetDependents("b").ToHashSet().SetEquals(new HashSet<string>() { "d" }));
            Assert.IsTrue(t.GetDependents("c").ToHashSet().SetEquals(new HashSet<string>() { }));
            Assert.IsTrue(t.GetDependents("d").ToHashSet().SetEquals(new HashSet<string>() { "d" }));
            Assert.IsTrue(t.GetDependees("a").ToHashSet().SetEquals(new HashSet<string>() {  }));
            Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet<string>() { "a" }));
            Assert.AreEqual(1, t["b"]);
            Assert.IsTrue(t.GetDependees("c").ToHashSet().SetEquals(new HashSet<string>() { "a" }));
            Assert.IsTrue(t.GetDependees("d").ToHashSet().SetEquals(new HashSet<string>() { "b","d" }));
            Assert.AreEqual(2, t["d"]);
            Assert.AreEqual(0, t["h"]);
            Assert.AreEqual(0, t["a"]);
            Assert.IsFalse(t.HasDependees("a"));
            Assert.IsFalse(t.HasDependees("f"));
            Assert.IsFalse(t.HasDependents("c"));
            Assert.IsTrue(t.HasDependents("a"));
            Assert.IsFalse(t.HasDependents("h"));
            Assert.IsTrue(t.HasDependents("d"));
            Assert.IsTrue(t.HasDependees("b"));
            Assert.IsTrue(t.HasDependees("c")); 
            Assert.IsTrue(t.HasDependees("d"));
            Assert.AreEqual(4, t.Size);


            
            t.RemoveDependency("a", "b");
            Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet<string>() { "c" }));
            Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet<string>() {  }));

            t.AddDependency("a", "b");
            t.AddDependency("a", "b");
            t.ReplaceDependents("a", new HashSet<string>() { "x", "y", "x", "y" ,"z"});
            Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet<string>() { "x", "y","z"}));
            Assert.AreEqual(5, t.Size);


            t.ReplaceDependees("b", new HashSet<string>() { "x", "y", "x", "y" });
            Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet<string>() { "x", "y" }));
            Assert.AreEqual(7, t.Size);
            Assert.AreEqual(2, t["b"]);
           

            //Assert.AreEqual(4, t.Size);
        }
Esempio n. 16
0
        public void ExceptionTest3()
        {
            DependencyGraph t = new DependencyGraph();
            t.AddDependency("a", "b");
            HashSet<string> emptySet = new HashSet<string>();
            //t.ReplaceDependents("a", null);
            try
            {
                t.ReplaceDependents("a", null);
                //Assert.Fail();
            }
            catch (ArgumentException) {/*Do nothing test should fail*/}
            try
            {
                t.ReplaceDependents("a", emptySet);
                Assert.IsFalse(t.HasDependents("a"));
                //Assert.Fail();
            }
            catch (ArgumentException) {/*Do nothing test should fail*/}

        }