From b0892b21d8e54004b75825b3afd4d2bde3fbe840 Mon Sep 17 00:00:00 2001 From: Hanno Rein Date: Thu, 2 Jan 2025 08:54:14 -0500 Subject: [PATCH] set serialized data unit test --- rebound/tests/test_serialize.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rebound/tests/test_serialize.py b/rebound/tests/test_serialize.py index c5828497b..b7fecfd2d 100644 --- a/rebound/tests/test_serialize.py +++ b/rebound/tests/test_serialize.py @@ -26,6 +26,8 @@ def test_serialize(self): self.assertEqual(a[1][1],0) self.assertEqual(a[1][2],0) + self.sim.particles[0].xyz = [0,0,0] + b = np.zeros(self.sim.N,dtype="uint32") c = np.zeros(self.sim.N) self.sim.serialize_particle_data(r=c,hash=b) @@ -40,5 +42,27 @@ def test_serialize(self): self.sim.serialize_particle_data(xyz=c) + def test_set_serialize(self): + try: + import numpy as np + except: + # Make numpy tests optional + print("WARNING: Not testing serialization because numpy is not available") + return; + + for i in range(self.sim.N): + self.sim.particles[i].xyz = [0,0,0] + self.assertEqual(self.sim.particles[i].x,0) + self.assertEqual(self.sim.particles[i].y,0) + self.assertEqual(self.sim.particles[i].z,0) + + a = np.zeros((self.sim.N,3),dtype="float64") + a[0][1] = 2 + a[1][2] = 6 + self.sim.set_serialized_particle_data(xyz=a) + self.assertEqual(self.sim.particles[0].y,2) + self.assertEqual(self.sim.particles[1].z,6) + + if __name__ == "__main__": unittest.main()