def test_flip() -> None: """ test flip """ vectors = make_vectors([(1, 0), (1, 1), (0, 1), (0, 0)]) actual = flip(vectors) expected = make_vectors([(-1, 0), (-1, -1), (0, -1), (0, 0)]) for index in range(len(vectors)): assert actual[index] == expected[index]
def test_shift() -> None: """ test shift """ vectors = make_vectors([(1, 0), (1, 1), (0, 1), (0, 0)]) actual = shift(vectors, x=1, y=1) expected = make_vectors([(2, 1), (2, 2), (1, 2), (1, 1)]) for index in range(len(vectors)): assert actual[index] == expected[index]
def test_scale() -> None: """ test scale """ vectors = make_vectors([(1, 0), (1, 1), (0, 1), (0, 0)]) actual = scale(vectors, .5) expected = make_vectors([(.5, 0), (.5, .5), (0, .5), (0, 0)]) for index in range(len(vectors)): assert actual[index] == expected[index]
def test_sub2(): """ sub uc 2 """ u, v = make_vectors([(2, -1), (1, 0)]) assert subtract(u, v) == Vector(1, -1)
def test_sub1(): """ sub uc 1 """ u, v = make_vectors([(2, -1), (1, 0)]) assert u - v == Vector(1, -1)
def test_add2(): """ add uc 2 """ u, v = make_vectors([(2, -1), (1, 0)]) assert add(u, v) == Vector(3, -1)
def test_add1(): """ add uc 1 """ u, v = make_vectors([(2, -1), (1, 0)]) assert u + v == Vector(3, -1)
def test_multiply2(): """ multiply uc 2 """ u, v = make_vectors([(2, -1), (1, 1)]) assert multiply(u, v) == Vector(2, -1)
def test_multiply1(): """ multiply uc 1 """ u, v = make_vectors([(2, -1), (1, 1)]) assert u * v == Vector(2, -1)
def test_multiple() -> None: """ multiply """ u = [(1, 1), (0, 1), (0, 0), (1, 0)] v = make_vectors(u) for z in v: assert isinstance(z, Vector)
def test_perimeter() -> None: """ test perimiter """ vectors = make_vectors([(1, 0), (1, 1), (0, 1), (0, 0)]) actual = perimeter(Points(*vectors)) expected = 4 assert actual == expected
def test_distance() -> None: """ distance """ u, v = make_vectors([(2, -1), (1, 0)]) actual = round(distance(u, v), 3) expected = 1.414 assert actual == expected
from matlib.enums import Color from matlib.plotting import draw_shapes from matlib.vectors import ( Polygon, make_vectors, regular_polygon ) dino_vectors = make_vectors([(6,4), (3,1), (1,2), (-1,5), (-2,5), (-3,4), (-4,4), (-5,3), (-5,2), (-2,2), (-5,1), (-4,0), (-2,1), (-1,0), (0,-3), (-1,-4), (1,-4), (2,-3), (1,-2), (3,-1), (5,1)]) points = regular_polygon(7) draw_shapes(Polygon(*points, color=Color.Blue)) 6