public void IsEulerianEmpty()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(Enumerable.Empty <Vertices>());

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsFalse(algorithm.IsEulerian());
        }
Exemple #2
0
        private static void AssertIsEulerian(
            bool expectedEulerian,
            [NotNull] IUndirectedGraph <int, UndirectedEdge <int> > graph)
        {
            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.AreEqual(expectedEulerian, algorithm.IsEulerian());
            Assert.AreEqual(expectedEulerian, IsEulerianGraphAlgorithm.IsEulerian(graph));
        }
        public void IsEulerianOneVertex()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(Enumerable.Empty <Vertices>());

            graph.AddVertex(420);

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsTrue(algorithm.IsEulerian());
        }
        public void IsEulerianTwoVerticesOneEdge()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(new[]
            {
                new Vertices(1, 2)
            });

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsFalse(algorithm.IsEulerian());
        }
        public void IsEulerianOneVertexWithLoop()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(new[]
            {
                new Vertices(1, 1)
            });

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsTrue(algorithm.IsEulerian());
        }
Exemple #6
0
        public void IsEulerian_Throws()
        {
            // ReSharper disable ObjectCreationAsStatement
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(
                () => new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(null));

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(
                () => IsEulerianGraphAlgorithm.IsEulerian <int, UndirectedEdge <int> >(null));
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper restore ObjectCreationAsStatement
        }
        public void IsEulerianOneComponentTrue()
        {
            var graph = ConstructGraph(new[]
            {
                new Vertices(1, 2),
                new Vertices(2, 3),
                new Vertices(3, 1)
            });

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsTrue(algorithm.IsEulerian());
        }
        public void IsEulerianOneComponentFalse()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(new[]
            {
                new Vertices(1, 2),
                new Vertices(2, 3),
                new Vertices(3, 4),
                new Vertices(4, 1),
                new Vertices(1, 3)
            });

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsFalse(algorithm.IsEulerian());
        }
        public void IsEulerianManyComponentsTrue()
        {
            UndirectedGraph <int, UndirectedEdge <int> > graph = ConstructGraph(new[]
            {
                new Vertices(1, 2),
                new Vertices(2, 3),
                new Vertices(3, 1)
            });

            graph.AddVertex(4);
            graph.AddVertex(5);

            var algorithm = new IsEulerianGraphAlgorithm <int, UndirectedEdge <int> >(graph);

            Assert.IsTrue(algorithm.IsEulerian());
        }
Exemple #10
0
        public static bool IsEulerian <TVertex>(IUndirectedGraph <TVertex, UndirectedEdge <TVertex> > g)
        {
            var algorithm = new IsEulerianGraphAlgorithm <TVertex, UndirectedEdge <TVertex> >(g);

            return(algorithm.IsEulerian());
        }