Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def test_instanciation_from_point_and_vector_2D():
    """Check Bipoints' instanciation."""
    A = Point(0, 0, 'A')
    v = Vector(1, 1)
    assert Bipoint(A, v) == Bipoint(Point(0, 0), Point(1, 1))
    A = Point(0, 0, 'A')
    v = Vector(1, 1, 0)
    assert Bipoint(A, v).three_dimensional
    assert Bipoint(A, v) == Bipoint(Point(0, 0, 0), Point(1, 1, 0))
Exemplo n.º 4
0
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)
    ]
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def test_midpoint_3D():
    """Check Bipoint.midpoint() in 3D."""
    pointO = Point(0, 0, 0, 'O')
    pointI = Point(1, 0, 1, 'I')
    i = Bipoint(pointO, pointI)
    assert i.midpoint() == Point(0.5, 0, 0.5)
Exemplo n.º 8
0
def test_repr():
    """Check Bipoint.__repr__()"""
    A = Point(0, 0, 'A')
    B = Point(1, 1, 'B')
    assert repr(Bipoint(A, B)) == 'Bipoint(Point A(0, 0), Point B(1, 1))'
Exemplo n.º 9
0
def test_coordinates():
    """Check Bipoints' coordinates."""
    A = Point(0, 0, 'A')
    B = Point(1, 1, 'B')
    assert Bipoint(A, B).coordinates == (1, 1, 0)
Exemplo n.º 10
0
def test_point_at_2D():
    """Check Bipoint.point_at() in 2D."""
    pointO = Point(0, 0, 'O')
    pointI = Point(1, 0, 'I')
    i = Bipoint(pointO, pointI)
    assert i.point_at(0.5) == Point(0.5, 0)