Skip to content

Commit b5c73b4

Browse files
committed
Separated into two different matchers
Added synonym and grant for matcher Reworked expectation to work fine with syntax `to_( matcher() )` for to_be_within. TODO - add tests for other matchers with `to_( matcher )` and `not_to( matcher )` syntax
1 parent 013db74 commit b5c73b4

File tree

15 files changed

+220
-88
lines changed

15 files changed

+220
-88
lines changed

source/api/be_within.syn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create synonym be_within for ut_be_within;

source/create_grants.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ grant execute on &&ut3_owner..ut_be_like to &ut3_user;
8787
grant execute on &&ut3_owner..ut_be_not_null to &ut3_user;
8888
grant execute on &&ut3_owner..ut_be_null to &ut3_user;
8989
grant execute on &&ut3_owner..ut_be_true to &ut3_user;
90+
grant execute on &&ut3_owner..ut_be_within to &ut3_user;
9091
grant execute on &&ut3_owner..ut_contain to &ut3_user;
9192
grant execute on &&ut3_owner..ut_equal to &ut3_user;
9293
grant execute on &&ut3_owner..ut_have_count to &ut3_user;

source/create_synonyms.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ create &action_type. synonym &ut3_user.be_like for &&ut3_owner..be_like;
103103
create &action_type. synonym &ut3_user.be_not_null for &&ut3_owner..be_not_null;
104104
create &action_type. synonym &ut3_user.be_null for &&ut3_owner..be_null;
105105
create &action_type. synonym &ut3_user.be_true for &&ut3_owner..be_true;
106+
create &action_type. synonym &ut3_user.be_within for &&ut3_owner..be_within;
106107
create &action_type. synonym &ut3_user.contain for &&ut3_owner..contain;
107108
create &action_type. synonym &ut3_user.equal for &&ut3_owner..equal;
108109
create &action_type. synonym &ut3_user.have_count for &&ut3_owner..have_count;

source/expectations/matchers/ut_be_within.tpb

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,27 @@ create or replace type body ut_be_within as
1616
limitations under the License.
1717
*/
1818

19-
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value, a_is_pct number , a_self_type varchar2 := null) is
19+
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value) is
2020
begin
2121
self.distance_from_expected := a_distance_from_expected;
22-
self.is_pct := nvl(a_is_pct,0);
23-
self.self_type := nvl( a_self_type, $$plsql_unit );
22+
self.self_type := $$plsql_unit;
2423
end;
2524

26-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number, a_is_pct number) return self as result is
25+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result is
2726
begin
28-
init(ut_data_value_number(a_distance_from_expected),a_is_pct);
27+
init(ut_data_value_number(a_distance_from_expected));
2928
return;
3029
end;
3130

32-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained, a_is_pct number) return self as result is
31+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result is
3332
begin
34-
init(ut_data_value_dsinterval(a_distance_from_expected),a_is_pct);
33+
init(ut_data_value_dsinterval(a_distance_from_expected));
3534
return;
3635
end;
3736

38-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained, a_is_pct number) return self as result is
37+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result is
3938
begin
40-
init(ut_data_value_yminterval(a_distance_from_expected),a_is_pct);
39+
init(ut_data_value_yminterval(a_distance_from_expected));
4140
return;
4241
end;
4342

@@ -54,20 +53,29 @@ create or replace type body ut_be_within as
5453
l_result.expected := ut_data_value_date(a_expected);
5554
l_result.expectation.to_(l_result );
5655
end;
57-
56+
57+
member function of_(self in ut_be_within, a_expected number) return ut_be_within is
58+
l_result ut_be_within := self;
59+
begin
60+
l_result.expected := ut_data_value_number(a_expected);
61+
return l_result;
62+
end;
63+
64+
member function of_(self in ut_be_within, a_expected date) return ut_be_within is
65+
l_result ut_be_within := self;
66+
begin
67+
l_result.expected := ut_data_value_date(a_expected);
68+
return l_result;
69+
end;
70+
5871
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is
5972
l_result boolean;
6073
begin
6174
if self.expected.data_type = a_actual.data_type then
62-
if self.expected is of (ut_data_value_number) and self.is_pct = 0 then
75+
if self.expected is of (ut_data_value_number) then
6376
l_result := abs((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value)) <=
6477
treat(self.distance_from_expected as ut_data_value_number).data_value;
65-
elsif self.expected is of (ut_data_value_number) and self.is_pct = 1 then
66-
l_result := treat(self.distance_from_expected as ut_data_value_number).data_value >=
67-
(
68-
((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value ) * 100 ) /
69-
(treat(self.expected as ut_data_value_number).data_value)) ;
70-
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected is of ( ut_data_value_yminterval) then
78+
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected is of ( ut_data_value_yminterval) then
7179
l_result := treat(a_actual as ut_data_value_date).data_value
7280
between
7381
(treat(self.expected as ut_data_value_date).data_value) - treat(self.distance_from_expected as ut_data_value_yminterval).data_value

