Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff15596

Browse files
committed
Added tests for be_within_pct
Reorganized code so that `be_within_pct` is only supported for `number` Added tests for non-supported syntax
1 parent 322e0a1 commit ff15596

13 files changed

Lines changed: 280 additions & 54 deletions

source/api/be_within_pct.syn

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

source/core/ut_expectation_processor.pkb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ create or replace package body ut_expectation_processor as
183183
);
184184
end;
185185
begin
186+
-- dbms_output.put_line(a_call_stack);
186187
l_call_stack := cut_header_and_expectations( a_call_stack );
187188
l_call_stack := cut_address_columns( l_call_stack );
188189
l_call_stack := cut_framework_stack( l_call_stack );

source/create_grants.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ 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;
9090
grant execute on &&ut3_owner..ut_be_within to &ut3_user;
91+
grant execute on &&ut3_owner..ut_be_within_pct to &ut3_user;
9192
grant execute on &&ut3_owner..ut_contain to &ut3_user;
9293
grant execute on &&ut3_owner..ut_equal to &ut3_user;
9394
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
@@ -104,6 +104,7 @@ 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;
106106
create &action_type. synonym &ut3_user.be_within for &&ut3_owner..be_within;
107+
create &action_type. synonym &ut3_user.be_within_pct for &&ut3_owner..be_within_pct;
107108
create &action_type. synonym &ut3_user.contain for &&ut3_owner..contain;
108109
create &action_type. synonym &ut3_user.equal for &&ut3_owner..equal;
109110
create &action_type. synonym &ut3_user.have_count for &&ut3_owner..have_count;

source/expectations/matchers/ut_be_within.tpb

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,24 @@ 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) is
20-
begin
21-
self.distance_from_expected := a_distance_from_expected;
22-
self.self_type := $$plsql_unit;
23-
end;
24-
2519
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result is
2620
begin
27-
init(ut_data_value_number(a_distance_from_expected));
21+
self.init(ut_data_value_number(a_distance_from_expected), $$plsql_unit);
2822
return;
2923
end;
3024

3125
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result is
3226
begin
33-
init(ut_data_value_dsinterval(a_distance_from_expected));
27+
self.init(ut_data_value_dsinterval(a_distance_from_expected), $$plsql_unit);
3428
return;
3529
end;
36-
30+
3731
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result is
3832
begin
39-
init(ut_data_value_yminterval(a_distance_from_expected));
33+
self.init(ut_data_value_yminterval(a_distance_from_expected), $$plsql_unit);
4034
return;
4135
end;
4236

43-
member procedure of_(self in ut_be_within, a_expected number) is
44-
l_result ut_be_within := self;
45-
begin
46-
l_result.expected := ut_data_value_number(a_expected);
47-
if l_result.is_negated_flag = 1 then
48-
l_result.expectation.not_to(l_result );
49-
else
50-
l_result.expectation.to_(l_result );
51-
end if;
52-
end;
53-
5437
member procedure of_(self in ut_be_within, a_expected date) is
5538
l_result ut_be_within := self;
5639
begin
@@ -62,13 +45,6 @@ create or replace type body ut_be_within as
6245
end if;
6346
end;
6447

65-
member function of_(self in ut_be_within, a_expected number) return ut_be_within is
66-
l_result ut_be_within := self;
67-
begin
68-
l_result.expected := ut_data_value_number(a_expected);
69-
return l_result;
70-
end;
71-
7248
member function of_(self in ut_be_within, a_expected date) return ut_be_within is
7349
l_result ut_be_within := self;
7450
begin
@@ -96,7 +72,7 @@ create or replace type body ut_be_within as
9672
then treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
9773
end;
9874
begin
99-
return case when l_distance_ym is not null
75+
return case when l_distance_ym is not null
10076
then l_actual between l_expected - l_distance_ym and l_expected + l_distance_ym
10177
else l_actual between l_expected - l_distance_ds and l_expected + l_distance_ds
10278
end;
@@ -116,15 +92,14 @@ create or replace type body ut_be_within as
11692
end;
11793

