1af176a6e0
also did some pep8/pyflakes cleanup
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
|
|
from interp.baker import interpolate
|
|
from interp.grid import contains
|
|
|
|
|
|
def exact_func(X):
|
|
x = X[0]
|
|
y = X[0]
|
|
return 1 - x * x + y * y
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
def setUp(self):
|
|
self.g = [
|
|
[0.25, 0.40], # 0
|
|
[0.60, 0.80], # 1
|
|
[0.65, 0.28], # 2
|
|
[0.28, 0.65], # 3
|
|
[1.00, 0.75], # 4
|
|
[0.30, 0.95], # 5
|
|
[0.80, 0.50], # 6
|
|
[0.35, 0.15], # 7
|
|
]
|
|
self.q = [exact_func(p) for p in self.g]
|
|
|
|
self.X = [0.25, 0.4001]
|
|
self.X = [0.55, 0.45]
|
|
|
|
self.R = self.g[0:3]
|
|
self.R_q = self.q[0:3]
|
|
self.exact = exact_func(self.X)
|
|
|
|
def test_R_contains_X(self):
|
|
self.assertTrue(contains(self.X, self.R))
|
|
|
|
def test_RunBaker_1_extra_point(self, extra=1):
|
|
S = self.g[3: 3 + extra]
|
|
S_q = self.q[3: 3 + extra]
|
|
answer = interpolate(self.X, self.R, self.R_q, S, S_q)
|
|
lin_err = abs(self.exact - answer.qlin)
|
|
final_err = abs(self.exact - answer.final)
|
|
|
|
#XXX: not sure about this one:
|
|
self.assertEqual(lin_err, final_err)
|
|
|
|
def test_RunBaker_2_extra_point(self, extra=2):
|
|
S = self.g[3: 3 + extra]
|
|
S_q = self.q[3: 3 + extra]
|
|
answer = interpolate(self.X, self.R, self.R_q, S, S_q)
|
|
lin_err = abs(self.exact - answer.qlin)
|
|
final_err = abs(self.exact - answer.final)
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_3_extra_point(self, extra=3):
|
|
S = self.g[3: 3 + extra]
|
|
S_q = self.q[3: 3 + extra]
|
|
answer = interpolate(self.X, self.R, self.R_q, S, S_q)
|
|
lin_err = abs(self.exact - answer.qlin)
|
|
final_err = abs(self.exact - answer.final)
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_4_extra_point(self, extra=4):
|
|
S = self.g[3: 3 + extra]
|
|
S_q = self.q[3: 3 + extra]
|
|
answer = interpolate(self.X, self.R, self.R_q, S, S_q)
|
|
lin_err = abs(self.exact - answer.qlin)
|
|
final_err = abs(self.exact - answer.final)
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_5_extra_point(self, extra=5):
|
|
S = self.g[3: 3 + extra]
|
|
S_q = self.q[3: 3 + extra]
|
|
answer = interpolate(self.X, self.R, self.R_q, S, S_q)
|
|
lin_err = abs(self.exact - answer.qlin)
|
|
final_err = abs(self.exact - answer.final)
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
if __name__ == '__main__':
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
|
|
unittest.TextTestRunner(verbosity=3).run(suite)
|