public void OutGoingArcsOrEmptyPeak() { UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 3); graph.AddArc(0, 1); Assert.IsTrue(graph.OutGoingArcs(2).Count() == 0); foreach (var e in graph.OutGoingArcs(2)) { Assert.AreEqual(0, graph.OutGoingArcs(2)); Assert.AreEqual(0, e); } }
public void OutGoingArcsOr() { UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 3); graph.AddArc(0, 1); graph.AddArc(0, 2); graph.AddArc(1, 0); graph.AddArc(1, 2); graph.AddArc(2, 0); int i = 0; int[] zero = { 1, 2 }; int[] one = { 0, 2 }; int[] two = { 0 }; foreach (var e in graph.OutGoingArcs(0)) { Assert.IsTrue(graph.OutGoingArcs(0).Count() == zero.Length); Assert.IsTrue(zero[i] == e); i++; } i = 0; foreach (var e in graph.OutGoingArcs(1)) { Assert.IsTrue(graph.OutGoingArcs(1).Count() == one.Length); Assert.IsTrue(one[i] == e); i++; } i = 0; foreach (var e in graph.OutGoingArcs(2)) { Assert.IsTrue(graph.OutGoingArcs(2).Count() == two.Length); Assert.IsTrue(two[i] == e); i++; } }
public void Combine() { UnweightedGraphMatrix graph = new UnweightedGraphMatrix(false, 2); Assert.IsFalse(graph.Oriented); Assert.AreEqual(2, graph.PeakCount); // AddArc ================== graph.AddArc(0, 1); Assert.IsTrue(graph.ContainsArc(0, 1)); Assert.IsTrue(graph.ContainsArc(1, 0)); Assert.AreEqual(1, graph.InArcsCount(0)); Assert.AreEqual(1, graph.InArcsCount(1)); Assert.IsTrue(graph.OutGoingArcs(0).Count() == 1); foreach (var e in graph.OutGoingArcs(0)) { Assert.AreEqual(1, e); } Assert.IsTrue(graph.OutGoingArcs(1).Count() == 1); foreach (var e in graph.OutGoingArcs(1)) { Assert.AreEqual(0, e); } Assert.IsTrue(graph.InComingArcs(0).Count() == 1); foreach (var e in graph.InComingArcs(0)) { Assert.AreEqual(1, e); } Assert.IsTrue(graph.InComingArcs(1).Count() == 1); foreach (var e in graph.InComingArcs(1)) { Assert.AreEqual(0, e); } // AddPeak ================== graph.AddPeak(); Assert.AreEqual(3, graph.PeakCount); graph.AddArc(0, 2); Assert.IsTrue(graph.ContainsArc(0, 2)); Assert.IsTrue(graph.ContainsArc(2, 0)); Assert.AreEqual(2, graph.InArcsCount(0)); Assert.AreEqual(1, graph.InArcsCount(2)); int[] zeroIn = { 1, 2 }; int zeroInInd = 0; Assert.IsTrue(graph.InComingArcs(0).Count() == 2); foreach (var e in graph.InComingArcs(0)) { Assert.AreEqual(zeroIn[zeroInInd], e); zeroInInd++; } Assert.IsTrue(graph.InComingArcs(2).Count() == 1); foreach (var e in graph.InComingArcs(2)) { Assert.AreEqual(0, e); } int[] zeroOut = { 1, 2 }; int zeroOutInd = 0; Assert.IsTrue(graph.OutGoingArcs(0).Count() == 2); foreach (var e in graph.OutGoingArcs(0)) { Assert.AreEqual(zeroOut[zeroOutInd], e); zeroOutInd++; } Assert.IsTrue(graph.OutGoingArcs(2).Count() == 1); foreach (var e in graph.OutGoingArcs(2)) { Assert.AreEqual(0, e); } graph.AddPeak(); graph.AddArc(3, 2); graph.DeleteArc(2, 0); graph.RemovePeak(1); // Проверка ребер Assert.IsFalse(graph.ContainsArc(0, 1)); Assert.IsFalse(graph.ContainsArc(1, 0)); Assert.IsFalse(graph.ContainsArc(0, 2)); Assert.IsFalse(graph.ContainsArc(2, 0)); Assert.IsTrue(graph.ContainsArc(1, 2)); Assert.IsTrue(graph.ContainsArc(2, 1)); // Проверка вершин // Нулевая Assert.AreEqual(0, graph.InArcsCount(0)); Assert.IsTrue(graph.OutGoingArcs(0).Count() == 0); foreach (var e in graph.OutGoingArcs(0)) { Assert.AreEqual(0, e); } Assert.IsTrue(graph.InComingArcs(0).Count() == 0); foreach (var e in graph.InComingArcs(0)) { Assert.AreEqual(0, e); } // Первая Assert.AreEqual(1, graph.InArcsCount(1)); Assert.IsTrue(graph.OutGoingArcs(1).Count() == 1); foreach (var e in graph.OutGoingArcs(1)) { Assert.AreEqual(2, e); } Assert.IsTrue(graph.InComingArcs(1).Count() == 1); foreach (var e in graph.InComingArcs(1)) { Assert.AreEqual(2, e); } // Вторая Assert.AreEqual(1, graph.InArcsCount(2)); Assert.IsTrue(graph.OutGoingArcs(2).Count() == 1); foreach (var e in graph.OutGoingArcs(2)) { Assert.AreEqual(1, e); } Assert.IsTrue(graph.InComingArcs(2).Count() == 1); foreach (var e in graph.InComingArcs(2)) { Assert.AreEqual(1, e); } // Завершение Assert.IsFalse(graph.Oriented); Assert.AreEqual(3, graph.PeakCount); }