protected static void ContainsVertex_ImmutableGraph_Test( IMutableVertexSet <TestVertex> wrappedGraph, Func <IImplicitVertexSet <TestVertex> > createGraph) { IImplicitVertexSet <TestVertex> graph = createGraph(); var vertex1 = new TestVertex("1"); var vertex2 = new TestVertex("2"); var otherVertex1 = new TestVertex("1"); Assert.IsFalse(graph.ContainsVertex(vertex1)); Assert.IsFalse(graph.ContainsVertex(vertex2)); Assert.IsFalse(graph.ContainsVertex(otherVertex1)); wrappedGraph.AddVertex(vertex1); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsFalse(graph.ContainsVertex(otherVertex1)); wrappedGraph.AddVertex(vertex2); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex2)); wrappedGraph.AddVertex(otherVertex1); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsTrue(graph.ContainsVertex(otherVertex1)); }
protected static void ContainsVertex_EquatableVertex_ImmutableGraph_Test( [NotNull] IMutableVertexSet <EquatableTestVertex> wrappedGraph, [NotNull, InstantHandle] Func <IImplicitVertexSet <EquatableTestVertex> > createGraph) { IImplicitVertexSet <EquatableTestVertex> graph = createGraph(); var vertex1 = new EquatableTestVertex("1"); var vertex2 = new EquatableTestVertex("2"); var otherVertex1 = new EquatableTestVertex("1"); Assert.IsFalse(graph.ContainsVertex(vertex1)); Assert.IsFalse(graph.ContainsVertex(vertex2)); Assert.IsFalse(graph.ContainsVertex(otherVertex1)); wrappedGraph.AddVertex(vertex1); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsTrue(graph.ContainsVertex(otherVertex1)); wrappedGraph.AddVertex(vertex2); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex2)); wrappedGraph.AddVertex(otherVertex1); graph = createGraph(); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsTrue(graph.ContainsVertex(otherVertex1)); }
protected static void ComputeWithoutRoot_Throws_Test <TGraph>( [NotNull] IMutableVertexSet <int> graph, [NotNull, InstantHandle] Func <RootedSearchAlgorithmBase <int, TGraph> > createAlgorithm) where TGraph : IImplicitVertexSet <int> { RootedSearchAlgorithmBase <int, TGraph> algorithm = createAlgorithm(); Assert.Throws <InvalidOperationException>(algorithm.Compute); // Source (and target) vertex set but not to a vertex in the graph const int vertex1 = 1; algorithm = createAlgorithm(); algorithm.SetRootVertex(vertex1); algorithm.SetTargetVertex(vertex1); Assert.Throws <VertexNotFoundException>(algorithm.Compute); const int vertex2 = 2; graph.AddVertex(vertex1); algorithm = createAlgorithm(); algorithm.SetRootVertex(vertex1); algorithm.SetTargetVertex(vertex2); Assert.Throws <VertexNotFoundException>(algorithm.Compute); }
protected static void AddVertex_Throws_Test <TVertex>( IMutableVertexSet <TVertex> graph) where TVertex : class { // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => graph.AddVertex(null)); AssertNoVertex(graph); }
protected static void AddVertex_ImmutableGraph_WithUpdate( IMutableVertexSet <int> wrappedGraph, Func <IVertexSet <int> > createGraph) { IVertexSet <int> graph = createGraph(); wrappedGraph.AddVertex(1); AssertHasVertices(graph, new[] { 1 }); // Graph is updated }
protected static void AddVertex_ImmutableGraph_NoUpdate( IMutableVertexSet <int> wrappedGraph, Func <IVertexSet <int> > createGraph) { IVertexSet <int> graph = createGraph(); wrappedGraph.AddVertex(1); AssertNoVertex(graph); // Graph is not updated }
private static string[] InitVertices([NotNull] IMutableVertexSet <object> graph, int vertexCount) { var vertices = new string[vertexCount]; for (int i = 0; i < vertexCount; ++i) { vertices[i] = i.ToString(); graph.AddVertex(vertices[i]); } return(vertices); }
protected static void ContainsVertex_EquatableVertex_Test( IMutableVertexSet <EquatableTestVertex> graph) { var vertex1 = new EquatableTestVertex("1"); var vertex2 = new EquatableTestVertex("2"); var otherVertex1 = new EquatableTestVertex("1"); Assert.IsFalse(graph.ContainsVertex(vertex1)); Assert.IsFalse(graph.ContainsVertex(vertex2)); Assert.IsFalse(graph.ContainsVertex(otherVertex1)); graph.AddVertex(vertex1); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsTrue(graph.ContainsVertex(otherVertex1)); graph.AddVertex(vertex2); Assert.IsTrue(graph.ContainsVertex(vertex2)); graph.AddVertex(otherVertex1); Assert.IsTrue(graph.ContainsVertex(vertex1)); Assert.IsTrue(graph.ContainsVertex(otherVertex1)); }
protected static void AddVertex_EquatableVertex_Test( [NotNull] IMutableVertexSet <EquatableTestVertex> graph) { int vertexAdded = 0; AssertNoVertex(graph); // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local graph.VertexAdded += v => { Assert.IsNotNull(v); ++vertexAdded; }; // Vertex 1 var vertex1 = new EquatableTestVertex("1"); Assert.IsTrue(graph.AddVertex(vertex1)); Assert.AreEqual(1, vertexAdded); AssertHasVertices(graph, new[] { vertex1 }); // Vertex 2 var vertex2 = new EquatableTestVertex("2"); Assert.IsTrue(graph.AddVertex(vertex2)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); // Vertex 1 bis Assert.IsFalse(graph.AddVertex(vertex1)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); // Other "Vertex 1" var otherVertex1 = new EquatableTestVertex("1"); Assert.IsFalse(graph.AddVertex(otherVertex1)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); }
protected static void AddVertex_EquatableVertex_Test( IMutableVertexSet <EquatableTestVertex> graph) { int vertexAdded = 0; AssertNoVertex(graph); graph.VertexAdded += v => { Assert.IsNotNull(v); ++vertexAdded; }; // Vertex 1 var vertex1 = new EquatableTestVertex("1"); Assert.IsTrue(graph.AddVertex(vertex1)); Assert.AreEqual(1, vertexAdded); AssertHasVertices(graph, new[] { vertex1 }); // Vertex 2 var vertex2 = new EquatableTestVertex("2"); Assert.IsTrue(graph.AddVertex(vertex2)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); // Vertex 1 bis Assert.IsFalse(graph.AddVertex(vertex1)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); // Other "Vertex 1" var otherVertex1 = new EquatableTestVertex("1"); Assert.IsFalse(graph.AddVertex(otherVertex1)); Assert.AreEqual(2, vertexAdded); AssertHasVertices(graph, new[] { vertex1, vertex2 }); }
protected static void ComputeWithRootAndTarget_Throws_Test <TGraph>( [NotNull] IMutableVertexSet <int> graph, [NotNull] RootedSearchAlgorithmBase <int, TGraph> algorithm) where TGraph : IImplicitVertexSet <int> { const int start = 1; const int end = 2; Assert.Throws <ArgumentException>(() => algorithm.Compute(start)); graph.AddVertex(start); Assert.Throws <InvalidOperationException>(() => algorithm.Compute(start)); Assert.Throws <ArgumentException>(() => algorithm.Compute(start, end)); }