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

feat: impl Add, Sub, Mul, Div for all newtypes. #317

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

alxsimon
Copy link
Contributor

@alxsimon alxsimon commented Sep 19, 2023

Closes #277

($type: ty, $fn_name: ident, $a:expr,$b:expr) => {
#[test]
fn $fn_name() {
let a = $a;
Copy link
Owner

Choose a reason for hiding this comment

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

Overall, this looks great -- thanks!

I have some concerns with the tests

  1. For some of the types, 0.0 is not allowed. For example, Time can be 0 but DemeSize cannot. That case is not covered here.
  2. One way to stress test these operations in more depth is via proptest. We could add that as a dev dependency and then let it test all sorts of edge cases for the input into these ops. The simplest method is to use their macro to do the heavy lifting. The idea would be to let proptest generate two f64. We can then say let t = DemeSize::try_from(a + b). If t.is_ok(), then we also expect DemeSize(a) + b, a + DemeSize(b), etc., to all be Some(...) and to contain the same value.

Copy link
Contributor Author

@alxsimon alxsimon Sep 20, 2023

Choose a reason for hiding this comment

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

Thanks, I'll have a look into proptest when I have time. That sounds like a good solution.

Copy link
Owner

Choose a reason for hiding this comment

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

There are limitations to property testing. Upon a bit of reflection, It may be best now to manually treat edge cases: NaN input (f64::NAN), 0 for DemeSize, etc..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes can have known edge cases in and additionally property testing.

Copy link
Owner

Choose a reason for hiding this comment

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

@alxsimon -- I am happy to merge this and revisit detailed testing later. Overall, these crates could be doing a better job testing the newtypes throughout. I think it'll be more efficient to do a higher level review of the testing and make changes later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to merge this one, good for me to come back to tests later

@molpopgen molpopgen merged commit f710183 into molpopgen:main Sep 26, 2023
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

Successfully merging this pull request may close these issues.

Arithmetic on low-level types
2 participants