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

Skip to content

Commit 9ee0e75

Browse files
committed
Update documentation and tests
1 parent a5481ac commit 9ee0e75

6 files changed

Lines changed: 211 additions & 18 deletions

File tree

docs/userguide/expectations.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,15 +1096,85 @@ SUCCESS
10961096
10971097
## to_be_within of
10981098
1099-
This fuzzy matcher is designed to allow user to compare a numbers and dates within distance of error.
1099+
This matcher is created to determine wheter expected value is approximately equal or "close" to another value.
11001100
1101-
We are allowing a numbers to be compared within a absolute distance from other number of within a percentage calculated based on expected value.
1101+
Matcher will allow to compare numbers as well as dates.
11021102
1103-
When comparing a date a distance is measured in interval.
1103+
When comparing a number the tolerance / distance can be expressed as another postive number or a percentage.
11041104
1105+
When comparing a two dates tolerance can be expressed in interval time either Day-To-Second or Year-To-Month.
11051106
1107+
Matcher for numbers will calculate a absolute distance between expected and actual and check whether that value is within a tolerance.
11061108
1109+
When comparing a date a distance is measured in interval, the check is done that actual value is within date range of expected taking into account interval plus and minus.
11071110
1111+
**Example 1.**
1112+
```sql
1113+
begin
1114+
ut.expect(3).to_be_within(1).of_(4);
1115+
end;
1116+
/
1117+
```
1118+
1119+
**Example 2.**
1120+
```sql
1121+
begin
1122+
ut.expect(9).to_be_within_pct(10).of_(10);
1123+
end;
1124+
/
1125+
```
1126+
1127+
**Example 3.**
1128+
```sql
1129+
begin
1130+
ut.expect(sysdate).to_be_within_pct(interval '1' day).of_(sysdate + 1);
1131+
end;
1132+
/
1133+
```
1134+
1135+
**Example 4.**
1136+
```sql
1137+
begin
1138+
ut.expect(sysdate).to_be_within_pct(interval '1' month).of_(add_months(sysdate,1));
1139+
end;
1140+
/
1141+
```
1142+
1143+
**Example 5.**
1144+
```sql
1145+
begin
1146+
ut.expect(3).to_be_within(1).of_(5);
1147+
end;
1148+
/
1149+
```
1150+
1151+
Returns following output via DBMS_OUTPUT:
1152+
```
1153+
Failures:
1154+
1155+
1) wihtin_test
1156+
Actual: 3 (number) was expected to be within 1 of 5 (number)
1157+
at "UT3_DEVELOP.UT_BE_WITHIN.OF_", line 48 l_result.expectation.to_(l_result );
1158+
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
1159+
```
1160+
1161+
**Example 6.**
1162+
```sql
1163+
begin
1164+
ut.expect(sysdate).to_be_within(interval '1' day).of_(sysdate+2);
1165+
end;
1166+
/
1167+
```
1168+
1169+
Returns following output via DBMS_OUTPUT:
1170+
```
1171+
Failures:
1172+
1173+
1) wihtin_test
1174+
Actual: 2020-06-07T13:32:58 (date) was expected to be within 1 day of 2020-06-09T13:32:58 (date)
1175+
at "UT3_DEVELOP.UT_BE_WITHIN.OF_", line 55 l_result.expectation.to_(l_result );
1176+
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
1177+
```
11081178
11091179
## Comparing cursors, object types, nested tables and varrays
11101180

