コード例 #1
0
 def test_item_get_set(self) -> None:
     result = VectorND([1, 2, 3])
     result[0] = -1
     expected_result = VectorND([-1, 2, 3])
     self.assertEqual(result, expected_result)
     self.assertEqual(result[0], expected_result[0])
     self.assertRaises(IndexError, VectorND.__getitem__, result, -1)
     self.assertRaises(IndexError, VectorND.__setitem__, result, -1, 1337)
コード例 #2
0
 def test_init(self):
     result = VectorND([-1, 1])
     self.assertEqual(result, self.v2)
     self.assertRaises(TypeError, VectorND, 0, "a")
     self.assertRaises(TypeError, VectorND, "B", 1)
     self.assertRaises(TypeError, VectorND, "B", 1)
     self.assertRaises(TypeError, VectorND)
コード例 #3
0
 def test_init(self) -> None:
     result = VectorND([-1, 1])
     self.assertEqual(result, self.v2)
     self.assertRaises(TypeError, VectorND, 0, 'a')
     self.assertRaises(TypeError, VectorND, 'B', 1)
     self.assertRaises(TypeError, VectorND, 'B', 1)
     self.assertRaises(TypeError, VectorND)
コード例 #4
0
 def test_cython_clip_vector(self) -> None:
     result = VectorND(0, 0)
     cython_clip_vector(self.v1, -1, 1, result)
     expected_result = self.v2
     self.assertEqual(result, expected_result)
     self.assertRaises(ValueError, cython_clip_vector, self.v1, 1, -1,
                       result)
コード例 #5
0
 def test_div(self) -> None:
     # Valid division
     result = self.v3 / 5
     expected_result = VectorND(0.5, -0.5)
     self.assertEqual(result, expected_result)
     # Invalid division
     self.assertRaises(TypeError, self.v1.__truediv__, 'a')
     self.assertRaises(ValueError, self.v1.__truediv__, 0)
コード例 #6
0
 def test_mul(self) -> None:
     ''' Tests the multiplication operator.
     '''
     result1 = self.v1 * 5
     expected_result1 = VectorND(0.0, 0.0)
     self.assertEqual(result1, expected_result1)
     result2 = self.v1 * self.v2
     expected_result2 = 0.0
     self.assertEqual(result2, expected_result2)
コード例 #7
0
 def test_comparison(self):
     # Test equality
     self.assertNotEqual(self.v1, self.v2)
     expected_result = VectorND(-1, 1)
     self.assertEqual(self.v2, expected_result)
     # Test less
     result = self.v1 + self.v2
     self.assertLess(result, self.v3)
     # Test greater
     self.assertGreater(self.v3, result)
コード例 #8
0
 def test_mul(self) -> None:
     # Valid multiplication
     result1 = self.v1 * 5
     expected_result1 = VectorND(0.0, 0.0)
     self.assertEqual(result1, expected_result1)
     result2 = self.v1 * self.v2
     expected_result2 = 0.0
     self.assertEqual(result2, expected_result2)
     # Invalid multiplication
     self.assertRaises(TypeError, self.v1.__mul__, 'a')
コード例 #9
0
from typing import Any
from typing import SupportsFloat

from fastvector import VectorND
from fastvector import int32
from fastvector import uint32

import pytest


V1 = VectorND(0, 0)
V2 = VectorND(-1, 1)
V3 = VectorND(2.5, -2.5)


@pytest.mark.parametrize(
    ('lhs', 'rhs', 'exp_res'),
    (
        (V1, V2, VectorND(-1, 1)),
        (V1, V3, VectorND(2.5, -2.5)),
        (V3, V2, VectorND(1.5, -1.5)),
    )
)
def test_add(lhs: VectorND, rhs: VectorND, exp_res: VectorND) -> None:
    assert lhs + rhs == exp_res


@pytest.mark.parametrize(
    ('lhs', 'rhs', 'exp_res'),
    (
        (V1, V2, VectorND(1, -1)),
コード例 #10
0
 def test_add(self) -> None:
     result = self.v1 + self.v2
     expected_result = VectorND(-1, 1)
     self.assertEqual(result, expected_result)
コード例 #11
0
 def test_sub(self) -> None:
     result = self.v2 - self.v3
     expected_result = VectorND(-3.5, 3.5)
     self.assertEqual(result, expected_result)
コード例 #12
0
 def test_len(self) -> None:
     result = VectorND([3, 4])
     self.assertEqual(len(result), len(self.v1))
コード例 #13
0
 def test_sub(self) -> None:
     ''' Tests the subtraction operator.
     '''
     result = self.v2 - self.v3
     expected_result = VectorND(-3.5, 3.5)
     self.assertEqual(result, expected_result)
コード例 #14
0
 def test_div(self) -> None:
     ''' Tests the multiplication operator.
     '''
     result = self.v3 / 5
     expected_result = VectorND(0.5, -0.5)
     self.assertEqual(result, expected_result)
コード例 #15
0
def test_str(capture_stdout: dict) -> None:
    print(str(VectorND(1.0, 2.0)))
    assert capture_stdout["stdout"] == "(array('d', [1.0, 2.0]))\n"
コード例 #16
0
 def test_add(self) -> None:
     ''' Tests the addition operator.
     '''
     result = self.v1 + self.v2
     expected_result = VectorND(-1, 1)
     self.assertEqual(result, expected_result)
コード例 #17
0
 def setUp(self) -> None:
     self.v1 = VectorND(0, 0)
     self.v2 = VectorND(-1, 1)
     self.v3 = VectorND(2.5, -2.5)
コード例 #18
0
 def setUp(self) -> None:
     self.v1 = VectorND(2.5, -2.5)
     self.v2 = VectorND(1, -1)
コード例 #19
0
def test_raises(x: Any, y: Any) -> None:
    with pytest.raises(TypeError):
        _ = VectorND(x, y)
コード例 #20
0
 def test_equality(self) -> None:
     ''' Tests the equality operator.
     '''
     self.assertNotEqual(self.v1, self.v2)
     expected_result = VectorND(-1, 1)
     self.assertEqual(self.v2, expected_result)