Permalink
Browse files

delaunay: test for 1d and 0d grids (fails upstream) re: issue #997

  • Loading branch information...
1 parent 5b90a27 commit 49215c26fa0780afadba900c50c2e4022d778997 Amit Aronovitch committed Nov 10, 2012
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -159,7 +159,7 @@ def interpolator(self, func):
z = func(self.x, self.y)
return self.tri.nn_extrapolator(z, bbox=self.xrange+self.yrange)
-def make_all_testfuncs(allfuncs=allfuncs):
+def make_all_2d_testfuncs(allfuncs=allfuncs):
def make_test(func):
filenames = [
'%s-%s' % (func.func_name, x) for x in
@@ -186,4 +186,27 @@ def reference_test():
for func in allfuncs:
globals()['test_%s' % func.func_name] = make_test(func)
-make_all_testfuncs()
+make_all_2d_testfuncs()
+
+# 1d and 0d grid tests
+
+ref_interpolator = Triangulation([0,10,10,0],
+ [0,0,10,10]).linear_interpolator([1,10,5,2.0])
+
+def equal_arrays(a1,a2, tolerance=1e-10):
+ return np.all(np.absolute(a1 - a2) < tolerance)
+
+def test_1d_grid():
+ res = ref_interpolator[3:6:2j,1:1:1j]
+ assert equal_arrays(res, [[1.6],[1.9]])
+
+def test_0d_grid():
+ res = ref_interpolator[3:3:1j,1:1:1j]
+ assert equal_arrays(res, [[1.6]])
+
+@image_comparison(baseline_images=['delaunay-1d-interp'], extensions=['png'])
+def test_1d_plots():
+ x_range = slice(0.25,9.75,20j)
+ x = np.mgrid[x_range]
+ for y in xrange(2,10,2):
+ plt.plot(x, ref_interpolator[x_range,y:y:1j])

0 comments on commit 49215c2

Please sign in to comment.