source/core/ut_utils.pkb

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,10 +884,29 @@ create or replace package body ut_utils is
884884
l_second varchar2(100) := extract(second from a_interval);
885885
l_result varchar2(32767);
886886
begin
887-
l_result := case when l_day > 0 then l_day ||' day' else null end;
888-
l_result := l_result || case when l_hour > 0 then ' '|| l_hour ||' hour' else null end;
889-
l_result := l_result || case when l_minute> 0 then ' '||l_minute ||' minute' else null end;
890-
l_result := l_result || case when l_second > 0 then ' '||l_second ||' second' else null end;
887+
l_result := case
888+
when l_day = 1 then l_day ||' day'
889+
when l_day > 1 then l_day ||' days'
890+
else null
891+
end;
892+
l_result := l_result ||
893+
case
894+
when l_hour = 1 then ' '|| l_hour ||' hour'
895+
when l_hour > 1 then ' '|| l_hour ||' hours'
896+
else null
897+
end;
898+
l_result := l_result ||
899+
case
900+
when l_minute = 1 then ' '||l_minute ||' minute'
901+
when l_minute > 1 then ' '||l_minute ||' minutes'
902+
else null
903+
end;
904+
l_result := l_result ||
905+
case
906+
when l_second = 1 then ' '||l_second ||' second'
907+
when l_second > 1 then ' '||l_second ||' seconds'
908+
else null
909+
end;
891910
return trim(leading ' ' from l_result);
892911
end;
893912

@@ -896,8 +915,17 @@ create or replace package body ut_utils is
896915
l_month varchar2(20) := extract(month from a_interval);
897916
l_result varchar2(32767);
898917
begin
899-
l_result := case when l_year > 0 then l_year ||' year' else null end;
900-
l_result := l_result || case when l_month > 0 then ' '||l_month ||' month' else null end;
918+
l_result := case
919+
when l_year = 1 then l_year ||' year'
920+
when l_year > 1 then l_year ||' years'
921+
else null
922+
end;
923+
l_result := l_result ||
924+
case
925+
when l_month = 1 then ' '||l_month ||' month'
926+
when l_month > 1 then ' '||l_month ||' months'
927+
else null
928+
end;
901929
return trim(leading ' ' from l_result);
902930
end;
903931

source/expectations/matchers/ut_be_within.tpb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,25 @@ create or replace type body ut_be_within as
6060
begin
6161
if self.expected.data_type = a_actual.data_type then
6262
if self.expected is of (ut_data_value_number) and self.is_pct = 0 then
63-
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;
63+
l_result := abs((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value)) <=
64+
treat(self.dist as ut_data_value_number).data_value;
6465
elsif self.expected is of (ut_data_value_number) and self.is_pct = 1 then
65-
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 ) /
66-
(treat(self.expected as ut_data_value_number).data_value) ;
66+
l_result := treat(self.dist 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)) ;
6770
elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_yminterval) then
68-
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
69-
and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_yminterval).data_value;
71+
l_result := treat(a_actual as ut_data_value_date).data_value
72+
between
73+
(treat(self.expected as ut_data_value_date).data_value) - treat(self.dist as ut_data_value_yminterval).data_value
74+
and
75+
(treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_yminterval).data_value;
7076
elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_dsinterval) then
71-
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
72-
and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_dsinterval).data_value;
77+
l_result := treat(a_actual as ut_data_value_date).data_value
78+
between
79+
(treat(self.expected as ut_data_value_date).data_value) - treat(self.dist as ut_data_value_dsinterval).data_value
80+
and
81+
(treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_dsinterval).data_value;
7382
end if;
7483
else
7584
l_result := (self as ut_matcher).run_matcher(a_actual);

