smbinterp/test/2dcubic.py
Stephen Mardson McQuay 6bfaa20d40 renamed test files
--HG--
rename : test/cubic.test.py => test/2dcubic.py
rename : test/quad.test.py => test/2dquadratic.py
rename : test/baker.test.py => test/baker2d.py
rename : test/baker.order.test.py => test/baker2dorder.py
rename : test/baker3D.test.py => test/baker3d.py
rename : test/qhull.test.py => test/qhull.py
2011-02-03 09:38:44 -07:00

77 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python
import unittest
import math
from interp.baker import run_baker
from interp.grid.DD import grid
from interp.grid.simplex import contains
def exact_func(X):
x = X[0]
y = X[0]
return 1 + x + y
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.verts = [
[ 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.verts]
self.X = [0.55, 0.45]
self.g = grid(self.verts, self.q)
self.g.construct_connectivity()
self.R = self.g.create_mesh(range(3))
self.exact = exact_func(self.X)
def test_R_contains_X(self):
self.assertTrue(contains(self.X, self.R.verts))
def test_RunBaker_1_extra_point(self, extra=1):
S = self.g.create_mesh(range(3, 3 + extra))
answer = run_baker(self.X, self.R, S, order=3)
lin_err = abs(self.exact - answer['qlin'])
final_err = abs(self.exact - answer['final'])
self.assertTrue(lin_err >= final_err)
def test_RunBaker_2_extra_point(self, extra=2):
S = self.g.create_mesh(range(3, 3 + extra))
answer = run_baker(self.X, self.R, S, order=3)
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.create_mesh(range(3, 3 + extra))
answer = run_baker(self.X, self.R, S, order=3)
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.create_mesh(range(3, 3 + extra))
answer = run_baker(self.X, self.R, S, order=3)
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.create_mesh(range(3, 3 + extra))
answer = run_baker(self.X, self.R, S, order=3)
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(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=3).run(suite)