smbinterp/test/baker.test.py
Stephen Mardson McQuay 2db4169bfa major refactoring
--HG--
rename : lib/baker/__init__.py => interp/baker/__init__.py
rename : lib/grid/DD.py => interp/grid/DD.py
rename : lib/grid/DDD.py => interp/grid/DDD.py
rename : lib/grid/__init__.py => interp/grid/__init__.py
rename : lib/grid/qhull.py => interp/grid/qhull.py
rename : lib/grid/simplex.py => interp/grid/simplex.py
rename : lib/grid/smcqdelaunay.py => interp/grid/smcqdelaunay.py
rename : lib/baker/tools.py => interp/tools.py
2010-10-22 16:10:58 -06:00

149 lines
3.9 KiB
Python
Executable File

#!/usr/bin/env python
import unittest
from interplosion import baker
from interplosion import grid
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.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
]
self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
self.X = [0.5, 0.25]
self.accuracy = 8
def testImports(self):
import numpy
import scipy
import grid
import baker
def testGetPhis(self):
X = [0,0]
r = [[-1, -1], [0, 2], [1, -1]]
result = baker.get_phis(X, r)
#result = [round(i, self.accuracy) for i in result]
right_answer = [1/3.0, 1/3.0, 1/3.0]
for a,b in zip(result, right_answer):
self.assertAlmostEqual(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]
phi, result = baker.qlinear(X, grid.grid(r,q))
right_answer = 0.5
self.assertEqual(result, right_answer)
def testRunBaker_1(self):
size_of_simplex = 3
extra_points = 3
R = grid.grid(self.all_points[:size_of_simplex],
self.q[:size_of_simplex])
S = grid.grid(self.all_points[size_of_simplex:size_of_simplex + extra_points],
self.q[size_of_simplex:size_of_simplex + extra_points])
answer = baker.run_baker(self.X, R, S)
a = answer['a']
b = answer['b']
c = answer['c']
self.assertAlmostEqual(a, c)
self.assertAlmostEqual(c, 0.0)
self.assertAlmostEqual(b, 1/3.0)
def testRunBaker_2(self):
size_of_simplex = 3
extra_points = 4
R = grid.grid(self.all_points[:size_of_simplex],
self.q[:size_of_simplex])
S = grid.grid(self.all_points[size_of_simplex:size_of_simplex + extra_points],
self.q[size_of_simplex:size_of_simplex + extra_points])
answer = baker.run_baker(self.X, R, S)
a = answer['a']
b = answer['b']
c = answer['c']
self.assertAlmostEqual(a, c)
self.assertAlmostEqual(c, 2/3.0)
def testRunBaker_3(self):
size_of_simplex = 3
extra_points = 5
R = grid.grid(self.all_points[:size_of_simplex],
self.q[:size_of_simplex])
S = grid.grid(self.all_points[size_of_simplex:size_of_simplex + extra_points],
self.q[size_of_simplex:size_of_simplex + extra_points])
answer = baker.run_baker(self.X, R, S)
a = answer['a']
b = answer['b']
c = answer['c']
self.assertAlmostEqual(a, 13/14.0)
self.assertAlmostEqual(b, 2 / 7.0)
self.assertAlmostEqual(c, 15/14.0)
def testRunBaker_4(self):
size_of_simplex = 3
extra_points = 6
R = grid.grid(self.all_points[:size_of_simplex],
self.q[:size_of_simplex])
S = grid.grid(self.all_points[size_of_simplex:size_of_simplex + extra_points],
self.q[size_of_simplex:size_of_simplex + extra_points])
answer = baker.run_baker(self.X, R, S)
a = answer['a']
b = answer['b']
c = answer['c']
self.assertAlmostEqual(a, 48/53.0)
self.assertAlmostEqual(b, 15/53.0)
self.assertAlmostEqual(c, 54/53.0)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=3).run(suite)