Example #1
0
def test_point_distance_many_points():
    for _ in range(1000):
        x = random.randint(-1e9, 1e9)
        y = random.randint(-1e9, 1e9)
        d = math.hypot(x, y)
        p = Point(x, y)
        assert p.x == x and p.y == y
        assert math.isclose(p.distance(), d)
Example #2
0
def test_point_radius_property():
    p = Point(1, 1)
    r = math.hypot(1, 1)
    assert p.radius == r

    p.radius *= 3
    # XXX epsilons are biting me here.
    assert round(p.radius, 13) == round(3 * r, 13)

    p.radius = 0
    assert p.radius == 0 and p.is_origin
Example #3
0
def test_point_xy_property():

    p = Point(4, 5)

    assert p.xy == (4, 5)

    p.xy = (2, 3)

    assert p.x == 2 and p.y == 3

    with pytest.raises(TypeError):
        p.xy = "nonsense"

    with pytest.raises(TypeError):
        p.xy = 1
Example #4
0
def test_point_getitem_int_key():

    p = Point(1, 2)

    assert p[0] == 1
    assert p[1] == 2

    with pytest.raises(IndexError):
        p[2]
Example #5
0
def test_point_midpoint_from_origin():
    p = Point(1, 1)
    o = Point()
    r = p.midpoint()
    s = o.midpoint(p)
    assert r.x == 0.5 and r.y == 0.5
    assert s == r
Example #6
0
def test_point_midpoint_from_point():
    p = Point(1, 1)
    q = Point(2, 2)
    r = p.midpoint(q)
    s = q.midpoint(p)
    assert r.x == 1.5 and r.y == 1.5
    assert r == s
Example #7
0
def test_point_from_polar_not_origin_all_quadrants(x, y):

    radius = math.hypot(x, y)
    radians = math.atan2(y, x)
    degrees = math.degrees(radians)

    p = Point.from_polar(radius, radians)
    q = Point.from_polar(radius, degrees, is_radians=False)

    i = Point()
    i.radius = radius
    i.radians = radians

    j = Point()
    j.radius = radius
    j.degrees = degrees

    assert p.x == x and p.y == y
    assert q.x == x and q.y == y
    assert i.x == x and i.y == y
    assert j.x == x and j.y == y
    assert p == q == i == j
Example #8
0
def test_point_ccw_iterable(A, B, C):
    p = Point(*A)
    q = Point(*B)
    r = Point(*C)

    assert p.ccw(q, C) > 0
    assert p.ccw(B, r) > 0
    assert p.ccw(B, C) > 0
Example #9
0
def test_point_polar_deg_assignment():
    p = Point()
    q = Point(1, 1)
    assert p.polar_deg != q.polar_deg and p != q and p is not q
    p.polar_deg = q.polar_deg
    assert p == q

    with pytest.raises(TypeError):
        p.polar_deg = 1

    with pytest.raises(TypeError):
        p.polar_deg = "ackqux"
Example #10
0
def test_point_polar_assignment():
    p = Point()
    q = Point(1, 1)
    assert p.polar != q.polar and p != q and p is not q
    p.polar = q.polar
    assert p == q

    with pytest.raises(TypeError):
        p.polar = 1

    with pytest.raises(TypeError):
        p.polar = "foobar"
Example #11
0
def test_point_inplace_subtraction_with_iterable(A, values, result):
    r = Point(*A)
    r -= values
    assert r == result
Example #12
0
def test_point_subtraction_with_scalar(A, scalar, result):
    p = Point(*A) - scalar
    assert p == result
Example #13
0
def test_point_multiplication_with_scalar(A, scalar, result):
    p = Point(*A) * scalar
    assert p == result
Example #14
0
def test_point_multiplication_with_point(A, B, result):
    p = Point(*A)
    q = Point(*B)
    r = p * q
    assert r == result
Example #15
0
def test_point_origin_inplace_pow():
    p = Point()
    p **= 2
    assert p.x == 0 and p.y == 0
Example #16
0
def test_point_inequality():
    p = Point()
    r = Point(1, 1)
    assert p != r and p is not r
Example #17
0
def test_point_quadrant_location():
    assert Point(0, 0).quadrant == Quadrant.ORIGIN
    assert Point(1, 1).quadrant == Quadrant.I
    assert Point(-1, 1).quadrant == Quadrant.II
    assert Point(-1, -1).quadrant == Quadrant.III
    assert Point(1, -1).quadrant == Quadrant.IV
Example #18
0
def test_point_addition_with_point(A, B, expected):
    result = Point(*A) + Point(*B)
    assert result == expected
Example #19
0
def test_point_creation_without_args():
    p = Point()
    assert p.x == 0 and p.y == 0
    assert p.is_origin
    assert p.polar == (0, 0)
    assert p.quadrant == Quadrant.ORIGIN
Example #20
0
def test_point_addition_with_scalar(A, scalar, expected):
    result = Point(*A) + scalar
    assert result == expected
Example #21
0
def test_point_getitem_slice_key(A, key, expected):
    p = Point(*A)
    assert p[key] == expected
Example #22
0
def test_point_addition_with_iterable(A, iterable, expected):
    result = Point(*A) + iterable
    assert result == expected
Example #23
0
def test_point_multiplication_with_iterable(A, iterable, result):
    p = Point(*A) * iterable
    assert p == result
Example #24
0
def test_point_creation_with_x_arg():
    p = Point(1)
    q = Point(x=2)
    assert p.x == 1 and p.y == 0
    assert q.x == 2 and q.y == 0
Example #25
0
def test_point_subtraction_with_point(A, B, result):
    r = Point(*A) - Point(*B)
    assert r == result
Example #26
0
def test_point_creation_with_y_arg():
    p = Point(y=1)
    assert p.x == 0 and p.y == 1
Example #27
0
def test_point_inplace_subtraction_with_point(A, B, result):
    p = Point(*A)
    p -= Point(*B)
    assert p == result
Example #28
0
def test_point_create_with_two_args():
    p = Point(1, 2)
    assert p.x == 1 and p.y == 2
    assert not p.is_origin
Example #29
0
def test_point_inplace_subtraction_with_scalar(A, scalar, result):
    p = Point(*A)
    p -= scalar
    assert p == result
Example #30
0
def test_point_equality():
    p = Point(1, 1)
    r = Point(1, 1)
    assert p == r and p is not r