11894
overriding member function failure_message(a_actual ut_data_value) return varchar2 is
119-
begin
95+
begin
12096
return (self as ut_matcher).failure_message(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
12197
end;
12298

12399
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is
124-
l_result varchar2(32767);
125-
begin
100+
begin
126101
return (self as ut_matcher).failure_message_when_negated(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
127-
end;
128-
102+
end;
103+
129104
end;
130105
/

source/expectations/matchers/ut_be_within.tps

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_within under ut_comparison_matcher(
1+
create or replace type ut_be_within under ut_be_within_pct(
22
/*
33
utPLSQL - Version 3
44
Copyright 2016 - 2019 utPLSQL Project
@@ -17,19 +17,11 @@ create or replace type ut_be_within under ut_comparison_matcher(
1717
*/
1818

1919

20-
/**
21-
* Holds information about mather options
22-
*/
23-
distance_from_expected ut_data_value,
24-
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value),
2520
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result,
2621
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result,
2722
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result,
28-
member procedure of_(self in ut_be_within, a_expected number),
2923
member procedure of_(self in ut_be_within, a_expected date),
30-
member function of_(self in ut_be_within, a_expected number) return ut_be_within,
3124
member function of_(self in ut_be_within, a_expected date) return ut_be_within,
32-
3325
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean,
3426
overriding member function failure_message(a_actual ut_data_value) return varchar2,
3527
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2

source/expectations/matchers/ut_be_within_pct.tpb

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

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
19+
constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_pct_of_expected number) return self as result is
2020
begin
21-
self.init(ut_data_value_number(a_distance_from_expected));
21+
self.init(ut_data_value_number(a_pct_of_expected), $$plsql_unit);
2222
return;
2323
end;
2424

25+
member procedure init(self in out nocopy ut_be_within_pct, a_distance_from_expected ut_data_value, self_type varchar2) is
26+
begin
27+
self.distance_from_expected := a_distance_from_expected;
28+
self.self_type := self_type;
29+
end;
30+
31+
member procedure of_(self in ut_be_within_pct, a_expected number) is
32+
l_result ut_be_within_pct := self;
33+
begin
34+
l_result.expected := ut_data_value_number(a_expected);
35+
if l_result.is_negated_flag = 1 then
36+
l_result.expectation.not_to(l_result );
37+
else
38+
l_result.expectation.to_(l_result );
39+
end if;
40+
end;
41+
42+
member function of_(self in ut_be_within_pct, a_expected number) return ut_be_within_pct is
43+
l_result ut_be_within_pct := self;
44+
begin
45+
l_result.expected := ut_data_value_number(a_expected);
46+
return l_result;
47+
end;
48+
2549
overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean is
2650
l_result boolean;
2751
begin
2852
if self.expected.data_type = a_actual.data_type then
2953
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)) ;
54+
l_result :=
55+
treat(self.distance_from_expected as ut_data_value_number).data_value
56+
>= ( ( treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value ) * 100 ) /
57+
treat(self.expected as ut_data_value_number).data_value;
3458
end if;
3559
else
3660
l_result := (self as ut_matcher).run_matcher(a_actual);
3761
end if;
3862
return l_result;
3963
end;
4064

65+
overriding member function failure_message(a_actual ut_data_value) return varchar2 is
66+
begin
67+
return rtrim( (self as ut_matcher).failure_message(a_actual), 'pct' ) || self.distance_from_expected.to_string ||' % of '|| expected.to_string_report();
68+
end;
69+
70+
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is
71+
begin
72+
return rtrim( (self as ut_matcher).failure_message_when_negated(a_actual), 'pct' ) || self.distance_from_expected.to_string ||' % of '|| expected.to_string_report();
73+
end;
74+
4175
end;
4276
/

source/expectations/matchers/ut_be_within_pct.tps

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_within_pct under ut_be_within(
1+
create or replace type ut_be_within_pct under ut_comparison_matcher(
22
/*
33
utPLSQL - Version 3
44
Copyright 2016 - 2019 utPLSQL Project
@@ -17,8 +17,18 @@ create or replace type ut_be_within_pct under ut_be_within(
1717
*/
1818

1919

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
20+
/**
21+
* Holds information about mather options
22+
*/
23+
distance_from_expected ut_data_value,
24+
25+
constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_pct_of_expected number) return self as result,
26+
member procedure init(self in out nocopy ut_be_within_pct, a_distance_from_expected ut_data_value, self_type varchar2),
27+
member procedure of_(self in ut_be_within_pct, a_expected number),
28+
member function of_(self in ut_be_within_pct, a_expected number) return ut_be_within_pct,
29+
overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean,
30+
overriding member function failure_message(a_actual ut_data_value) return varchar2,
31+
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2
2232
)
2333
not final
2434
/

source/install.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
240240
@@install_component.sql 'expectations/ut_expectation_base.tps'
241241
@@install_component.sql 'expectations/matchers/ut_matcher.tps'
242242
@@install_component.sql 'expectations/matchers/ut_comparison_matcher.tps'
243-
@@install_component.sql 'expectations/matchers/ut_be_within.tps'
244243
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tps'
244+
@@install_component.sql 'expectations/matchers/ut_be_within.tps'
245245
@@install_component.sql 'expectations/ut_expectation.tps'
246246
@@install_component.sql 'expectations/matchers/ut_be_false.tps'
247247
@@install_component.sql 'expectations/matchers/ut_be_greater_or_equal.tps'
@@ -297,8 +297,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
297297
@@install_component.sql 'expectations/matchers/ut_be_null.tpb'
298298
@@install_component.sql 'expectations/matchers/ut_be_true.tpb'
299299
@@install_component.sql 'expectations/matchers/ut_equal.tpb'
300-
@@install_component.sql 'expectations/matchers/ut_be_within.tpb'
301300
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tpb'
301+
@@install_component.sql 'expectations/matchers/ut_be_within.tpb'
302302
@@install_component.sql 'expectations/matchers/ut_contain.tpb'
303303
@@install_component.sql 'expectations/matchers/ut_have_count.tpb'
304304
@@install_component.sql 'expectations/matchers/ut_be_between.tpb'
@@ -362,6 +362,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
362362
@@install_component.sql 'api/be_not_null.syn'
363363
@@install_component.sql 'api/be_null.syn'
364364
@@install_component.sql 'api/be_true.syn'
365+
@@install_component.sql 'api/be_within_pct.syn'
365366
@@install_component.sql 'api/be_within.syn'
366367
@@install_component.sql 'api/equal.syn'
367368
@@install_component.sql 'api/have_count.syn'

source/uninstall_objects.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ drop synonym equal;
5656

5757
drop synonym be_within;
5858

59+
drop synonym be_within_pct;
60+
5961
drop type ut_coveralls_reporter force;
6062

6163
drop type ut_coverage_sonar_reporter force;

0 commit comments

Comments
 (0)