def setUp(self):
        self.eulerian4_circuit = UndirectedAdjList()
        self.eulerian4_circuit.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_circuit.make_neighbor("n1", "n2")
        self.eulerian4_circuit.make_neighbor("n1", "n3")
        self.eulerian4_circuit.make_neighbor("n2", "n4")
        self.eulerian4_circuit.make_neighbor("n3", "n4")
        
        self.eulerian4_path = UndirectedAdjList()
        self.eulerian4_path.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_path.make_neighbor("n1", "n2")
        self.eulerian4_path.make_neighbor("n1", "n3")
        self.eulerian4_path.make_neighbor("n2", "n4")
        self.eulerian4_path.make_neighbor("n4", "n3")
        self.eulerian4_path.make_neighbor("n3", "n2")

        self.star_circuit = UndirectedAdjList()
        self.star_circuit.add_nodes(["n1", "n2", "n3", "n4", "n5"])
        self.star_circuit.make_neighbor("n1", "n2")
        self.star_circuit.make_neighbor("n1", "n4")
        self.star_circuit.make_neighbor("n3", "n5")
        self.star_circuit.make_neighbor("n3", "n2")
        self.star_circuit.make_neighbor("n4", "n5")
        self.star_circuit.make_neighbor("n4", "n1")

        self.line = UndirectedAdjList()
        self.line.add_nodes(["n1", "n2", "n3", "n4"])
        self.line.make_neighbor("n1", "n2")
        self.line.make_neighbor("n2", "n3")
        self.line.make_neighbor("n3", "n4")
    def setUp(self):
        self.eulerian4_circuit = UndirectedAdjList()
        self.eulerian4_circuit.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_circuit.make_neighbor("n1", "n2")
        self.eulerian4_circuit.make_neighbor("n1", "n3")
        self.eulerian4_circuit.make_neighbor("n2", "n4")
        self.eulerian4_circuit.make_neighbor("n3", "n4")

        self.eulerian4_path = UndirectedAdjList()
        self.eulerian4_path.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_path.make_neighbor("n1", "n2")
        self.eulerian4_path.make_neighbor("n1", "n3")
        self.eulerian4_path.make_neighbor("n2", "n4")
        self.eulerian4_path.make_neighbor("n4", "n3")
        self.eulerian4_path.make_neighbor("n3", "n2")

        self.star_circuit = UndirectedAdjList()
        self.star_circuit.add_nodes(["n1", "n2", "n3", "n4", "n5"])
        self.star_circuit.make_neighbor("n1", "n2")
        self.star_circuit.make_neighbor("n1", "n4")
        self.star_circuit.make_neighbor("n3", "n5")
        self.star_circuit.make_neighbor("n3", "n2")
        self.star_circuit.make_neighbor("n4", "n5")
        self.star_circuit.make_neighbor("n4", "n1")

        self.line = UndirectedAdjList()
        self.line.add_nodes(["n1", "n2", "n3", "n4"])
        self.line.make_neighbor("n1", "n2")
        self.line.make_neighbor("n2", "n3")
        self.line.make_neighbor("n3", "n4")
class EulerianTests(unittest.TestCase):
    
    def setUp(self):
        self.eulerian4_circuit = UndirectedAdjList()
        self.eulerian4_circuit.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_circuit.make_neighbor("n1", "n2")
        self.eulerian4_circuit.make_neighbor("n1", "n3")
        self.eulerian4_circuit.make_neighbor("n2", "n4")
        self.eulerian4_circuit.make_neighbor("n3", "n4")
        
        self.eulerian4_path = UndirectedAdjList()
        self.eulerian4_path.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_path.make_neighbor("n1", "n2")
        self.eulerian4_path.make_neighbor("n1", "n3")
        self.eulerian4_path.make_neighbor("n2", "n4")
        self.eulerian4_path.make_neighbor("n4", "n3")
        self.eulerian4_path.make_neighbor("n3", "n2")

        self.star_circuit = UndirectedAdjList()
        self.star_circuit.add_nodes(["n1", "n2", "n3", "n4", "n5"])
        self.star_circuit.make_neighbor("n1", "n2")
        self.star_circuit.make_neighbor("n1", "n4")
        self.star_circuit.make_neighbor("n3", "n5")
        self.star_circuit.make_neighbor("n3", "n2")
        self.star_circuit.make_neighbor("n4", "n5")
        self.star_circuit.make_neighbor("n4", "n1")

        self.line = UndirectedAdjList()
        self.line.add_nodes(["n1", "n2", "n3", "n4"])
        self.line.make_neighbor("n1", "n2")
        self.line.make_neighbor("n2", "n3")
        self.line.make_neighbor("n3", "n4")

    def test_eulerian_circuit(self):
        self.assertTrue(is_eulerian_circuit(self.eulerian4_circuit))
        self.assertFalse(is_eulerian_circuit(self.eulerian4_path))
        self.assertTrue(is_eulerian_circuit(self.star_circuit))
        self.assertFalse(is_eulerian_circuit(self.line))
        
        # TODO Characterize Eulerian circuits for unit test checking
        present_nodes = set(["n1", "n2", "n3", "n4"])
        
        circuit = eulerian(circuit_start_node, is_eulerian_circuit, self.eulerian4_circuit)
        print(str(circuit))
        foo = present_nodes == set(circuit)
        self.assertTrue(foo)

        self.assertEqual(None, eulerian(circuit_start_node,
            is_eulerian_circuit, self.eulerian4_circuit))

    def test_eulerian_path(self):
        self.assertTrue(is_eulerian_path(self.eulerian4_path))
        self.assertFalse(is_eulerian_path(self.star_circuit))
        self.assertFalse(is_eulerian_path(self.eulerian4_circuit))
        self.assertTrue(is_eulerian_path(self.line))

        # Test determining actual Eulerian path
        # TODO Better characterization of Eulerian paths.
        eulerianpath = [
            set(["n2", "n1"]),
            set(["n1", "n3"]),
            set(["n3", "n4"]),
            set(["n4", "n2"]),
            set(["n2", "n3"]),
        ]

        self.assertEqual(eulerianpath, eulerian(path_start_node,
            is_eulerian_path, self.eulerian4_path))
        self.assertEqual(None, eulerian(path_start_node,
            is_eulerian_path, self.eulerian4_circuit))
        self.assertEqual(None, eulerian(path_start_node,
            is_eulerian_path, self.star_circuit))

        # Destroy the Eulerian path in eulerian4_path
        self.eulerian4_path.make_neighbor("n1", "n4")
        self.assertFalse(is_eulerian_path(self.eulerian4_path))
