|
1 | 1 | import copy |
2 | 2 | import ctypes |
| 3 | +from typing import cast |
3 | 4 |
|
4 | 5 | import numpy as np |
5 | 6 | import pytest |
6 | 7 |
|
7 | | -from ncca.ngl import Mat3, Vec3 |
| 8 | +from ncca.ngl import Mat3, Vec3, Vec2, Vec4 |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def test_properties(): |
@@ -345,3 +346,44 @@ def test_to_metods(): |
345 | 346 | a = Vec3(1, 2, 3) |
346 | 347 | assert a.to_list() == [1, 2, 3] |
347 | 348 | assert np.array_equal(a.to_numpy(), np.array([1, 2, 3])) |
| 349 | + assert a.to_tuple() == (1, 2, 3) |
| 350 | + |
| 351 | + |
| 352 | +def test_unknown_component_kwarg(): |
| 353 | + with pytest.raises(ValueError, match="Unknown component name"): |
| 354 | + Vec3(invalid_component=1.0) |
| 355 | + |
| 356 | + |
| 357 | +def test_add_incompatible_type(): |
| 358 | + a = Vec3(1, 2, 3) |
| 359 | + b = cast(Vec3, Vec2(1, 2)) |
| 360 | + with pytest.raises(ValueError, match="Can only add Vec3 to Vec3"): |
| 361 | + _ = a + b |
| 362 | + |
| 363 | + |
| 364 | +def test_iadd_incompatible_type(): |
| 365 | + a = Vec3(1, 2, 3) |
| 366 | + b = cast(Vec3, Vec2(1, 2)) |
| 367 | + with pytest.raises(ValueError, match="Can only add Vec3 to Vec3"): |
| 368 | + a += b |
| 369 | + |
| 370 | + |
| 371 | +def test_sub_incompatible_type(): |
| 372 | + a = Vec3(1, 2, 3) |
| 373 | + b = cast(Vec3, Vec2(1, 2)) |
| 374 | + with pytest.raises(ValueError, match="Can only subtract Vec3 from Vec3"): |
| 375 | + _ = a - b |
| 376 | + |
| 377 | + |
| 378 | +def test_isub_incompatible_type(): |
| 379 | + a = Vec3(1, 2, 3) |
| 380 | + b = cast(Vec3, Vec2(1, 2)) |
| 381 | + with pytest.raises(ValueError, match="Can only subtract Vec3 from Vec3"): |
| 382 | + a -= b |
| 383 | + |
| 384 | + |
| 385 | +def test_dot_incompatible_type(): |
| 386 | + a = Vec3(1, 2, 3) |
| 387 | + b = cast(Vec3, Vec2(1, 2)) |
| 388 | + with pytest.raises(ValueError, match="Can only compute dot product with Vec3"): |
| 389 | + _ = a.dot(b) |
0 commit comments