#!/usr/bin/env python
# run with nose: nosetests -v test_euler.py

from nose.tools import *
import networkx as nx
from networkx import is_eulerian,eulerian_circuit

class TestEuler:

    def test_is_eulerian(self):
        assert_true(is_eulerian(nx.complete_graph(5)))
        assert_true(is_eulerian(nx.complete_graph(7)))
        assert_true(is_eulerian(nx.hypercube_graph(4)))
        assert_true(is_eulerian(nx.hypercube_graph(6)))

        assert_false(is_eulerian(nx.complete_graph(4)))
        assert_false(is_eulerian(nx.complete_graph(6)))
        assert_false(is_eulerian(nx.hypercube_graph(3)))
        assert_false(is_eulerian(nx.hypercube_graph(5)))

        assert_false(is_eulerian(nx.petersen_graph()))

        assert_false(is_eulerian(nx.path_graph(4)))

    def test_eulerian_circuit_cycle(self):
        G=nx.cycle_graph(4)

        edges=list(eulerian_circuit(G,source=0))
        nodes=[u for u,v in edges]
        assert_equal(nodes,[0,1,2,3])
        assert_equal(edges,[(0,1),(1,2),(2,3),(3,0)])

        edges=list(eulerian_circuit(G,source=1))
        nodes=[u for u,v in edges]
        assert_equal(nodes,[1,0,3,2])
        assert_equal(edges,[(1,0),(0,3),(3,2),(2,1)])


    def test_eulerian_circuit_digraph(self):
        G=nx.DiGraph()
        G.add_cycle([0,1,2,3])

        edges=list(eulerian_circuit(G,source=0))
        nodes=[u for u,v in edges]
        assert_equal(nodes,[0,1,2,3])
        assert_equal(edges,[(0,1),(1,2),(2,3),(3,0)])

        edges=list(eulerian_circuit(G,source=1))
        nodes=[u for u,v in edges]
        assert_equal(nodes,[1,2,3,0])
        assert_equal(edges,[(1,2),(2,3),(3,0),(0,1)])


    def test_eulerian_circuit_multigraph(self):
        G=nx.MultiGraph()
        G.add_cycle([0,1,2,3])
        G.add_edge(1,2)
        G.add_edge(1,2)
        edges=list(eulerian_circuit(G,source=0))
        nodes=[u for u,v in edges]
        assert_equal(nodes,[0,1,2,1,2,3])
        assert_equal(edges,[(0,1),(1,2),(2,1),(1,2),(2,3),(3,0)])



@@ -709,25 +709,24 @@
 n_graph()))%0A
-%0A
         asse
@@ -762,24 +762,478 @@
 graph(4)))%0A%0A
+    def test_is_eulerian2(self):%0A        # not connected%0A        G = nx.Graph()%0A        G.add_nodes_from(%5B1,2,3%5D)%0A        assert_false(is_eulerian(G))%0A        # not strongly connected%0A        G = nx.DiGraph()%0A        G.add_nodes_from(%5B1,2,3%5D)%0A        assert_false(is_eulerian(G))%0A        G = nx.MultiDiGraph()%0A        G.add_edge(1,2)%0A        G.add_edge(2,3)%0A        G.add_edge(2,3)%0A        G.add_edge(3,1)%0A        assert_false(is_eulerian(G))%0A%0A        %0A%0A
     def test
@@ -2445,12 +2445,134 @@
 ),(3,0)%5D)%0A%0A%0A
+    @raises(nx.NetworkXError)%0A    def test_not_eulerian(self):    %0A        f=list(eulerian_circuit(nx.complete_graph(4)))%0A

Add more tests for euler_cycle corner cases.