Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_delaunay: avoid numbers in 1d test, use np.allclose
  • Loading branch information
AmitAronovitch committed Nov 13, 2012
commit 9fb8c3cc697268dbb920b77172e377446d760c04
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ def reference_test():
ref_interpolator = Triangulation([0,10,10,0],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using the module level namespace, it might be worth considering constructing a class which has "test_" methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding tests to an existing module, I should try staying close to existing style.
make_all_testfuncs() was there (I just renamed it), and since it used module functions rather than class methods, so did I
( and that would have been my default choice anyways in this case).

[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]])
assert np.allclose(res, [[1.6],[1.9]], rtol=0)

def test_0d_grid():
res = ref_interpolator[3:3:1j,1:1:1j]
assert equal_arrays(res, [[1.6]])
assert np.allclose(res, [[1.6]], rtol=0)

@image_comparison(baseline_images=['delaunay-1d-interp'], extensions=['png'])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably remove the fonts from this plot. (see other examples in test_axes)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same myself, but wanted to get feedback, since these "freetype_version=" arguments seem to appear everywhere. Indeed, test_axes has a couple of tick-less plots. Point taken.

def test_1d_plots():
x_range = slice(0.25,9.75,20j)
x = np.mgrid[x_range]
ax = plt.gca()
for y in xrange(2,10,2):
plt.plot(x, ref_interpolator[x_range,y:y:1j])
ax.set_xticks([])
ax.set_yticks([])