hbui
2024-07-19 cb171b125c047de75cd2c7c6837e8781b8336699
stundenplan/tests/pygraph/graphdemo.tests.py
@@ -35,6 +35,54 @@
            self.assertTrue(edge in edges)
        g.for_each_edges(action)
    def test_iterate_all_vertices(self):
        g = Graph()
        g.add_edge(1, 2)
        g.add_edge(1, 3)
        g.add_edge(2, 3)
        g.add_edge(2, 4)
        vertices = []
        for v in g.vertices():
            vertices.append(v)
        expected = [1, 2, 3, 4]
        self.assertListEqual(sorted(vertices), expected)
        pass
    def test_iterate_neighbor_vertex(self):
        g = Graph()
        g.add_edge(1, 2)
        g.add_edge(1, 3)
        g.add_edge(2, 3)
        g.add_edge(2, 4)
        g.add_edge(4, 1)
        vertices = []
        for v in g.adjacent_of(1):
            vertices.append(v)
        expected = [2, 3, 4]
        self.assertListEqual(sorted(vertices), expected)
        pass
    def test_not_add_float_to_vertex(self):
        g = Graph()
        try:
            g.add_vertex(1.2)
            pass
        except TypeError as ex:
            expected_msg = "Argument 1.2 is not a valid vertex"
            self.assertEqual(str(ex), expected_msg)
            pass
        pass
    def test_not_add_string_to_vertex(self):
        g = Graph()
        try:
            g.add_vertex("add")
        except TypeError as ex:
            expected_msg = 'Argument add is not a valid vertex'
            self.assertEqual(str(ex), expected_msg)
            pass
        pass
if __name__ == '__main__':
    unittest.main()