From c6c92e8f0d78f0c48b90df65cd50c4884bd4ccda Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Tue, 27 Jan 2026 19:38:18 +0100 Subject: [PATCH] add tests for distance between objects --- tests/test_objects.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_objects.py diff --git a/tests/test_objects.py b/tests/test_objects.py new file mode 100644 index 0000000..bde3dd3 --- /dev/null +++ b/tests/test_objects.py @@ -0,0 +1,36 @@ +import numpy as np +import pytest + +from pg_rad.objects import Source + +@pytest.fixture +def test_sources(): + pos_a = np.random.rand(3) + pos_b = np.random.rand(3) + + a = Source(*tuple(pos_a), strength = None) + b = Source(*tuple(pos_b), strength = None) + + return pos_a, pos_b, a, b + +def test_if_distances_equal(test_sources): + """_Verify whether from object A to object B is the same as B to A._""" + + _, _, a, b = test_sources + + assert a.distance_to(b) == b.distance_to(a) + +def test_distance_calculation(test_sources): + """_Verify whether distance between two static objects (e.g. sources) + is calculated correctly._""" + + pos_a, pos_b, a, b = test_sources + + dx = pos_b[0] - pos_a[0] + dy = pos_b[1] - pos_a[1] + dz = pos_b[2] - pos_a[2] + + assert np.isclose( + a.distance_to(b), + np.sqrt(dx**2 + dy**2 + dz**2), + rtol = 1e-12) \ No newline at end of file