Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fleshing out check_numpy_array #2

Open
machow opened this issue Jun 21, 2017 · 0 comments
Open

fleshing out check_numpy_array #2

machow opened this issue Jun 21, 2017 · 0 comments

Comments

@machow
Copy link
Contributor

machow commented Jun 21, 2017

Copied from @beangoben 's issue raised here: datacamp/pythonwhat#217

(CC @yrdatacamp @hugobowne)

Feature request:

Having a test function catered to 1-D, 2-D numpy arrays, in particular that could check:

  • If defined (already implemented)
  • Have the same datatype (i,g list vs np.array)
  • Have the same shape (i.g (2,3) vs (3,2))
  • Has the same contents, or very close (like numpy's allclose https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.testing.assert_allclose.html), equality is only implemented

Currently if I wanted to do this I have to do the following test:

key = 'y'
# messages
type_msg="__JINJA__: **type** **mismatch**: expected `{{sol_eval}}`, got `{{stu_eval}}`."
type_expr = 'type({:s})'.format(key)
shape_msg="__JINJA__: **shape** **mismatch**: expected `{{sol_eval}}`, got `{{stu_eval}}`."
shape_expr = '{:s}.shape'.format(key)
contents_msg="__JINJA__: **solution** **contents** are different, expected `{{sol_eval}}`, got `{{stu_eval}}`."

Ex().check_object(key)  \
    .has_equal_value(expr_code = type_expr,incorrect_msg=type_msg)  \
    .has_equal_value(expr_code = shape_expr,incorrect_msg=shape_msg) \
    .has_equal_value(incorrect_msg=contents_msg)

Would nice to have a function that could wrap around all these scenarios such as

test_numpyarray(key,type_test=True,type_msg,shape_test=True,shape_msg,content_test='allclose', contents_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant