2010-04-29 22:29:35 -07:00
|
|
|
#!/usr/bin/env python
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2011-09-17 14:39:01 -07:00
|
|
|
from interp.baker import interpolate
|
2011-09-17 14:38:49 -07:00
|
|
|
from interp.grid import contains
|
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
def exact_func(X):
|
2011-09-17 14:38:49 -07:00
|
|
|
x = X[0]
|
|
|
|
y = X[0]
|
|
|
|
return 1 - x * x + y * y
|
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-02-15 10:27:45 -08:00
|
|
|
class Test(unittest.TestCase):
|
2011-09-17 14:38:49 -07:00
|
|
|
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
|
2010-03-20 16:10:02 -07:00
|
|
|
]
|
2011-09-17 14:38:49 -07:00
|
|
|
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]
|
2011-09-17 14:39:01 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
|
|
|
|
#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]
|
2011-09-17 14:39:01 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
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]
|
2011-09-17 14:39:01 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
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]
|
2011-09-17 14:39:01 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
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]
|
2011-09-17 14:39:01 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
self.assertTrue(lin_err >= final_err)
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-09-17 14:38:49 -07:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
|
|
|
|
unittest.TextTestRunner(verbosity=3).run(suite)
|