2010-04-29 22:29:35 -07:00
|
|
|
#!/usr/bin/env python
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
import unittest
|
2011-02-02 09:56:20 -08:00
|
|
|
from interp.baker import get_phis, qlinear
|
2010-10-29 20:34:15 -07:00
|
|
|
from interp.grid import grid
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
import scipy.spatial
|
|
|
|
|
2011-02-15 10:27:45 -08:00
|
|
|
class Test(unittest.TestCase):
|
2010-03-18 22:32:24 -07:00
|
|
|
def setUp(self):
|
|
|
|
self.X = [0.0, 0.0, 0.0]
|
|
|
|
self.r = [
|
|
|
|
[0.0, 0.0, 1.0],
|
|
|
|
[0.94280904333606508, 0.0, -0.3333333283722672],
|
|
|
|
[-0.47140452166803232, 0.81649658244673617, -0.3333333283722672],
|
|
|
|
[-0.47140452166803298, -0.81649658244673584, -0.3333333283722672],
|
|
|
|
]
|
|
|
|
self.q = [0.0, 0.0, 0.0, 4]
|
|
|
|
|
|
|
|
|
2011-02-02 09:56:20 -08:00
|
|
|
def testGetPhis(self):
|
|
|
|
result = get_phis(self.X, self.r)
|
2010-03-20 19:09:46 -07:00
|
|
|
right_answer = [0.25, 0.25, 0.25, 0.25]
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
for a,b in zip(result, right_answer):
|
|
|
|
self.assertAlmostEqual(a,b)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
|
2011-02-02 09:56:20 -08:00
|
|
|
def testQlinear(self):
|
|
|
|
phi, result = qlinear(self.X, grid(self.r, self.q))
|
2010-03-20 19:09:46 -07:00
|
|
|
result = result
|
|
|
|
right_answer = 1.0
|
|
|
|
self.assertAlmostEqual(result, right_answer)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-02-15 10:27:45 -08:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
|
2010-03-18 22:32:24 -07:00
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|