def test_incidence_matrix(self): g = SimpleGraph(8) g.add_random_edges(15) before = g.to_adjacency_list() g.from_incidence_matrix(g.to_incidence_matrix()) after = g.to_adjacency_list() assert before == after
def test_adjacency_matrix(self): g = SimpleGraph(8) g.add_random_edges(15) before = g.to_adjacency_matrix() g.from_adjacency_matrix(before) after = g.to_adjacency_matrix() assert before == after
def test_save_to_file_and_load(self): g = SimpleGraph(8) g.add_random_edges(15) before = g.to_adjacency_list() g.save("test", "al") g.load("test.al") after = g.to_adjacency_list() assert before == after
def test_incidence_matrix_file(self): g = SimpleGraph(8) g.add_random_edges(15) before = g.to_adjacency_matrix() g.save("test", "im") g.load("test.im") after = g.to_adjacency_matrix() assert before == after
def load_graph_to_work_on(args): g = SimpleGraph() if args.load: g.load(args.load) elif args.n: g.add_nodes(int(args.n)) if args.l: g.add_random_edges(int(args.l)) elif args.p: g.connect_random(float(args.p)) return g
def load_graph_to_work_on(args): g = SimpleGraph() if args.load: g.load(args.load) elif args.n: g.add_nodes(int(args.n)) if args.l: g.add_random_edges(int(args.l)) elif args.p: g.connect_random(float(args.p)) if args.w is not None: if args.w[0]: g.assign_random_weights(int(args.w[0][0]), int(args.w[0][1])) else: g.assign_random_weights() return g
def test_add_random_edges(self): g = SimpleGraph(8) # 8 vertices => max 28 edges g.add_random_edges(8) assert len(g.edges) == 8 g.add_random_edges(20) assert len(g.edges) == 28 with pytest.raises(ValueError): g.add_random_edges(1)