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

Property based testing #17

Open
1 task
mgalloy opened this issue May 2, 2022 · 0 comments
Open
1 task

Property based testing #17

mgalloy opened this issue May 2, 2022 · 0 comments
Assignees

Comments

@mgalloy
Copy link
Owner

mgalloy commented May 2, 2022

Adding the ability to do property based testing to mgunit would help find more bugs.

To do property based tests, you would write methods that take parameters and don't start with "test." Then the actual test methods would call a routine, mgunit_proptest, that calls the test method with the given keywords.

For example, to test the routine mg_n_smallest:

function mg_n_smallest_ut::check_size, array=array, n=n
  compile_opt strictarr

  result = mg_n_smallest(arr, n)
  assert, n_elements(result) eq n
  return, 1
end

function mg_n_smallest_ut::test_size
  compile_opt strictarr

  mgunit_proptest, self, 'check_size', $
                   array=mgunit_array(mgunit_float()), $
                   n=mgunit_long(min_value=0)

  return, 1
end

pro mg_n_smallest_ut__define
  compile_opt strictarr

  define = { mg_n_smallest_ut, inherits MGutLibTestCase }
end

Other features:

  • mgunit should write an explicit unit test when a property based test fails.
@mgalloy mgalloy self-assigned this May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant