def test_drawing_double_decorated_angles(): P = Point(0, 0, 'P') L = Point(0, 2, 'L') E = Point('-1.84', '0.8', 'E') α = Angle(L, P, E, label_vertex=True, draw_vertex=True, label_endpoints=True, draw_endpoints=True, label=Number(39, unit=r'\textdegree')) α.decoration = AngleDecoration(radius=Number('0.7', unit='cm'), eccentricity=Number('1.6')) α.decoration2 = AngleDecoration(radius=Number('1.6', unit='cm'), eccentricity=Number('1.3'), label=Number(42, unit=r'\textdegree'), color='NavyBlue', do_draw=False, thickness=None) assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (L) at (0,2); \coordinate (P) at (0,0); \coordinate (E) at (-1.84,0.8); % Draw Angle \draw[thick] (L) -- (P) -- (E) pic ["\ang{39}", angle eccentricity=1.6, draw, thick, angle """\ r"""radius = 0.7 cm] {angle = L--P--E} pic ["\ang{42}", angle eccentricity=1.3, angle radius = 1.6 cm, """\ r"""NavyBlue] {angle = L--P--E};
def test_instanciation(): """Check RightTriangle's instanciation.""" r = RightTriangle() assert r.type == 'RightTriangle' assert r.hypotenuse == LineSegment(Point(2, 1), Point(0, 0)) assert r.right_angle.mark_right assert r.right_angle.vertex == Point(2, 0)
def test_drawing_angles_with_labeled_vertex(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) α.label_vertex = True assert α.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (X) at (6,1); \coordinate (A) at (0,0); \coordinate (Y) at (3,5); % Draw Angle \draw[thick] (X) -- (A) -- (Y); % Label Points \draw (A) node[below left] {A}; \end{tikzpicture} """ Z = Point(-6, -3, 'Z') α = Angle(X, A, Z) α.label_vertex = True assert α.drawn == r"""
def test_naming(): """Check Angle's naming.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) assert α.name == r'\angle XAY' required.package['stackengine'] = required.package['scalerel'] = False config.language = 'fr' assert α.name == r'\stackon[-5pt]{XAY}{\vstretch{1.5}{\hstretch{1.6}'\ '{\widehat{\phantom{\;\;\;\;}}}}}' assert required.package['stackengine'] assert required.package['scalerel'] required.package['stackengine'] = required.package['scalerel'] = False config.language = 'en' α.naming_mode = 'from_vertex' assert α.name == r'\angle A' α.naming_mode = 'from_armspoints' with pytest.raises(RuntimeError) as excinfo: α.name assert str(excinfo.value) == 'The naming mode of this Angle is '\ '\'from_armspoints\' but the armspoints '\ 'are not defined (empty list).' α.armspoints = [('Z', ), ('T', )] assert α.name == r'\angle ZAT' with pytest.raises(ValueError) as excinfo: α.naming_mode = 'undefined' assert str(excinfo.value) == 'naming_mode must belong to {}. '\ 'Found \'undefined\' instead.'.format(AVAILABLE_NAMING_MODES)
def test_marked_angles(): """Check Angle's instanciation.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') required.tikz_library['angles'] = False theta = Angle(pointI, pointO, pointJ) assert theta.tikz_decorations() == '' theta.decoration = AngleDecoration(color='red', thickness='ultra thick', radius=Number(2)) assert theta.tikz_decorations() \ == 'pic [draw, ultra thick, angle radius = 2, red] {angle = I--O--J}' assert required.tikz_library['angles'] required.tikz_library['angles'] = False theta.mark_right = True theta.decoration = AngleDecoration() assert theta.label is None assert theta.tikz_decorations() == '' assert not required.tikz_library['angles'] assert theta.tikz_rightangle_mark() == \ '\draw[thick, cm={cos(0), sin(0), -sin(0), cos(0), (O)}]' \ ' (0.25 cm, 0) -- (0.25 cm, 0.25 cm) -- (0, 0.25 cm);' assert theta.tikz_rightangle_mark(winding='clockwise') == \ '\draw[thick, cm={cos(0), sin(0), -sin(0), cos(0), (O)}]' \ ' (0.25 cm, 0) -- (0.25 cm, -0.25 cm) -- (0, -0.25 cm);' with pytest.raises(ValueError) as excinfo: theta.tikz_rightangle_mark(winding=None) assert str(excinfo.value) == 'Expect \'clockwise\' or \'anticlockwise\'. '\ 'Found \'None\' instead.'
def test_drawing_angles_with_arrowtips(): """Check drawing standalone Angles.""" A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) α.decoration = AngleDecoration(arrow_tips='<->') assert α.drawn == r"""
def test_simple_drawing(): """Check drawing the Quadrilateral.""" r = Quadrilateral(Point(0, 0), Point(1, 0), Point(2, 2), Point(0, 3), name='PINK') r.setup_labels() assert r.drawn == r"""
def test_addition_3D(): """Check Bipoints' additions.""" pointO = Point(0, 0, 0, 'O') pointI = Point(1, 0, 0, 'I') pointJ = Point(0, 1, 1, 'J') pointA = Point(1, 1, 1, 'A') i = Bipoint(pointO, pointI) j = Bipoint(pointO, pointJ) assert i + j == Bipoint(pointO, pointA)
def test_angle_measure(): """Check angle measure between two Vectors.""" Ω = Point(0, 0) pointI = Point(1, 0) A = Point(1, 1) i = Vector(Ω, pointI) a = Vector(Ω, A) assert i.angle_measure(a) == 45 assert a.angle_measure(i) == 315
def test_dividing_points_2D(): """Check Bipoint.dividing_points() in 2D.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') i = Bipoint(pointO, pointI) assert i.dividing_points(4) == [ Point(0.25, 0), Point(0.5, 0), Point(0.75, 0) ]
def test_instanciation_errors(): """Check Point's instanciation exceptions.""" with pytest.raises(TypeError) as excinfo: Point('A', 0, 0) assert str(excinfo.value) == 'Expected a number as abscissa, ' \ 'found \'A\' instead.' with pytest.raises(TypeError) as excinfo: Point(0, 'A', 0) assert str(excinfo.value) == 'Expected a number as ordinate, ' \ 'found \'A\' instead.'
def test_AnglesSet_instanciation(): """Check AnglesSets instanciation.""" A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') Z1 = Point(1, '6.5', 'X1') α = Angle(X1, A, Y1) β = Angle(Y1, A, Z1) S = AnglesSet(α, β) assert S._tikz_draw_options() == []
def test_equality(): """Check __eq__() is correct.""" A = Point(0, 0, 'A') B = Point(1, 1, 'B') s = Bipoint(A, B) t = Bipoint(B, A) u = Bipoint(B, A) assert s != t assert t == u assert not (t == A)
def test_instanciation(): """Check LineSegment's instanciation.""" A = Point(0, 0, 'A') B = Point(10, 0, 'B') s = DividedLineSegment(A, B, n=5, fill=3) assert s.thickness == 'ultra thick' assert s.label is None assert s.label_mask is None assert s.endpoints[0].shape == '|' assert s.endpoints[1].shape == '|'
def test_instanciation_errors(): """Check DividedLineSegment's instanciation exceptions.""" A = Point(0, 0, 'A') B = Point(10, 0, 'B') with pytest.raises(TypeError) as excinfo: DividedLineSegment(A, B) assert str(excinfo.value) == 'n must be an integer >= 1, got None instead.' with pytest.raises(TypeError) as excinfo: DividedLineSegment(A, B, n=3, fill=4) assert str(excinfo.value) == 'fill must be an 1 <= integer <= self.n == ' \ '3, got 4 instead.'
def test_cross_product(): """Check cross product of two Vectors.""" Ω = Point(0, 0, 'Ω') A = Point(1, 1, 'A') with pytest.raises(TypeError) as excinfo: Vector(0, 1).cross(Bipoint(Ω, A)) assert str(excinfo.value) == 'Can only calculate the cross product of a '\ 'Vector by another Vector. '\ 'Found Bipoint(Point Ω(0, 0), Point A(1, 1)) instead.' assert Vector(1, 0).cross(Vector(0, 1)) == Vector(0, 0, 1) assert Vector(1, 0, 0).cross(Vector(0, 1, 0)) == Vector(0, 0, 1) assert Vector(3, 4, 5).cross(Vector(2, 5, 6)) == Vector(-1, -8, 7)
def test_measures_3D(): """Check Angle's measure.""" Ω = Point(0, 0, 0, 'Ω') A = Point(1, 0, 0, 'A') B = Point(1, 1, 1, 'B') α = Angle(A, Ω, B) assert α.measure.rounded(Number('0.001')) == Number(54.736) C = Point(-1, -1, -1, 'C') β = Angle(B, Ω, C) assert β.measure.rounded(Number('0.001')) == Number(180) D = Point(0, 1, 1, 'D') γ = Angle(A, Ω, D) assert γ.measure.rounded(Number('0.001')) == Number(90)
def test_drawing_AnglesSets_errors(): """Check errors when drawing AnglesSets.""" A = Point(0, 0, 'A') X1 = Point(6, 1, 'X1') Y1 = Point(3, 5, 'Y1') Z1 = Point(1, '6.5', 'X1') α = Angle(X1, A, Y1) β = Angle(Y1, A, Z1) S = AnglesSet(α, β) with pytest.raises(RuntimeError) as excinfo: S.drawn assert str(excinfo.value) == 'Two different Points have been provided ' \ 'the same name in this list: A(0, 0); X1(6, 1); Y1(3, 5); X1(1, 6.5)'
def test_instanciation(): """Check Angle's instanciation.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') pointA = Point(1, 1, 'A') theta = Angle(pointI, pointO, pointJ, mark_right=True) assert repr(theta) == 'Angle(I, O, J)' assert theta.measure == Number('90') assert isinstance(theta.decoration, AngleDecoration) assert theta.decoration.label is None assert theta.decoration.variety is None assert theta.mark_right assert theta.vertex == pointO assert theta.points == [pointI, pointO, pointJ] theta = Angle(pointA, pointO, pointI, decoration=AngleDecoration()) assert theta.measure == Number('315') assert Angle(pointI, pointO, pointA).measure == Number('45') assert not theta.mark_right assert theta.vertex == pointO assert theta.points == [pointA, pointO, pointI] theta = Angle(pointI, pointO, 60) assert theta.vertex == pointO assert theta.points[2] == Point('0.5', '0.866', 'I\'') A = Point(0, 0, 'A') X = Point(6, 1, 'X') Y = Point(3, 5, 'Y') α = Angle(X, A, Y) assert α.winding == 'anticlockwise' assert α.arms[0] == Bipoint(A, X) assert α.arms[1] == Bipoint(A, Y)
def test_addition_2D(): """Check Bipoints' additions.""" pointO = Point(0, 0, 'O') pointI = Point(1, 0, 'I') pointJ = Point(0, 1, 'J') pointA = Point(1, 1, 'A') with pytest.raises(TypeError) as excinfo: Bipoint(pointO, pointI) + 'a' assert str(excinfo.value) == 'Can only add a Bipoint to another '\ 'Bipoint. Found \'a\' instead.' i = Bipoint(pointO, pointI) j = Bipoint(pointO, pointJ) assert i + j == Bipoint(pointO, pointA) assert i.add(j) == Bipoint(pointO, pointA)
def test_drawing_with_linesegment_not_sloped_labels(): """Check drawing is correct.""" A = Point(0, 0, 'A') B = Point(1, 0, 'B') ls = LineSegment(A, B, label='4 cm') ls.sloped_label = False ls.label_position = 'automatic' assert ls.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (A) at (0,0); \coordinate (B) at (1,0); % Draw Points \draw (A) node[scale=0.67] {$\times$}; \draw (B) node[scale=0.67] {$\times$}; % Draw Line Segment \draw[thick] (A) -- (B) node[midway, below] {4 cm}; % Label Points \draw (A) node[left] {A}; \draw (B) node[right] {B}; \end{tikzpicture} """ B = Point(1, 1, 'B') ls = LineSegment(A, B, label='4 cm') ls.sloped_label = False ls.label_position = 'automatic' assert ls.drawn == r""" \begin{tikzpicture} % Declare Points \coordinate (A) at (0,0); \coordinate (B) at (1,1); % Draw Points \draw (A) node[scale=0.67] {$\times$}; \draw (B) node[scale=0.67] {$\times$}; % Draw Line Segment \draw[thick] (A) -- (B) node[midway, below right] {4 cm}; % Label Points \draw (A) node[below left] {A}; \draw (B) node[above right] {B}; \end{tikzpicture} """ ls.label_position = 'above left' assert ls.drawn == r"""
def test_addition(): """Check Vectors' additions.""" Ω = Point(0, 0, 'Ω') A = Point(1, 1, 'A') with pytest.raises(TypeError) as excinfo: Vector(0, 1) + Bipoint(Ω, A) assert str(excinfo.value) == 'Can only add a Vector to another Vector. '\ 'Found Bipoint(Point Ω(0, 0), Point A(1, 1)) instead.' u = Vector(1, 1) v = Vector(3, -7) assert u + v == Vector(4, -6) v = Vector(3, -7, 2) assert u + v == Vector(4, -6, 2) u = Vector(2, 5, -7) assert u + v == Vector(5, -2, -5)
def test_dot_product(): """Check dot product of two Vectors.""" Ω = Point(0, 0, 'Ω') A = Point(1, 1, 'A') with pytest.raises(TypeError) as excinfo: Vector(0, 1).dot(Bipoint(Ω, A)) assert str(excinfo.value) == 'Can only calculate the dot product of a '\ 'Vector by another Vector. '\ 'Found Bipoint(Point Ω(0, 0), Point A(1, 1)) instead.' u = Vector(1, 1) v = Vector(3, -7) assert u.dot(v) == -4 u = Vector(2, 5, -7) v = Vector(3, -7, 2) assert u.dot(v) == -43
def test_AnglesSet_instanciation_errors(): """Check AnglesSet's instanciation exceptions.""" pointO = Point(0, 0, 'O') with pytest.raises(TypeError) as excinfo: AnglesSet(pointO) assert str(excinfo.value) == 'Any element of an AnglesSet must be an ' \ 'Angle. Found <class \'mathmakerlib.geometry.point.Point\'> instead.'
def test_drawing_with_labeled_sides(): """Check drawing the Quadrilateral.""" r = Quadrilateral(Point(0, 0), Point(1, 0), Point(2, 2), Point(0, 3), name='PINK') with pytest.raises(ValueError) as excinfo: r.setup_labels(labels=['one', 'two', 'three']) assert str(excinfo.value) == 'All four labels must be setup. Found '\ '3 values instead.' with pytest.raises(ValueError) as excinfo: r.setup_labels(masks=[None, None]) assert str(excinfo.value) == 'All four masks must be setup. Found '\ '2 values instead.' r.setup_labels(labels=['one', 'two', 'three', 'four']) assert r.drawn == r"""
def test_bisector(): """Check bisector of two Vectors.""" Ω = Point(0, 0) pointI = Point(1, 0) J = Point(0, 1) A = Point(1, 1) i = Vector(Ω, pointI) j = Vector(Ω, J) a = Vector(Ω, A) assert i.bisector(j) == a assert j.bisector(i) == -a k = Vector(Ω, Point(2, 0)) assert k.bisector(j) == a with pytest.raises(TypeError) as excinfo: k.bisector('j') assert str(excinfo.value) == 'Can only create the bisector with another ' \ 'Vector. Found \'j\' instead.'
def test_colors(): """Check colors setting and usage.""" p = Point(0, 0, 'A') required.options['xcolor'] = set() required.package['xcolor'] = False p.color = 'blue' assert not required.package['xcolor'] assert 'dvipsnames' not in required.options['xcolor'] with pytest.raises(ValueError) as excinfo: p.color = 'UndefinedBlueOrange' assert str(excinfo.value) == 'Unknown color name: UndefinedBlueOrange. ' \ 'Only colors from xcolor\'s dvipsnames are yet supported.' assert not required.package['xcolor'] assert 'dvipsnames' not in required.options['xcolor'] p.color = 'Apricot' assert required.package['xcolor'] assert 'dvipsnames' in required.options['xcolor'] assert p.drawn == r"""
def test_equality(): """Check __eq__, __ne__ and coordinates are correct.""" p = Point(0, 0, 'A') assert p != 'A' assert not (p == 0) assert p == Point(0, 0, 'B') assert p == Point(0, 0, 'A', shape=r'$\bullet$') assert p == Point(0, 0, 'A', label='?') assert p.coordinates == Point(0, 0, 'B').coordinates assert len(set([p, Point(0, 0, 'B')])) == 1 assert len(set([Point(0, 0, 0, 'A'), Point(0, 0, 0, 'B')])) == 1
def test_rotation3D(): """Check 3D rotating.""" pointO = Point(0, 0, 0, 'O') pointA = Point(1, 0, 0, 'A') with pytest.raises(TypeError) as excinfo: pointA.rotate(pointO, Number(30), pointO) assert str(excinfo.value) == 'Expected either None or a Vector as '\ 'axis, found Point O(0, 0, 0) instead.' pointZ = Point(0, 0, 1, 'Z') vz = Vector(pointO, pointZ) assert pointA.rotate(pointO, Number(30), vz).coordinates \ == (Number('0.866'), Number('0.5'), Number('0')) pointY = Point(0, 1, 0, 'Y') vy = Vector(pointO, pointY) assert pointA.rotate(pointO, Number(30), vy).coordinates \ == (Number('0.866'), Number('0'), Number('-0.5'))
def test_belongs_to(): s = LineSegment(Point(0, 0), Point(4, 4)) assert Point(1, 1).belongs_to(s) assert not Point(3, 4).belongs_to(s) assert not Point(5, 5).belongs_to(s) with pytest.raises(TypeError) as excinfo: Point(1, 1, 'A').belongs_to(Point(3, 4, 'B')) assert str(excinfo.value) == 'Argument \'other\' must be a LineSegment. '\ 'Found Point B(3, 4) instead.'