public void SetRootVertex() { var graph = new AdjacencyGraph <int, Edge <int> >(); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(graph); SetRootVertex_Test(algorithm); }
public void ComputeWithRoot() { var graph = new AdjacencyGraph <int, Edge <int> >(); graph.AddVertexRange(new[] { 0, 1 }); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(graph); algorithm.SetVertexPairs(new[] { new SEquatableEdge <int>(0, 1) }); ComputeWithRoot_Test(algorithm); }
public void SetVertexPairs_Throws() { var graph = new AdjacencyGraph <int, Edge <int> >(); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(graph); // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => algorithm.SetVertexPairs(null)); Assert.Throws <ArgumentException>(() => algorithm.SetVertexPairs(Enumerable.Empty <SEquatableEdge <int> >())); Assert.Throws <ArgumentException>(() => algorithm.SetVertexPairs(new[] { new SEquatableEdge <int>(1, 2) })); graph.AddVertex(1); Assert.Throws <ArgumentException>(() => algorithm.SetVertexPairs(new[] { new SEquatableEdge <int>(1, 2) })); }
public void TryGetVertexPairs() { var graph = new AdjacencyGraph <int, Edge <int> >(); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(graph); Assert.IsFalse(algorithm.TryGetVertexPairs(out _)); graph.AddVertexRange(new[] { 1, 2 }); algorithm.SetVertexPairs(new[] { new SEquatableEdge <int>(1, 2) }); Assert.IsTrue(algorithm.TryGetVertexPairs(out IEnumerable <SEquatableEdge <int> > pairs)); CollectionAssert.AreEqual( new[] { new SEquatableEdge <int>(1, 2) }, pairs); }
public void TarjanOfflineLeastCommonAncestor_Throws() { var vertex1 = new TestVertex("1"); var vertex2 = new TestVertex("2"); var vertex3 = new TestVertex("3"); var pairs = new[] { new SEquatableEdge <TestVertex>(vertex1, vertex2) }; var graph = new AdjacencyGraph <TestVertex, Edge <TestVertex> >(); graph.AddVertexRange(new[] { vertex1, vertex2 }); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <TestVertex, Edge <TestVertex> >(graph); // ReSharper disable AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => algorithm.Compute(null, pairs)); Assert.Throws <ArgumentNullException>(() => algorithm.Compute(vertex1, null)); Assert.Throws <ArgumentNullException>(() => algorithm.Compute(null, null)); Assert.Throws <ArgumentException>(() => algorithm.Compute(vertex3, pairs)); // ReSharper restore AssignNullToNotNullAttribute algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <TestVertex, Edge <TestVertex> >(graph); algorithm.SetRootVertex(vertex1); Assert.Throws <InvalidOperationException>(() => algorithm.Compute()); }
public void Constructor() { var graph = new AdjacencyGraph <int, Edge <int> >(); var algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(graph); AssertAlgorithmProperties(algorithm, graph); algorithm = new TarjanOfflineLeastCommonAncestorAlgorithm <int, Edge <int> >(null, graph); AssertAlgorithmProperties(algorithm, graph); #region Local function void AssertAlgorithmProperties <TVertex, TEdge>( TarjanOfflineLeastCommonAncestorAlgorithm <TVertex, TEdge> algo, IVertexListGraph <TVertex, TEdge> g) where TEdge : IEdge <TVertex> { AssertAlgorithmState(algo, g); CollectionAssert.IsEmpty(algo.Ancestors); } #endregion }