protected static void SetRootVertex_Test <TGraph>( [NotNull] RootedAlgorithmBase <int, TGraph> algorithm) where TGraph : IImplicitVertexSet <int> { int rootVertexChangeCount = 0; algorithm.RootVertexChanged += (sender, args) => ++ rootVertexChangeCount; const int vertex1 = 0; algorithm.SetRootVertex(vertex1); Assert.AreEqual(1, rootVertexChangeCount); algorithm.TryGetRootVertex(out int root); Assert.AreEqual(vertex1, root); // Not changed algorithm.SetRootVertex(vertex1); Assert.AreEqual(1, rootVertexChangeCount); algorithm.TryGetRootVertex(out root); Assert.AreEqual(vertex1, root); const int vertex2 = 1; algorithm.SetRootVertex(vertex2); Assert.AreEqual(2, rootVertexChangeCount); algorithm.TryGetRootVertex(out root); Assert.AreEqual(vertex2, root); algorithm.SetRootVertex(vertex1); Assert.AreEqual(3, rootVertexChangeCount); algorithm.TryGetRootVertex(out root); Assert.AreEqual(vertex1, root); }
protected static void TryGetRootVertex_Test <TVertex, TGraph>( [NotNull] RootedAlgorithmBase <TVertex, TGraph> algorithm) where TVertex : new() where TGraph : IImplicitVertexSet <TVertex> { Assert.IsFalse(algorithm.TryGetRootVertex(out _)); var vertex = new TVertex(); algorithm.SetRootVertex(vertex); Assert.IsTrue(algorithm.TryGetRootVertex(out TVertex root)); AssertEqual(vertex, root); }
protected static void ComputeWithRoot_Throws_Test <TVertex, TGraph>( [NotNull, InstantHandle] Func <RootedAlgorithmBase <TVertex, TGraph> > createAlgorithm) where TVertex : class, new() where TGraph : IImplicitVertexSet <TVertex> { RootedAlgorithmBase <TVertex, TGraph> algorithm = createAlgorithm(); // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => algorithm.Compute(null)); Assert.IsFalse(algorithm.TryGetRootVertex(out _)); // Vertex not in the graph algorithm = createAlgorithm(); Assert.Throws <ArgumentException>(() => algorithm.Compute(new TVertex())); }