mirror of
https://github.com/pim-n/pg-rad
synced 2026-02-03 14:43:08 +01:00
add tests for distance between objects
This commit is contained in:
36
tests/test_objects.py
Normal file
36
tests/test_objects.py
Normal file
@ -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)
|
||||||
Reference in New Issue
Block a user