summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-02-23 20:00:05 +0100
committerAnton Khirnov <anton@khirnov.net>2023-06-28 15:52:38 +0200
commit69734ef9828854aa668b104d47e08526b7a2bed0 (patch)
tree723c03ac33995dc3f6d4faf4a7a0f34569dc39be
parent49fb496527a3557ee44cc0ac210eba2ca8dd7bc6 (diff)
doublenull: add unit tests
-rw-r--r--Makefile5
-rw-r--r--doublenull.py4
-rw-r--r--test/__init__.py0
-rw-r--r--test/test_doublenull.npzbin0 -> 103064 bytes
-rw-r--r--test/test_doublenull.py36
5 files changed, 42 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index b10c533..a64b7fb 100644
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,12 @@ $(TARGET): $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -MMD -MF $(@:.o=.d) -MT $@ -c -o $@ $<
+test: $(TARGET)
+ LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH python3 -m unittest
+
clean:
-rm -f *.o *.d $(TARGET)
-include $(OBJS:.o=.d)
-.PHONY: clean
+.PHONY: clean test
diff --git a/doublenull.py b/doublenull.py
index 5aafc06..78e5632 100644
--- a/doublenull.py
+++ b/doublenull.py
@@ -109,7 +109,7 @@ def calc_null_coordinates(times, spatial_coords, u_rays, v_rays,
for i, t in enumerate(times):
Xu = X_of_ut[:, i]
Xv = X_of_vt[:, i]
- u_of_tx[i] = interp.interp1d(Xu, u_rays)(spatial_coords)
- v_of_tx[i] = interp.interp1d(Xv, v_rays)(spatial_coords)
+ u_of_tx[i] = interp.interp1d(Xu, u_rays, fill_value = 'extrapolate')(spatial_coords)
+ v_of_tx[i] = interp.interp1d(Xv, v_rays, fill_value = 'extrapolate')(spatial_coords)
return (u_of_tx, v_of_tx)
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/__init__.py
diff --git a/test/test_doublenull.npz b/test/test_doublenull.npz
new file mode 100644
index 0000000..4745593
--- /dev/null
+++ b/test/test_doublenull.npz
Binary files differ
diff --git a/test/test_doublenull.py b/test/test_doublenull.py
new file mode 100644
index 0000000..e50003e
--- /dev/null
+++ b/test/test_doublenull.py
@@ -0,0 +1,36 @@
+import os
+from unittest import TestCase
+
+import numpy as np
+from numpy.testing import assert_allclose
+
+from math_utils import array_utils
+from nr_analysis_axi import doublenull, invars
+
+class TestDoubleNull(TestCase):
+
+ def setUp(self):
+ datafile = os.path.splitext(__file__)[0] + '.npz'
+
+ self.data = np.load(datafile)
+
+ def test_null_curves(self):
+ rays = doublenull.calc_null_curves(self.data['t'], self.data['x'],
+ self.data['gxx'], np.zeros_like(self.data['gxx']),
+ -(self.data['alpha'] ** 2))
+
+ assert_allclose(rays[0], self.data['ray_times'], 1e-12)
+ assert_allclose(rays[1], self.data['rays_pos'], 1e-12)
+ assert_allclose(rays[2], self.data['rays_neg'], 1e-12)
+
+ def test_null_coordinates(self):
+ x = self.data['x']
+ idx = x.shape[0] // 2
+ gxx = self.data['gxx']
+ uv = 0.5 * array_utils.array_reflect(invars.dist_proper(x[idx:], gxx[0, idx:]), -1)
+
+ coords = doublenull.calc_null_coordinates(self.data['t'], x, uv, uv,
+ gxx, np.zeros_like(gxx),
+ -(self.data['alpha'] ** 2))
+ assert_allclose(coords[0], self.data['uxt'], 1e-12)
+ assert_allclose(coords[1], self.data['vxt'], 1e-12)