Exemplo n.º 1
0
        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) }));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }