Skip to content

Commit 8787dea

Browse files
kshitij-mathsndem0
authored andcommitted
test: add unittests for clough tocher interpolator
1 parent aa0b9e6 commit 8787dea

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_clough_tocher.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import numpy as np
2+
import pytest
3+
4+
from ezyrb import CloughTocher
5+
6+
np.random.seed(17)
7+
8+
def get_xy():
9+
npts = 20
10+
dinput = 2
11+
12+
inp = np.random.uniform(-1, 1, size=(npts, dinput))
13+
out = np.array([
14+
np.sin(inp[:, 0]) + np.sin(inp[:, 1]**2),
15+
np.cos(inp[:, 0]) + np.cos(inp[:, 1]**2)
16+
]).T
17+
18+
return inp, out
19+
20+
class TestCloughTocher:
21+
def test_constructor_empty(self):
22+
model = CloughTocher()
23+
24+
def test_fit(self):
25+
x, y = get_xy()
26+
approx = CloughTocher()
27+
approx.fit(x, y)
28+
29+
def test_predict_01(self):
30+
x, y = get_xy()
31+
approx = CloughTocher()
32+
approx.fit(x, y)
33+
test_y = approx.predict(x)
34+
np.testing.assert_array_almost_equal(y, test_y, decimal=6)
35+
36+
def test_wrong_dimensions(self):
37+
x = np.random.uniform(-1, 1, size=(10, 3))
38+
y = np.random.uniform(-1, 1, size=(10, 2))
39+
approx = CloughTocher()
40+
with pytest.raises(ValueError):
41+
approx.fit(x, y)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
import ezyrb
4+
from ezyrb.parallel import ReducedOrderModel as ParallelROM
5+
ezyrb.ReducedOrderModel = ParallelROM
6+
7+
from tests.test_clough_tocher import *

0 commit comments

Comments
 (0)