예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
 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)