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

Support for tests on floating point numbers. #15

Open
smblott-github opened this issue Nov 14, 2012 · 1 comment
Open

Support for tests on floating point numbers. #15

smblott-github opened this issue Nov 14, 2012 · 1 comment

Comments

@smblott-github
Copy link

With floating point calculations, the actual result is hardware dependent. Two algebraically equivalent calculations may yield slightly different values.

Suggestion: add explicit support for testing such values.

Support might look something like:

assert.withinEpsillon 0.001, oldWordRelevancy(...), newWordRelevancy(...) * 2
assert.withinFactor 0.001, oldWordRelevancy(...), newWordRelevancy(...) * 2

In the first case, we're looking for an absolute difference less than the given constant. In the second case, we're looking for the ratio of the difference to the absolute value (of the second argument, say) to be less than the given constant.

This came up for me while working on word relevancy in vimium. Amazingly, my floating point tests using isEqual work. But I'd be more comfortable working with test which are more likely to succeed on a variety of hardware platforms.

You might argue that such tests don't make sense for floating point calculations: they're always hardware dependent. And you'd have a point.

Or you might argue that such tests can always be constructed using the existing isTrue. And you'd be right there, too. However, all tests can be constructed in terms of isTrue. But explicit support from shoulda makes such tests easier to write and easier to read.

@smblott-github
Copy link
Author

If you buy the suggestion above, it would be natural to also have notWithinEpsillon and notWithinFactor.

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