def test_create_graph_with_badstream(self): try: data = io.StringIO('some random data') graph = Graph(None,0, data) self.assertTrue( graph.edges == 0) except Exception as e: print(e) finally: if data: data.close()
def test_create_graph_with_stream(self): try: TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'tiny_graph_data.txt') data = open(TESTDATA_FILENAME, 'r') graph = Graph(None,0, data) self.assertTrue(graph.edges>0) except Exception as e: print(e) finally: if data: data.close()
def test_graph(): graph = Graph(None, 7) graph.add_edge(0, 1) graph.add_edge(0, 2) graph.add_edge(0, 5) graph.add_edge(0, 6) graph.add_edge(6, 4) graph.add_edge(4, 3) graph.add_edge(4, 5) graph.add_edge(5, 3) print(graph.__str__())
def test_add_invalid_edge(self): graph = Graph(None, 3) self.assertRaises(ValueError, graph.add_edge,1,5)
def test_add_valid_edges(self): expected_edges = 1 graph = Graph(None, 3) graph.add_edge(1,2) self.assertEqual(expected_edges,graph.edges)
def test_get_vertex(self): expected = 3 graph = Graph(None, expected) self.assertEqual(expected,graph.vertices)
def _create_graph(self): graph = Graph(None, 4) graph.add_edge(1,3) graph.add_edge(1,2) graph.add_edge(1,0) return graph
def test_create_graph_with_vertex(self): graph = Graph(None,5) self.assertIsNotNone(graph)