Skip to content

Commit

Permalink
Interpolate: tests
Browse files Browse the repository at this point in the history
I suspected some code was wrong but was not
  • Loading branch information
markotoplak committed Oct 10, 2023
1 parent 3be514b commit 926b23f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions orangecontrib/spectroscopy/tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
interp1d_wo_unknowns_scipy, InterpolateToDomain, NotAllContinuousException, \
nan_extend_edges_and_interpolate
from orangecontrib.spectroscopy.data import getx
from orangecontrib.spectroscopy.tests.util import spectra_table


class TestInterpolate(unittest.TestCase):
Expand All @@ -25,6 +26,9 @@ def setUpClass(cls):
cls.iris = Orange.data.Table("iris")[:5].copy()
cls.collagen = Orange.data.Table("collagen.csv")[:5]
cls.titanic = Orange.data.Table("titanic")
ys = np.arange(16, dtype=float).reshape(4, 4)
np.fill_diagonal(ys, np.nan)
cls.range16 = spectra_table([0, 1, 2, 3], X=ys)

def test_nofloatname(self):
data = self.iris
Expand Down Expand Up @@ -158,6 +162,23 @@ def test_nan_extend_edges_and_interpolate(self):
np.testing.assert_allclose(interp, res)
np.testing.assert_allclose(unknowns, resu)

def test_nan_extend_edges_and_interpolate_mixed(self):
data = self.range16

xs = getx(data)
ys = data.X
v, n = nan_extend_edges_and_interpolate(xs, ys)
exp = np.arange(16, dtype=float).reshape(4, 4)
exp[0, 0] = 1
exp[3, 3] = 14
np.testing.assert_equal(v, exp)

mix = np.array([0, 2, 1, 3])
xsm = xs[mix]
ysm = ys[:, mix]
v, n = nan_extend_edges_and_interpolate(xsm, ysm)
np.testing.assert_equal(v[:, mix], exp)


class TestInterpolateToDomain(unittest.TestCase):

Expand Down Expand Up @@ -194,6 +215,7 @@ def setUpClass(cls):
super().setUpClass()
cls.iris = temp_dasktable(cls.iris)
cls.collagen = temp_dasktable(cls.collagen)
cls.range16 = temp_dasktable(cls.range16)


@unittest.skipUnless(dask, "installed Orange does not support dask")
Expand Down

0 comments on commit 926b23f

Please sign in to comment.