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); }
public void GetDependees1() { DependencyGraph dg = new DependencyGraph(); IEnumerator <string> empty = dg.GetDependees("a").GetEnumerator(); Assert.IsFalse(empty.MoveNext()); }
public void EmptyTest3() { DependencyGraph t = new DependencyGraph(); Assert.IsFalse(t.GetDependees("x").GetEnumerator().MoveNext()); Assert.IsFalse(t.GetDependents("x").GetEnumerator().MoveNext()); }
public void NonEmptyTest19() { 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.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()); }
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()); }
public void MethodsOnHugeGraph() { // Checks HasDependents and HasDependees Methods Assert.IsTrue(hugeGraph.HasDependents("0a")); Assert.IsTrue(hugeGraph.HasDependees("0b")); // Creates list for ReplaceDependents and ReplaceDependees Methods List <string> stringList = new List <string>(); for (int i = 0; i < 10; i++) { stringList.Add("new " + i); } // Checks ReplaceDependents and ReplaceDependees Methods hugeGraph.ReplaceDependents("0a", stringList); Assert.IsTrue(hugeGraph.HasDependents("0a")); hugeGraph.ReplaceDependees("0b", stringList); Assert.IsTrue(hugeGraph.HasDependees("0b")); // Checks HasDependents and HasDependees Methods to make sure the new dependencies have been added properly Assert.IsTrue(hugeGraph.HasDependents("new 0")); Assert.IsTrue(hugeGraph.HasDependees("new 0")); // Checks RemoveDependency Method hugeGraph.RemoveDependency("0a", "0b"); hugeGraph.RemoveDependency("0a", "new 0"); Assert.IsFalse(hugeGraph.HasDependees("new 0")); Assert.IsTrue(hugeGraph.HasDependents("0a")); // Checks GetDependents and GetDependees Methods foreach (string s in hugeGraph.GetDependees("0a")) { if (s.Equals("new 1")) { break; } else { Assert.Fail(); } } foreach (string s in hugeGraph.GetDependents("new 0")) { if (s.Equals("0b")) { break; } else { Assert.Fail(); } } }
public void NonEmptyTest14() { 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.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()); }
public void GetDependeesEmptyTest() { DependencyGraph g = new DependencyGraph(); g.AddDependency("A", "B"); g.AddDependency("A", "C"); string result = ""; foreach (string s in g.GetDependees("A")) { result += s + " "; } Assert.AreEqual("", result); }
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); }
public void GetDependees2() { DependencyGraph dg = new DependencyGraph(); for (int i = 0; i < 10; i++) { dg.AddDependency(i.ToString(), "a"); } IEnumerator <string> list = dg.GetDependees("a").GetEnumerator(); int j = 0; while (list.MoveNext()) { Assert.IsTrue(list.Current == j.ToString()); j++; } }
public void NullGet() { DependencyGraph g = new DependencyGraph(); g.AddDependency("A", "B"); // Get Dependees / Dependents try { g.AddDependency("A1", "B1"); g.GetDependees(null); Assert.Fail(); } catch (ArgumentNullException) { } try { g.AddDependency("A1", "B1"); g.GetDependents(null); Assert.Fail(); } catch (ArgumentNullException) { } }
public void AddTest6() { DependencyGraph dg = new DependencyGraph(); dg.AddDependency("a2", "a1"); dg.AddDependency("a3", "a1"); dg.AddDependency("a4", "a1"); dg.AddDependency("a5", "a1"); dg.AddDependency("a6", "a1"); HashSet <String> dependees = new HashSet <string>(dg.GetDependees("a1")); Assert.IsTrue(dependees.Count == 5); Assert.IsTrue(dependees.Contains("a2")); Assert.IsTrue(dependees.Contains("a3")); Assert.IsTrue(dependees.Contains("a4")); Assert.IsTrue(dependees.Contains("a5")); Assert.IsTrue(dependees.Contains("a6")); }
public void GetDependees3() { DependencyGraph dg = new DependencyGraph(); for (int i = 0; i < 100; i++) { dg.AddDependency(i.ToString(), "a"); } for (int i = 50; i < 100; i++) { dg.RemoveDependency(i.ToString(), "a"); } IEnumerator <string> list = dg.GetDependees("a").GetEnumerator(); for (int j = 0; j < 50; j++) { list.MoveNext(); Assert.IsTrue(list.Current == j.ToString()); } }
public void replaceDependees() { DependencyGraph dg = new DependencyGraph(); dg.AddDependency("a2", "a1"); dg.AddDependency("a3", "a1"); dg.AddDependency("a4", "a1"); dg.AddDependency("a5", "a1"); dg.AddDependency("a6", "a1"); dg.ReplaceDependees("a1", new HashSet <string>() { "a7", "a8", "a9", "a10", "a11", "a12" }); HashSet <String> testDependentsHashTable = new HashSet <string>(dg.GetDependees("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")); }
public void NonEmptyTest19() { 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.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()); }
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])))); } }
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); }
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])))); } }
public void TestGetDependeesNull() { DependencyGraph dg = new DependencyGraph(); dg.GetDependees(null); }
public void NonEmptyTest14() { 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.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()); }
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) { } }
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])))); } }
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); }
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])))); } }
public void SimpleTest4() { DependencyGraph dg = new DependencyGraph(); Assert.IsFalse(dg.GetDependees("a").GetEnumerator().MoveNext()); }
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()); }