test/ut3_tester/core/test_ut_utils.pkb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,5 +432,62 @@ end;
432432
--Assert
433433
ut.expect(l_actual).to_equal(l_expected);
434434
end;
435+
436+
procedure int_conv_ds_sec is
437+
l_expected varchar2(100) := '1 second';
438+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' second);
439+
begin
440+
ut.expect(l_expected).to_equal(l_actual);
441+
end;
442+
443+
procedure int_conv_ds_minute is
444+
l_expected varchar2(100) := '1 minute';
445+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' minute);
446+
begin
447+
ut.expect(l_expected).to_equal(l_actual);
448+
end;
449+
450+
procedure int_conv_ds_hour is
451+
l_expected varchar2(100) := '1 hour';
452+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' hour);
453+
begin
454+
ut.expect(l_expected).to_equal(l_actual);
455+
end;
456+
457+
procedure int_conv_ds_day is
458+
l_expected varchar2(100) := '1 day';
459+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' day);
460+
begin
461+
ut.expect(l_expected).to_equal(l_actual);
462+
end;
463+
464+
procedure int_conv_ds_date is
465+
l_expected varchar2(100) := '2 days 3 hours 4 minutes 11.333 seconds';
466+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(INTERVAL '2 3:04:11.333' DAY TO SECOND);
467+
begin
468+
ut.expect(l_expected).to_equal(l_actual);
469+
end;
470+
471+
procedure int_conv_ym_year is
472+
l_expected varchar2(100) := '1 year';
473+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' year);
474+
begin
475+
ut.expect(l_expected).to_equal(l_actual);
476+
end;
477+
478+
procedure int_conv_ym_month is
479+
l_expected varchar2(100) := '1 month';
480+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' month);
481+
begin
482+
ut.expect(l_expected).to_equal(l_actual);
483+
end;
484+
485+
procedure int_conv_ym_date is
486+
l_expected varchar2(100) := '1 year 2 months';
487+
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(INTERVAL '1-2' YEAR TO MONTH);
488+
begin
489+
ut.expect(l_expected).to_equal(l_actual);
490+
end;
491+
435492
end test_ut_utils;
436493
/

test/ut3_tester/core/test_ut_utils.pks

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,34 @@ create or replace package test_ut_utils is
128128
--%test(replace_multiline_comments - replaces multi-line comments with empty lines)
129129
procedure replace_multiline_comments;
130130

131+
--%context(interval_converter_to_strin)
132+
133+
--%test(Test day to second interval passing a second)
134+
procedure int_conv_ds_sec;
135+
136+
--%test(Test day to second interval passing a minute)
137+
procedure int_conv_ds_minute;
138+
139+
--%test(Test day to second interval passing a hour)
140+
procedure int_conv_ds_hour;
141+
142+
--%test(Test day to second interval passing a day)
143+
procedure int_conv_ds_day;
144+
145+
--%test(Test day to second interval passing a custom date )
146+
procedure int_conv_ds_date;
147+
148+
--%test(Test year to month interval passing a hour)
149+
procedure int_conv_ym_year;
150+
151+
--%test(Test year to month interval passing a day)
152+
procedure int_conv_ym_month;
153+
154+
--%test(Test year to month interval passing a custom date )
155+
procedure int_conv_ym_date;
156+
157+
158+
--%endcontext
159+
131160
end test_ut_utils;
132161
/

test/ut3_user/expectations/binary/test_to_be_within.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ create or replace package body test_to_be_within is
103103
--Act
104104
ut3_develop.ut.expect(sysdate).to_be_within(INTERVAL '2 3:04:11.333' DAY TO SECOND).of_(sysdate+100);
105105
--Assert
106-
l_expected_message := q'[Actual: % (date) was expected to be within 2 day 3 hour 4 minute 11.333 second of % (date)]';
106+
l_expected_message := q'[Actual: % (date) was expected to be within 2 days 3 hours 4 minutes 11.333 seconds of % (date)]';
107107
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
108108
--Assert
109109
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -131,7 +131,7 @@ create or replace package body test_to_be_within is
131131
--Act
132132
ut3_develop.ut.expect(sysdate).to_be_within(INTERVAL '1-3' YEAR TO MONTH).of_(sysdate+720);
133133
--Assert
134-
l_expected_message := q'[Actual: % (date) was expected to be within 1 year 3 month % (date)]';
134+
l_expected_message := q'[Actual: % (date) was expected to be within 1 year 3 months % (date)]';
135135
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
136136
--Assert
137137
ut.expect(l_actual_message).to_be_like(l_expected_message);

0 commit comments

Comments
 (0)