summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2012-01-16 12:10:06 -0500
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:38 -0700
commitc3e072e5e5725f019e34ebc3d42489ced5094491 (patch)
treefbc1f7470042e8c6c4cce82c723541e0c7ee8d2f /test
parent7947f295b077fb830517b70693afc6283074dfd5 (diff)
downloadchroma-c3e072e5e5725f019e34ebc3d42489ced5094491.tar.gz
chroma-c3e072e5e5725f019e34ebc3d42489ced5094491.tar.bz2
chroma-c3e072e5e5725f019e34ebc3d42489ced5094491.zip
Basic BVH cache. Further implementation requires creation of BVH class.
Diffstat (limited to 'test')
-rw-r--r--test/test_cache.py77
1 files changed, 76 insertions, 1 deletions
diff --git a/test/test_cache.py b/test/test_cache.py
index e0162c8..e4bb165 100644
--- a/test/test_cache.py
+++ b/test/test_cache.py
@@ -4,7 +4,8 @@ import shutil
import tempfile
import binascii
-from chroma.cache import verify_or_create_dir, Cache, GeometryNotFoundError
+from chroma.cache import verify_or_create_dir, Cache, GeometryNotFoundError,\
+ BVHNotFoundError
from chroma.geometry import Geometry, Solid
from chroma.make import box
@@ -167,3 +168,77 @@ class TestCacheGeometry(unittest.TestCase):
def tearDown(self):
remove_path(self.cache_dir)
+
+class TestCacheBVH(unittest.TestCase):
+ def setUp(self):
+ self.cache_dir = random_tempdir('chroma_cache_test')
+ self.cache = Cache(self.cache_dir)
+
+ self.a = Geometry()
+ self.a.add_solid(Solid(box(1,1,1)))
+ self.a.add_solid(Solid(box(1,1,1)), displacement=(10,10,10))
+ self.a.flatten()
+
+ self.b = Geometry()
+ self.b.add_solid(Solid(box(2,2,2)))
+ self.b.add_solid(Solid(box(2,2,2)), displacement=(10,10,10))
+ self.b.add_solid(Solid(box(2,2,2)), displacement=(-10,-10,-10))
+ self.b.flatten()
+
+ # c is not in cache
+ self.c = Geometry()
+ self.c.add_solid(Solid(box(2,2,2)))
+ self.c.flatten()
+
+ self.a_hash = self.a.mesh.md5()
+ self.b_hash = self.b.mesh.md5()
+ self.c_hash = self.c.mesh.md5()
+
+ self.cache.save_geometry('a', self.a)
+ self.cache.save_geometry('b', self.b)
+
+ def test_list_bvh(self):
+ self.assertEqual(len(self.cache.list_bvh(self.a_hash)), 0)
+ self.cache.save_bvh([], self.a_hash)
+ self.assertIn('default', self.cache.list_bvh(self.a_hash))
+ self.cache.save_bvh([], self.a_hash, 'foo')
+ self.assertIn('foo', self.cache.list_bvh(self.a_hash))
+ self.assertEqual(len(self.cache.list_bvh(self.a_hash)), 2)
+
+ def test_exist_bvh(self):
+ self.cache.save_bvh([], self.a_hash)
+ assert self.cache.exist_bvh(self.a_hash)
+ self.cache.save_bvh([], self.a_hash, 'foo')
+ assert self.cache.exist_bvh(self.a_hash, 'foo')
+
+ def test_load_bvh_not_found(self):
+ with self.assertRaises(BVHNotFoundError):
+ self.cache.load_bvh(self.c_hash)
+
+ with self.assertRaises(BVHNotFoundError):
+ self.cache.load_bvh(self.a_hash, 'foo')
+
+ def test_save_load_new_bvh(self):
+ self.cache.save_bvh([], self.a_hash)
+ self.cache.load_bvh(self.a_hash)
+ self.cache.save_bvh([], self.a_hash, 'foo')
+ self.cache.load_bvh(self.a_hash, 'foo')
+
+ def test_remove_bvh(self):
+ self.cache.remove_bvh(self.a_hash, 'does_not_exist')
+
+ self.cache.save_bvh([], self.a_hash)
+ self.cache.save_bvh([], self.a_hash, 'foo')
+ assert self.cache.exist_bvh(self.a_hash)
+ assert self.cache.exist_bvh(self.a_hash, 'foo')
+
+ self.cache.remove_bvh(self.a_hash)
+ assert not self.cache.exist_bvh(self.a_hash)
+ assert self.cache.exist_bvh(self.a_hash, 'foo')
+
+ self.cache.remove_bvh(self.a_hash, 'foo')
+ assert not self.cache.exist_bvh(self.a_hash)
+ assert not self.cache.exist_bvh(self.a_hash, 'foo')
+
+ def tearDown(self):
+ remove_path(self.cache_dir)