manim/tests/test_graph.py
Benjamin Hackl e16f9a6cc4
Basic implementation of undirected graphs (#861)
* toying around with a graph using networkx layouting

* basic implementation and documentation of a class for undirected graphs

* import graph module into global namespace

* add graph module to documentation

* poetry: add networkx as a dependency

* remove some debug prints

* sort all extracted mobjects w.r.t. z_index

* add test for z_index (from #327)

* more complex z_index test

* black

* improve imports

* use z_index to have edges below vertices

* add type hints

* rename some tests to make space for graph tests

* fix problem with manual positioning

* add test

* black

* new animate syntax

* document label_fill_color
2020-12-31 21:10:41 +01:00

11 lines
443 B
Python

from manim import Graph
def test_graph_creation():
vertices = [1, 2, 3, 4]
edges = [(1, 2), (2, 3), (3, 4), (4, 1)]
layout = {1: [0, 0, 0], 2: [1, 1, 0], 3: [1, -1, 0], 4: [-1, 0, 0]}
G_manual = Graph(vertices=vertices, edges=edges, layout=layout)
assert str(G_manual) == "Graph on 4 vertices and 4 edges"
G_spring = Graph(vertices=vertices, edges=edges)
assert str(G_spring) == "Graph on 4 vertices and 4 edges"