def test_clone(self): vec = Vector2D(1, 4) clone = vec.clone() assert vec == clone, 'clone should be the same as the original' assert vec.x == clone.x, 'x should be the same' assert vec.y == clone.y, 'y should be the same' # Clone negative numbers vec = Vector2D(-1, -4) clone = vec.clone() assert vec == clone, 'clone should be the same as the original' assert vec.x == clone.x, 'x should be the same' assert vec.y == clone.y, 'y should be the same'
def test_clone_rounded(self): vec = Vector2D(1.1, 4.5) block = vec.clone_rounded() assert vec != block, 'Vectors should be different' assert block.x == 1, 'x should be 1' assert block.y == 4, 'y should be 4' # Check for negatives number vec = Vector2D(-1.1, -4.5) block = vec.clone_rounded() assert vec != block, 'Vectors should be different' assert block.x == -2, 'x should be -2' assert block.y == -5, 'y should be -5' # Check for negatives & positives number vec = Vector2D(-1.1, 4.5) block = vec.clone_rounded() assert vec != block, 'Vectors should be different' assert block.x == -2, 'x should be -2' assert block.y == 4, 'y should be 4'
def test_mult(self): assert Vector2D(1, 1) * 2 == Vector2D(2, 2) assert Vector2D(1, 1) * -1 == Vector2D(-1, -1) assert Vector2D(1, 1) * 0.5 == Vector2D(0.5, 0.5)
def test_sub(self): assert Vector2D(1, 1) - Vector2D(2, 2) == Vector2D(-1, -1) assert Vector2D(1, 1) - Vector2D(-2, 2) == Vector2D(3, -1) assert Vector2D(1, 1) - (2, 2) == Vector2D(-1, -1) assert Vector2D(1, 1) - (-2, 2) == Vector2D(3, -1)
def test_add(self): assert Vector2D(1, 1) + Vector2D(2, 2) == Vector2D(3, 3) assert Vector2D(1, 1) + Vector2D(-2, 2) == Vector2D(-1, 3) assert Vector2D(1, 1) + (2, 2) == Vector2D(3, 3) assert Vector2D(1, 1) + (-2, 2) == Vector2D(-1, 3)
def test_vector(self): vec = Vector2D(1, 4) assert vec.x == 1, 'x should be 1' assert vec.y == 4, 'y should be 4'
def test_distance(self): vec = Vector2D(1, 1) vec2 = Vector2D(2, 3) assert vec.distance_squared(vec2) == 5, 'Squared distance between (1, 1) and (2, 3) should be 5'