-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add be_within 'fuzzy' matcher #77
Comments
Similar should be available for dates, timestamps and intevals (once suported) |
Rescheduled to version 3.1 |
What should |
that may not make a whole lot of sense.. i guess you could say 50% would mean +/- 12hours |
I think that for dates, timestamps and intervals we should not think of within in terms of PCT. ut.expect(sysdate).to_( be_within( interval '1' day, to_date( '20170515', 'yyyy-mm-dd' ) ) ); |
I customized my utplsql implementation to be able to compare floats. However, instead of a relative precision, I used an absolute precision, but it sounds like the same idea as I already applied. Would it be an idea to make this absolute / relative distinction in a parameter? |
that could work so instead of that works for date/timestamp/interval comparison better then a_pct also and keeps it somewhat consistent to a date/timpstamp comparitson could be |
actually that does that not work well becuase cannot tell the difference between a_amt and a_pct for number comparision. |
I would keep the
Separate matcher seems more clear to use but both are good solutions. Thinking of code readability when matchers are used: ut.expect(v_actual).to_be_within(0.1, v_expected, 'Y');
ut.expect(v_actual).to_be_within_pct(0.1, v_expected);
--or maybe
ut.expect(v_actual).to_be_within(0.1).percent_of(v_expected);
--and without percent
ut.expect(v_actual).to_be_within(0.1).of(v_expected);
Which syntax do you find best and why you think it's best? |
After looking at the issue second time I think that absolute distance is a better option than pct. |
true and if you really want a pct value you can calculate it on the fly. |
So we can have options as follow:
Now dates one can be a bit of crude to see but I feel this provides an easy to write and udnerstand syntax that ask for absolute distance between two values We can also implement this , would be follow same syntax?
|
After some thought I think this should be an argument of equal. For me it's looking like an equality matcher with a margin of error. E.g. |
Actually having a little read the word |
Can't make a mind up :) I also like an idea of new one called |
How about going with:
|
Sounds good to me. |
Questions should we be supporting intervals as argument of within. |
In my opinion, INTERVAL is a measure of time. I agree that interval can also be used to capture date/timestamp difference. |
The definition of the
I like the
and for the second example
It's a well know The tolerance can be an interval (year to month or day to second) or a number. Tolerance is applicable for datetime, timestamp, number comparisons. In case of datetime/timestamp a number tolerance is interpreted in days. This would be consistent with the datetime arithmetic of the Oracle Database. |
I think there are two aspects here
Seems like you're supportive of the firts but suggest to use alternative syntax to |
Yes.
I favor |
For me a tolerance feel a better being second as for first part of name this can probably be modified there are multiple options like: I think |
One more: |
Why change the first part and not keep the existing variant |
We need to change first part as currently we bene looking on to be within(3).of_(5) where 3 was a distance and 5 was a point from distance was measured. |
@PhilippSalvisberg, apologies I misread your post. For some reason I assumed you reffered to |
@lwasylow no problem.
Actually that's what I like. Standalone
or like this
And it feels right. And also with non-default values for tolerance like this:
I am therefore voting against the introduction of additional keywords. Because I think it unnecessarily bloats the syntax of utPLSQL. We don't have to agree . Do whatever you and @jgebal think is best. |
Keep in mind that utPSLQL suppoers two flavors of syntax for expectations:
So for fuzzy matcher we would need to name it The be in OOP it s used to represent equal identity in sense of "the same object instance" not "the same value" or "identical object". I think that be is too strong for this matcher and actually in PL/SQL it is quite impossible for two variables to point to (represent) the same object instance as assignments in PLSQL are done by deep copy of a variable. We could have used Overloading It will not be possible to apply So we would need to add safety net for invalid syntax like: The Thanks for all the inputs. I'm in favor of the following: begin
ut.expect(interval).to_be_within(interval).of_(interval);
ut.expect(date).to_be_within(interval).of_(interval);
ut.expect(timestamp).to_be_within(interval).of_(timestamp);
ut.expect(timestamp_tz).to_be_within(interval).of_(timestamp_tz);
ut.expect(timestamp_ltz).to_be_within(interval).of_(timestamp_ltz);
ut.expect(number).to_be_within(number).of_(number);
ut.expect(number).to_be_within_pct(number).of_(number);
end; |
Thank you, @jgebal for the detailed answer. You got me with the link to RSpec (and because utPLSQL is based on that) and the explanation regarding the technical issues. So, I support your approach. |
@jgebal 's comments - as always a treasure of knowledge! ❤ |
For numbers we should allow a comparison with a percent_off deviation.
The syntax:
ut.expect( a_actual =>1.23 ).to_( be_within( a_pct => 1, a_expected => 1.23456789 ) )
should give success
ut.expect( a_actual =>1.2 ).to_( be_within( a_pct => 1, a_expected => 1.23456789 ) )
should give success
Calculation logic.
a_actual between (a_expected - ((a_expected * a_pct)/100) ) and (a_expected + ((a_expected * a_pct)/100) )
The text was updated successfully, but these errors were encountered: