def test_normalize(x, y): assume(x != 0) assume(y != 0) a = VectorNumpy(x, y) a.normalize() assert abs(a.norm - 1) < eps
def test_limit(x, y, limits): assume(x != 0) assume(y != 0) assume(limits) a = VectorNumpy(x, y) for limit in limits: a.limit(limit) assert abs(a.norm - abs(limit)) < eps or a.norm < abs(limit)
def test_set_mag(x, y, mags): assume(x != 0) assume(y != 0) assume(mags) a = VectorNumpy(x, y) for mag in mags: a.set_mag(mag) assert abs(a.norm - abs(mag)) < eps
def test_heading(x, y, length): a = VectorNumpy(x, y) assert math.atan2(a.y, a.x) == a.heading assert -math.pi <= a.heading <= math.pi a.set_mag(length) b = VectorNumpy().from_angle(a.heading, length=a.norm) assert abs(a.x - b.x) < eps assert abs(a.y - b.y) < eps
def test_set(values): x1, x2, y1, y2 = values a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) a.set(b) assert a.x == b.x assert a.y == b.y assert a.x == x2 assert a.y == y2
def test_sub(x1, y1, x2, y2): a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) c = a - b assert c.x == a.x - b.x assert c.y == a.y - b.y assert a.x == x1 assert a.y == y1 assert b.x == x2 assert b.y == y2
def test_add(x1, y1, x2, y2): a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) c = a + b assert c.x == a.x + b.x assert c.y == a.y + b.y assert a.x == x1 assert a.y == y1 assert b.x == x2 assert b.y == y2
def test_isub(x1, y1, x2, y2): a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) c = a.copy() a -= b assert a.x == c.x - b.x assert a.y == c.y - b.y if x1 != 0 and x2 != 0: assert a.x != x2 if y1 != 0 and y2 != 0: assert a.y != y2 a -= VectorNumpy(1, 1) assert a.x == c.x - b.x - 1 assert a.y == c.y - b.y - 1
def test_iadd(x1, y1, x2, y2): a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) c = a.copy() a += b assert a.x == c.x + b.x assert a.y == c.y + b.y if x1 != 0 and x2 != 0: assert a.x != x2 if y1 != 0 and y2 != 0: assert a.y != y2 a += VectorNumpy(1, 1) assert a.x == c.x + b.x + 1 assert a.y == c.y + b.y + 1
def test_setter(x, y): a = VectorNumpy() assert a.x == 0 assert a.y == 0 a.x = x assert a.x == x assert a.y == 0 a.y = y assert a.x == x assert a.y == y a.x = 0 a.y = 0 assert a.x == 0 assert a.y == 0
def test_random(_): a = VectorNumpy().random() assert -1 <= a.x <= 1 assert -1 <= a.y <= 1
def test_from_angle(angle): a = VectorNumpy().from_angle(angle) assert abs(a.heading - angle) < eps
def test_dist(x1, y1, x2, y2): a = VectorNumpy(x1, y1) b = VectorNumpy(x2, y2) assert a.dist(b) == distance(x1, x2, y1, y2) assert b.dist(a) == distance(x1, x2, y1, y2)
def test_zero(x, y): a = VectorNumpy(x, y) a.zero() assert a.x == 0 assert a.y == 0
def test_norm(x, y): a = VectorNumpy(x, y) norm = a.norm assert norm == math.sqrt(a.x**2 + a.y**2)
def test_imul(x, y, z): a = VectorNumpy(x, y) a *= z assert a.x == x * z assert a.y == y * z