class EulerianTests(unittest.TestCase):
    def setUp(self):
        self.eulerian4_circuit = UndirectedAdjList()
        self.eulerian4_circuit.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_circuit.make_neighbor("n1", "n2")
        self.eulerian4_circuit.make_neighbor("n1", "n3")
        self.eulerian4_circuit.make_neighbor("n2", "n4")
        self.eulerian4_circuit.make_neighbor("n3", "n4")

        self.eulerian4_path = UndirectedAdjList()
        self.eulerian4_path.add_nodes(["n1", "n2", "n3", "n4"])
        self.eulerian4_path.make_neighbor("n1", "n2")
        self.eulerian4_path.make_neighbor("n1", "n3")
        self.eulerian4_path.make_neighbor("n2", "n4")
        self.eulerian4_path.make_neighbor("n4", "n3")
        self.eulerian4_path.make_neighbor("n3", "n2")

        self.star_circuit = UndirectedAdjList()
        self.star_circuit.add_nodes(["n1", "n2", "n3", "n4", "n5"])
        self.star_circuit.make_neighbor("n1", "n2")
        self.star_circuit.make_neighbor("n1", "n4")
        self.star_circuit.make_neighbor("n3", "n5")
        self.star_circuit.make_neighbor("n3", "n2")
        self.star_circuit.make_neighbor("n4", "n5")
        self.star_circuit.make_neighbor("n4", "n1")

        self.line = UndirectedAdjList()
        self.line.add_nodes(["n1", "n2", "n3", "n4"])
        self.line.make_neighbor("n1", "n2")
        self.line.make_neighbor("n2", "n3")
        self.line.make_neighbor("n3", "n4")

    def test_eulerian_circuit(self):
        self.assertTrue(is_eulerian_circuit(self.eulerian4_circuit))
        self.assertFalse(is_eulerian_circuit(self.eulerian4_path))
        self.assertTrue(is_eulerian_circuit(self.star_circuit))
        self.assertFalse(is_eulerian_circuit(self.line))

        # TODO Characterize Eulerian circuits for unit test checking
        present_nodes = set(["n1", "n2", "n3", "n4"])

        circuit = eulerian(circuit_start_node, is_eulerian_circuit,
                           self.eulerian4_circuit)
        print(str(circuit))
        foo = present_nodes == set(circuit)
        self.assertTrue(foo)

        self.assertEqual(
            None,
            eulerian(circuit_start_node, is_eulerian_circuit,
                     self.eulerian4_circuit))

    def test_eulerian_path(self):
        self.assertTrue(is_eulerian_path(self.eulerian4_path))
        self.assertFalse(is_eulerian_path(self.star_circuit))
        self.assertFalse(is_eulerian_path(self.eulerian4_circuit))
        self.assertTrue(is_eulerian_path(self.line))

        # Test determining actual Eulerian path
        # TODO Better characterization of Eulerian paths.
        eulerianpath = [
            set(["n2", "n1"]),
            set(["n1", "n3"]),
            set(["n3", "n4"]),
            set(["n4", "n2"]),
            set(["n2", "n3"]),
        ]

        self.assertEqual(
            eulerianpath,
            eulerian(path_start_node, is_eulerian_path, self.eulerian4_path))
        self.assertEqual(
            None,
            eulerian(path_start_node, is_eulerian_path,
                     self.eulerian4_circuit))
        self.assertEqual(
            None, eulerian(path_start_node, is_eulerian_path,
                           self.star_circuit))

        # Destroy the Eulerian path in eulerian4_path
        self.eulerian4_path.make_neighbor("n1", "n4")
        self.assertFalse(is_eulerian_path(self.eulerian4_path))