working on adding 3D baker. also starting to massage together a good baker method test (2D), and added a stub file for 3D testing
parent
961b3b7b26
commit
f4b2c95cf5
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import unittest
|
||||
import baker
|
||||
|
||||
import numpy as np
|
||||
import scipy.spatial
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.l = [[-1, 1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
|
||||
self.r = [[1,2,3], [2,2,3], [1,3,3], [1,2,9]]
|
||||
self.approx_fmt = "%0.6f"
|
||||
|
||||
def testGetPhis(self):
|
||||
|
||||
X = [0,0]
|
||||
r = [[-1, -1], [0, 2], [1, -1]]
|
||||
|
||||
result = baker.get_phis(X, r)
|
||||
result = [self.approx_fmt % i for i in result]
|
||||
|
||||
right_answer = [self.approx_fmt % i for i in [1/3.0, 1/3.0, 1/3.0]]
|
||||
|
||||
for a,b in zip(result, right_answer):
|
||||
self.assertEqual(a,b)
|
||||
|
||||
def testGetPhis2(self):
|
||||
|
||||
X = [0.5,0.25]
|
||||
r = [[0, 0], [1, 0], [1, 1]]
|
||||
|
||||
result = baker.get_phis(X, r)
|
||||
|
||||
right_answer = [0.5, 0.25, 0.25]
|
||||
|
||||
for a,b in zip(result, right_answer):
|
||||
self.assertEqual(a,b)
|
||||
|
||||
def testQlinear(self):
|
||||
X = [0.5, 0.25]
|
||||
r = [[0, 0], [1, 0], [1, 1]]
|
||||
q = [1, 0, 0]
|
||||
|
||||
result = baker.qlinear(X, r, q)
|
||||
|
||||
right_answer = 0.5
|
||||
|
||||
self.assertEqual(result, right_answer)
|
||||
|
||||
def testRunBaker(self):
|
||||
X = [0.5, 0.25]
|
||||
|
||||
all_points = [
|
||||
[ 0, 0], # 0
|
||||
[ 1, 0], # 1
|
||||
[ 1, 1], # 2
|
||||
[ 0, 1], # 3
|
||||
[ 1,-1], # 4
|
||||
[ 0,-1], # 5
|
||||
[-1, 1], # 6
|
||||
[-1, 0], # 7
|
||||
[-1,-1], # 8
|
||||
]
|
||||
q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
|
||||
tree = scipy.spatial.KDTree(all_points)
|
||||
baker.run_baker(X,
|
||||
result = 3
|
||||
right_answer = 5
|
||||
|
||||
self.assertEqual(result, right_answer)
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
Loading…
Reference in New Issue