def test_mul(self) -> None: result1 = self.v1 * 5 expected_result1 = Vector2D(0.0, 0.0) self.assertEqual(result1, expected_result1) result2 = self.v1 * self.v2 expected_result2 = 0.0 self.assertEqual(result2, expected_result2)
def test_mul(self) -> None: ''' Tests the multiplication operator. ''' result1 = self.v1 * 5 expected_result1 = Vector2D(0.0, 0.0) self.assertEqual(result1, expected_result1) result2 = self.v1 * self.v2 expected_result2 = 0.0 self.assertEqual(result2, expected_result2)
def setUp(self) -> None: self.v1 = Vector2D(0, 0) self.v2 = Vector2D(-1, 1) self.v3 = Vector2D(2.5, -2.5)
def test_div(self) -> None: ''' Tests the multiplication operator. ''' result = self.v3 / 5 expected_result = Vector2D(0.5, -0.5) self.assertEqual(result, expected_result)
def test_sub(self) -> None: ''' Tests the subtraction operator. ''' result = self.v2 - self.v3 expected_result = Vector2D(-3.5, 3.5) self.assertEqual(result, expected_result)
def test_add(self) -> None: ''' Tests the addition operator. ''' result = self.v1 + self.v2 expected_result = Vector2D(-1, 1) self.assertEqual(result, expected_result)
def test_equality(self) -> None: ''' Tests the equality operator. ''' self.assertNotEqual(self.v1, self.v2) expected_result = Vector2D(-1, 1) self.assertEqual(self.v2, expected_result)
def test_div(self) -> None: result = self.v3 / 5 expected_result = Vector2D(0.5, -0.5) self.assertEqual(result, expected_result)
def test_sub(self) -> None: result = self.v2 - self.v3 expected_result = Vector2D(-3.5, 3.5) self.assertEqual(result, expected_result)
def test_equality(self) -> None: self.assertNotEqual(self.v1, self.v2) expected_result = Vector2D(-1, 1) self.assertEqual(self.v2, expected_result)
def test_add(self) -> None: result = self.v1 + self.v2 expected_result = Vector2D(-1, 1) self.assertEqual(result, expected_result)
def test_str(capture_stdout: dict) -> None: print(str(Vector2D(1.0, 2.0))) assert capture_stdout["stdout"] == "(1.0, 2.0)\n"
def test_repr(capture_stdout: dict) -> None: print(repr(Vector2D(1.0, 2.0))) assert capture_stdout["stdout"] == "vector.Vector2D(1.0, 2.0)\n"
def test_raises(x: Any, y: Any) -> None: with pytest.raises(TypeError): _ = Vector2D(x, y)
from typing import Any import pytest from fastvector import Vector2D V1 = Vector2D(0, 0) V2 = Vector2D(-1, 1) V3 = Vector2D(2.5, -2.5) @pytest.mark.parametrize(('lhs', 'rhs', 'exp_res'), ( (V1, V2, Vector2D(-1, 1)), (V1, V3, Vector2D(2.5, -2.5)), (V3, V2, Vector2D(1.5, -1.5)), )) def test_add(lhs: Vector2D, rhs: Vector2D, exp_res: Vector2D) -> None: assert lhs + rhs == exp_res @pytest.mark.parametrize(('lhs', 'rhs', 'exp_res'), ( (V1, V2, Vector2D(1, -1)), (V1, V3, Vector2D(-2.5, 2.5)), (V3, V2, Vector2D(3.5, -3.5)), )) def test_sub(lhs: Vector2D, rhs: Vector2D, exp_res: Vector2D) -> None: assert lhs - rhs == exp_res @pytest.mark.parametrize(('lhs', 'rhs', 'exp_res'), ( (V1, V2, 0.0), (V1, V3, 0.0),
from fastvector import Vector2D v1 = Vector2D(1, -1)