def test_instanciation_errors(): """Check errors when instanciating a new Polyhedron.""" with pytest.raises(ValueError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0)) assert str(excinfo.value) == 'At least four Points are required to be '\ 'able to build a Polyhedron. Found only 2 positional arguments, '\ 'though.' with pytest.raises(TypeError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), 'Point(0, 0, 1)') assert str(excinfo.value) == 'Only Points must be provided in order to '\ 'build a Polyhedron. Yet found <class \'str\'> as positional '\ 'argument #3.' Point.reset_names() with pytest.raises(TypeError) as excinfo: Tetrahedron(Point(0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1)) assert str(excinfo.value) == 'Points used to build a Polyhedron must '\ 'be three-dimensional Points. Found a two-dimensional Point '\ 'instead: Point A(0, 0).' with pytest.raises(TypeError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), name=1234) assert str(excinfo.value) == 'name must be a str, found 1234 instead.' with pytest.raises(ValueError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), name='ABCDE') assert str(excinfo.value) == 'A polyhedron\'s name must contain as many '\ 'letters as the polyhedron\'s number of vertices, yet found 5 '\ 'letters (name: \'ABCDE\') and 4 vertices.' with pytest.raises(TypeError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), draw_vertices=1) assert str(excinfo.value) == 'draw_vertices must be a boolean; ' \ 'got <class \'int\'> instead.' with pytest.raises(TypeError) as excinfo: Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), label_vertices=0) assert str(excinfo.value) == 'label_vertices must be a boolean; ' \ 'got <class \'int\'> instead.'
def test_instanciation(): """Check new Polyhedrons instanciations.""" Point.reset_names() t = Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1)) assert t.name == 'ABCD' assert t.label_vertices assert not t.draw_vertices assert t.vertices == [ Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1) ] assert t.edges == [ LineSegment(Point(0, 0, 0), Point(1, 0, 0)), LineSegment(Point(1, 0, 0), Point(0, 1, 0)), LineSegment(Point(0, 1, 0), Point(0, 0, 0)), LineSegment(Point(0, 1, 0), Point(0, 0, 1)), LineSegment(Point(0, 0, 1), Point(0, 0, 0)), LineSegment(Point(0, 0, 1), Point(1, 0, 0)) ] assert t.faces == [ Triangle(Point(0, 0, 0, 'A'), Point(1, 0, 0, 'B'), Point(0, 1, 0, 'C')), Triangle(Point(0, 0, 0, 'A'), Point(0, 1, 0, 'C'), Point(0, 0, 1, 'D')), Triangle(Point(0, 0, 0, 'A'), Point(0, 0, 1, 'D'), Point(1, 0, 0, 'B')), Triangle(Point(1, 0, 0, 'B'), Point(0, 1, 0, 'C'), Point(0, 0, 1, 'D')) ] Point.reset_names() t = Tetrahedron(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), name='SABC') assert t.name == 'SABC' t = Tetrahedron(Point(0, 0, 0, label='?'), Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), name='SABC')
def test_instanciation_errors(): """Check Vector's instanciation exceptions.""" Point.reset_names() with pytest.raises(TypeError) as excinfo: Vector() assert str(excinfo.value) == 'Vector() takes one, two or three arguments '\ '(0 given)' with pytest.raises(TypeError) as excinfo: Vector(Point(0, 0)) assert str(excinfo.value) == 'a Vector can be created from one Bipoint, '\ 'found Point A(0, 0) instead.' Point.reset_names() with pytest.raises(TypeError) as excinfo: Vector(Point(0, 0), 4) assert str(excinfo.value) == 'a Vector can be created from two '\ 'arguments, either two Points or two numbers. Found Point A(0, 0) '\ 'and 4 instead.' with pytest.raises(ZeroVector) as excinfo: Vector(Point(1, 1), Point(1, 1), allow_zero_length=False) assert str(excinfo.value) == 'Explicitly disallowed creation of a '\ 'zero-length Vector.'
def test_automatic_naming(): """Check automatic naming of Points.""" Point.reset_names() Point(0, 0, 'A') q = Point(1, 1) assert q.name == 'B' Point.reset_names() q = Point(1, 1) assert q.name == 'A' q = Point(1, 1, 'C') q = Point(1, 1) assert q.name == 'B' q = Point(1, 1) assert q.name == 'D' for _ in range(23): q = Point(1, 1) assert q.name == 'A$_1$' for _ in range(26): q = Point(1, 1) assert q.name == 'A$_2$' Point.reset_names() p = Point(1, 1) # 'A' q = Point(1, 1) # 'B' assert q.name == 'B' p.name = 'C' # 'A' is free q = Point(1, 1) assert q.name == 'A' q = Point(1, 1) assert q.name == 'D'
def test_drawing_angles_with_armspoints(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') α = Angle(X1, A, Y1, armspoints=[('X', ), ('Y', )], label_vertex=True, draw_vertex=True) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X1) at (6,1); \coordinate (A) at (0,0); \coordinate (Y1) at (3,5); \coordinate (X) at (4.8,0.8); \coordinate (Y) at (2.4,4); % Draw Angle \draw[thick] (X1) -- (A) -- (Y1); % Draw Vertex \draw (A) node[scale=0.67] {$\times$}; % Draw Arms' Points \draw (X) node[scale=0.67] {$\times$}; \draw (Y) node[scale=0.67] {$\times$}; % Label Points \draw (A) node[below left] {A}; \draw (X) node[below right] {X}; \draw (Y) node[above left] {Y}; \end{tikzpicture} """ Point.reset_names() A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') α = Angle(X1, A, Y1, armspoints=[('X', ), ('Y', )], label_vertex=True, draw_vertex=True) α.armspoints = [('', ), (None, )] assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X1) at (6,1); \coordinate (A) at (0,0); \coordinate (Y1) at (3,5); \coordinate (B) at (4.8,0.8); \coordinate (C) at (2.4,4); % Draw Angle \draw[thick] (X1) -- (A) -- (Y1); % Draw Vertex \draw (A) node[scale=0.67] {$\times$}; % Draw Arms' Points \draw (B) node[scale=0.67] {$\times$}; \draw (C) node[scale=0.67] {$\times$}; % Label Points \draw (A) node[below left] {A}; \draw (B) node[below right] {B}; \draw (C) node[above left] {C}; \end{tikzpicture} """ Point.reset_names() Ω = Point(0, 0, 'O') A1 = Point('2.5', 0, 'A1') D1 = Point(-2, '1.5', 'D1') α = Angle(A1, Ω, D1, armspoints=[('C', ), ('E', )], label_vertex=True, draw_vertex=True, label_armspoints=True, draw_armspoints=True) assert α.drawn == r"""