-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
[feature] an assertion that compares numbers within a delta #92
Comments
Hello @masukomi and happy new year. Also, sorry for the delay. Thank you for using bash_unit and for this nicely shaped proposal. Adding an assertion function in bash_unit itself is a tough one as we will have to maintain it forever then. But why not, your remark makes sense, it's quite close to asserting against regexp. I've implemented your proposed I guess we can keep in mind |
yay 🎉 :D
correct. i'm doing time related tests so it'd always be in the same direction. I think the positive and negative are "nice-to-haves" rather than truly necessary for most folks. |
Use case:
I'm testing a timestamp that's been inserted in the db, but don't have a good way to "freeze time". So, I need to insert the record, get the current epoch time (presumably from
date
) then compare the two, but the second may have changed between the creation and the acquisition of the new date.So, i want the ability to assert within a delta.
There are, one presumes, many cases where you know a good approximation of a correct value but not the exact value. Just like the need for regexp when you don't know the exact string that will come back, but do know its form.
Proposal
assert_within_delta <expected num> <actual num> <max delta>
Given an expectation of 5 and a delta of 2 this would match 3, 4, 5, 6, and 7
There should probably be a
positive
andnegative
variant.assert_within_positive_delta <expected_num> <actual_num> <max_delta>
Given an expectation of 5 and a delta of 2 this would match 5, 6, and 7.
assert_within_negative_delta <expected_num> <actual_num> <max_delta>
Given an expectation of 5 and a delta of 2 this would match 3, 4, and 5.
The text was updated successfully, but these errors were encountered: