mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
[EXPERIMENTAL] Fix test_graph.py tests (#4569)
* Fix some graph tests * Fix two more tests * Ensure temporary visuals get removed from scene * Fix wrong import * Remove redundant hasattr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
6fb7fa4b2f
commit
8b24a433ae
2 changed files with 13 additions and 6 deletions
|
|
@ -1564,6 +1564,9 @@ class Graph(GenericGraph):
|
|||
def __repr__(self: Graph) -> str:
|
||||
return f"Undirected graph on {len(self.vertices)} vertices and {len(self.edges)} edges"
|
||||
|
||||
def __str__(self: Graph) -> str:
|
||||
return self.__repr__()
|
||||
|
||||
|
||||
class DiGraph(GenericGraph):
|
||||
"""A directed graph.
|
||||
|
|
@ -1781,3 +1784,6 @@ class DiGraph(GenericGraph):
|
|||
|
||||
def __repr__(self: DiGraph) -> str:
|
||||
return f"Directed graph on {len(self.vertices)} vertices and {len(self.edges)} edges"
|
||||
|
||||
def __str__(self: DiGraph) -> str:
|
||||
return self.__repr__()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from manim import DiGraph, Graph, LabeledLine, Manager, Scene, Text, tempconfig
|
||||
|
|
@ -134,9 +135,9 @@ def test_custom_graph_layout_dict():
|
|||
[1, 2, 3], [(1, 2), (2, 3)], layout={1: [0, 0, 0], 2: [1, 1, 0], 3: [1, -1, 0]}
|
||||
)
|
||||
assert str(G) == "Undirected graph on 3 vertices and 2 edges"
|
||||
assert all(G.vertices[1].get_center() == [0, 0, 0])
|
||||
assert all(G.vertices[2].get_center() == [1, 1, 0])
|
||||
assert all(G.vertices[3].get_center() == [1, -1, 0])
|
||||
np.testing.assert_allclose(G.vertices[1].get_center(), [0, 0, 0])
|
||||
np.testing.assert_allclose(G.vertices[2].get_center(), [1, 1, 0])
|
||||
np.testing.assert_allclose(G.vertices[3].get_center(), [1, -1, 0])
|
||||
|
||||
|
||||
def test_graph_layouts():
|
||||
|
|
@ -165,9 +166,9 @@ def test_custom_graph_layout_function():
|
|||
return {vertex: [vertex, vertex, 0] for vertex in graph}
|
||||
|
||||
G = Graph([1, 2, 3], [(1, 2), (2, 3)], layout=layout_func)
|
||||
assert all(G.vertices[1].get_center() == [1, 1, 0])
|
||||
assert all(G.vertices[2].get_center() == [2, 2, 0])
|
||||
assert all(G.vertices[3].get_center() == [3, 3, 0])
|
||||
np.testing.assert_allclose(G.vertices[1].get_center(), [1, 1, 0])
|
||||
np.testing.assert_allclose(G.vertices[2].get_center(), [2, 2, 0])
|
||||
np.testing.assert_allclose(G.vertices[3].get_center(), [3, 3, 0])
|
||||
|
||||
|
||||
def test_custom_graph_layout_function_with_kwargs():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue