-
Notifications
You must be signed in to change notification settings - Fork 189
Feature/rework matcher #1076
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/rework matcher #1076
Changes from 1 commit
48abf1a
7041912
13d86b6
caeeb30
8ff4f6b
89cb0bc
a5481ac
9ee0e75
a660208
ada1ea4
fe1b0cb
013db74
b5c73b4
2e721da
fbc0f26
f182430
e3fb2d7
322e0a1
ff15596
3cae9a2
22549db
1d771a5
363c333
0ea8925
7c01afb
66d92fc
590fb38
5e2642a
ed06e33
38f3cbc
86e84c8
718ac0d
6dbef20
25b55b4
5b5a5c0
7fec0f9
fd7ef9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| create or replace type body ut_be_within as | ||
| /* | ||
| utPLSQL - Version 3 | ||
| Copyright 2016 - 2019 utPLSQL Project | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"): | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| member procedure init(self in out nocopy ut_be_within, a_dist ut_data_value, a_is_pct number , a_self_type varchar2 := null) is | ||
| begin | ||
| self.dist := a_dist; | ||
| self.is_pct := nvl(a_is_pct,0); | ||
| self.self_type := nvl( a_self_type, $$plsql_unit ); | ||
| end; | ||
|
|
||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist number, a_is_pct number) return self as result is | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| begin | ||
| init(ut_data_value_number(a_dist),a_is_pct); | ||
| return; | ||
| end; | ||
|
|
||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist dsinterval_unconstrained, a_is_pct number) return self as result is | ||
| begin | ||
| init(ut_data_value_dsinterval(a_dist),a_is_pct); | ||
| return; | ||
| end; | ||
|
|
||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist yminterval_unconstrained, a_is_pct number) return self as result is | ||
| begin | ||
| init(ut_data_value_yminterval(a_dist),a_is_pct); | ||
| return; | ||
| end; | ||
|
|
||
| member procedure of_(self in ut_be_within, a_expected number) is | ||
| l_result ut_be_within := self; | ||
| begin | ||
| l_result.expected := ut_data_value_number(a_expected); | ||
| l_result.expectation.to_(l_result ); | ||
| end; | ||
|
|
||
| member procedure of_(self in ut_be_within, a_expected date) is | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the following datatypes are missing:
We could also add support for ut.expect( interval '2' days ).to_be_within(interval '1' second').of_(interval '2' days);
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if that's right. It's a hit against logic as interval words itself describe the distance and have no meaning without of relative point. Distonace of the distance feel counter intuitive to me.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I use interval as a column to measure duration.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this discussion should be in issue rather than in PR |
||
| l_result ut_be_within := self; | ||
| begin | ||
| l_result.expected := ut_data_value_date(a_expected); | ||
| l_result.expectation.to_(l_result ); | ||
| end; | ||
|
|
||
| overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is | ||
| l_result boolean; | ||
| begin | ||
| if self.expected.data_type = a_actual.data_type then | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| if self.expected is of (ut_data_value_number) and self.is_pct = 0 then | ||
| l_result := abs((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value)) <= treat(self.dist as ut_data_value_number).data_value; | ||
| elsif self.expected is of (ut_data_value_number) and self.is_pct = 1 then | ||
| l_result := treat(self.dist as ut_data_value_number).data_value >= ((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value ) * 100 ) / | ||
| (treat(self.expected as ut_data_value_number).data_value) ; | ||
| elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_yminterval) then | ||
| l_result := treat(a_actual as ut_data_value_date).data_value between (treat(self.expected as ut_data_value_date).data_value) - treat(self.dist as ut_data_value_yminterval).data_value | ||
| and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_yminterval).data_value; | ||
| elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_dsinterval) then | ||
| l_result := treat(a_actual as ut_data_value_date).data_value between (treat(self.expected as ut_data_value_date).data_value) - treat(self.dist as ut_data_value_dsinterval).data_value | ||
| and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_dsinterval).data_value; | ||
| end if; | ||
| else | ||
| l_result := (self as ut_matcher).run_matcher(a_actual); | ||
| end if; | ||
| return l_result; | ||
| end; | ||
|
|
||
| overriding member function failure_message(a_actual ut_data_value) return varchar2 is | ||
| l_distance varchar2(32767); | ||
| begin | ||
| l_distance := case | ||
| when self.dist is of (ut_data_value_number) then | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| treat(self.dist as ut_data_value_number).to_string | ||
| when self.dist is of (ut_data_value_yminterval) then | ||
| treat(self.dist as ut_data_value_yminterval).to_string | ||
| when self.dist is of (ut_data_value_dsinterval) then | ||
| treat(self.dist as ut_data_value_dsinterval).to_string | ||
| else | ||
| null | ||
| end; | ||
|
|
||
| return (self as ut_matcher).failure_message(a_actual) || ' '||l_distance ||' of '|| expected.to_string_report(); | ||
| end; | ||
|
|
||
| overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is | ||
|
lwasylow marked this conversation as resolved.
|
||
| l_result varchar2(32767); | ||
| begin | ||
| return (self as ut_matcher).failure_message_when_negated(a_actual) || ': '|| expected.to_string_report(); | ||
| end; | ||
|
|
||
| end; | ||
| / | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| create or replace type ut_be_within under ut_comparison_matcher( | ||
| /* | ||
| utPLSQL - Version 3 | ||
| Copyright 2016 - 2019 utPLSQL Project | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"): | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * Holds information about mather options | ||
| */ | ||
| dist ut_data_value, | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| is_pct number(1,0), | ||
|
|
||
| member procedure init(self in out nocopy ut_be_within, a_dist ut_data_value, a_is_pct number , a_self_type varchar2 := null), | ||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist number, a_is_pct number) return self as result, | ||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist dsinterval_unconstrained, a_is_pct number) return self as result, | ||
| constructor function ut_be_within(self in out nocopy ut_be_within, a_dist yminterval_unconstrained, a_is_pct number) return self as result, | ||
| member procedure of_(self in ut_be_within, a_expected number), | ||
| member procedure of_(self in ut_be_within, a_expected date), | ||
|
|
||
| overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean, | ||
| overriding member function failure_message(a_actual ut_data_value) return varchar2, | ||
| overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 | ||
| ) | ||
| not final | ||
| / | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| create or replace type body ut_expectation_base as | ||
|
lwasylow marked this conversation as resolved.
|
||
| /* | ||
| utPLSQL - Version 3 | ||
| Copyright 2016 - 2019 utPLSQL Project | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"): | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| member procedure to_(self in ut_expectation_base, a_matcher ut_matcher_base) is | ||
| l_expectation_result boolean; | ||
| l_matcher ut_matcher := treat(a_matcher as ut_matcher); | ||
| l_message varchar2(32767); | ||
| begin | ||
| if l_matcher.is_negated() then | ||
| self.not_to( a_matcher ); | ||
| else | ||
| l_expectation_result := l_matcher.run_matcher( self.actual_data ); | ||
| l_expectation_result := coalesce(l_expectation_result,false); | ||
| l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message( self.actual_data ) ); | ||
| ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) ); | ||
| end if; | ||
| end; | ||
|
|
||
| member procedure not_to(self in ut_expectation_base, a_matcher ut_matcher_base) is | ||
| l_expectation_result boolean; | ||
| l_matcher ut_matcher := treat(a_matcher as ut_matcher); | ||
| l_message varchar2(32767); | ||
| begin | ||
| l_expectation_result := coalesce( l_matcher.run_matcher_negated( self.actual_data ), false ); | ||
|
|
||
| l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message_when_negated( self.actual_data ) ); | ||
| ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) ); | ||
| end; | ||
| end; | ||
| / | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| create or replace type ut_expectation_base force authid current_user as object( | ||
| /* | ||
| utPLSQL - Version 3 | ||
| Copyright 2016 - 2019 utPLSQL Project | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"): | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| actual_data ut_data_value, | ||
| description varchar2(4000 char), | ||
|
|
||
| --base matcher executors | ||
| member procedure to_(self in ut_expectation_base, a_matcher ut_matcher_base), | ||
|
lwasylow marked this conversation as resolved.
|
||
| member procedure not_to(self in ut_expectation_base, a_matcher ut_matcher_base) | ||
| ) not final | ||
| / | ||
|
lwasylow marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.