def test_operators(operator, x, y): v1 = Vect2(x, y) v2 = Vect2(y, x) v_op = operator(v1, v2) if math.isnan(operator(x, y)): assert math.isnan(v_op.x) assert math.isnan(v_op.y) else: assert v_op.x == operator(x, y) assert v_op.y == operator(y, x)
class Vects(NamedTuple): a: Vect2 = Vect2(-1, 0) b: Vect2 = Vect2(1, 0) c: Vect2 = Vect2(1, 1) d: Vect2 = Vect2(-1, -1) e: Vect2 = Vect2(0, 0)
def test_SymmetryTransform(): st = SymmetryTransform(Vect3(1, 0, 0), Vect3(0, 1, 0)) assert st.real_to_fractional(Vect2(0.5, 0.5)) == Vect2(0.5, 0.5)
def test_norm_sq(x, y): v = Vect2(x, y) if math.isnan(x) or math.isnan(y): assert math.isnan(v.norm_sq()) else: assert v.norm_sq() == x * x + y * y
def test_norm(x, y): v = Vect2(x, y) if math.isnan(x) or math.isnan(y): assert math.isnan(v.norm()) else: assert v.norm() == math.sqrt(x * x + y * y)
def test_access(): v = Vect2(0, 1) assert v.x == 0 assert v.y == 1
def test_init(): assert Vect2() assert Vect2(1, 1)