source/expectations/matchers/ut_be_within.tps

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ create or replace type ut_be_within under ut_comparison_matcher(
2121
* Holds information about mather options
2222
*/
2323
distance_from_expected ut_data_value,
24-
is_pct number(1,0),
25-
26-
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value, a_is_pct number , a_self_type varchar2 := null),
27-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number, a_is_pct number) return self as result,
28-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained, a_is_pct number) return self as result,
29-
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained, a_is_pct number) return self as result,
24+
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value),
25+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result,
26+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result,
27+
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result,
3028
member procedure of_(self in ut_be_within, a_expected number),
3129
member procedure of_(self in ut_be_within, a_expected date),
32-
30+
member function of_(self in ut_be_within, a_expected number) return ut_be_within,
31+
member function of_(self in ut_be_within, a_expected date) return ut_be_within,
32+
3333
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean,
3434
overriding member function failure_message(a_actual ut_data_value) return varchar2,
3535
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
create or replace type body ut_be_within_pct as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2019 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_distance_from_expected number) return self as result is
20+
begin
21+
self.init(ut_data_value_number(a_distance_from_expected));
22+
return;
23+
end;
24+
25+
overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean is
26+
l_result boolean;
27+
begin
28+
if self.expected.data_type = a_actual.data_type then
29+
if self.expected is of (ut_data_value_number) then
30+
l_result := treat(self.distance_from_expected as ut_data_value_number).data_value >=
31+
(
32+
((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value ) * 100 ) /
33+
(treat(self.expected as ut_data_value_number).data_value)) ;
34+
end if;
35+
else
36+
l_result := (self as ut_matcher).run_matcher(a_actual);
37+
end if;
38+
return l_result;
39+
end;
40+
41+
end;
42+
/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
create or replace type ut_be_within_pct under ut_be_within(
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2019 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
20+
constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_distance_from_expected number) return self as result,
21+
overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean
22+
)
23+
not final
24+
/

source/expectations/matchers/ut_matcher.tpb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ create or replace type body ut_matcher as
2020
begin
2121
ut_utils.debug_log('Failure - ut_matcher.run_matcher'||'(a_actual '||a_actual.data_type||')');
2222
self.is_errored := ut_utils.boolean_to_int(true);
23-
-- self.error_message := 'The matcher '''||name()||''' cannot be used';
24-
-- if self.expected is not null then
25-
-- self.error_message := self.error_message ||' for comparison of data type ('||self.expected.data_type||')';
26-
-- end if;
27-
-- self.error_message := self.error_message ||' with data type ('||a_actual.data_type||').';
2823
return null;
2924
end;
3025

source/expectations/ut_expectation.tpb

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,37 +694,69 @@ create or replace type body ut_expectation as
694694
self.not_to( ut_contain(a_expected).negated() );
695695
end;
696696

697-
member function to_be_within(a_dist natural) return ut_be_within is
697+
member function to_be_within(a_dist natural) return ut_be_within is
698698
l_result ut_matcher;
699699
begin
700-
l_result := ut_be_within(a_dist,0);
700+
l_result := ut_be_within(a_dist);
701701
l_result.expectation := self;
702702
return treat(l_result as ut_be_within);
703703
end;
704704

705-
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
705+
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
706706
l_result ut_matcher;
707707
begin
708-
l_result := ut_be_within(a_dist,0);
708+
l_result := ut_be_within(a_dist);
709709
l_result.expectation := self;
710710
return treat(l_result as ut_be_within);
711711
end;
712712

713-
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
713+
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
714714
l_result ut_matcher;
715715
begin
716-
l_result := ut_be_within(a_dist,0);
716+
l_result := ut_be_within(a_dist);
717717
l_result.expectation := self;
718718
return treat(l_result as ut_be_within);
719719
end;
720720

721-
member function to_be_within_pct(a_dist natural) return ut_be_within is
721+
member function to_be_within_pct(a_dist natural) return ut_be_within_pct is
722+
l_result ut_matcher;
723+
begin
724+
l_result := ut_be_within_pct(a_dist);
725+
l_result.expectation := self;
726+
return treat(l_result as ut_be_within_pct);
727+
end;
728+
729+
member function not_to_be_within(a_dist natural) return ut_be_within is
722730
l_result ut_matcher;
723731
begin
724-
l_result := ut_be_within(a_dist,1);
732+
l_result := ut_be_within(a_dist).negated();
725733
l_result.expectation := self;
726734
return treat(l_result as ut_be_within);
727-
end;
728-
735+
end;
736+
737+
member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
738+
l_result ut_matcher;
739+
begin
740+
l_result := ut_be_within(a_dist).negated();
741+
l_result.expectation := self;
742+
return treat(l_result as ut_be_within);
743+
end;
744+
745+
member function not_to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
746+
l_result ut_matcher;
747+
begin
748+
l_result := ut_be_within(a_dist).negated();
749+
l_result.expectation := self;
750+
return treat(l_result as ut_be_within);
751+
end;
752+
753+
member function not_to_be_within_pct(a_dist natural) return ut_be_within_pct is
754+
l_result ut_matcher;
755+
begin
756+
l_result := ut_be_within_pct(a_dist).negated();
757+
l_result.expectation := self;
758+
return treat(l_result as ut_be_within_pct);
759+
end;
760+
729761
end;
730762
/

source/expectations/ut_expectation.tps

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ create or replace type ut_expectation under ut_expectation_base(
167167
member function to_be_within(a_dist natural) return ut_be_within,
168168
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
169169
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
170-
member function to_be_within_pct(a_dist natural) return ut_be_within
170+
member function to_be_within_pct(a_dist natural) return ut_be_within_pct,
171+
member function not_to_be_within(a_dist natural) return ut_be_within,
172+
member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
173+
member function not_to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
174+
member function not_to_be_within_pct(a_dist natural) return ut_be_within_pct
171175
)
172176
not final
173177
/

0 commit comments

Comments
 (0)