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

Skip to content

Commit e3fb2d7

Browse files
committed
Update progress
1 parent f182430 commit e3fb2d7

5 files changed

Lines changed: 63 additions & 41 deletions

File tree

docs/userguide/expectations.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ The matrix below illustrates the data types supported by different matchers.
334334
| **be_empty** | X | | X | | | | | | | | | X | X | | X |
335335
| **have_count** | | | | | | | | | | | | X | X | | X |
336336
| **be_within().of_()** | | | | x | x | | | | | | | | | | |
337-
337+
| **be_within_pct().of()**| | | | | x | | | | | | | | | | |
338338

339339
# Expecting exceptions
340340

@@ -1118,14 +1118,6 @@ end;
11181118
11191119
**Example 2.**
11201120
```sql
1121-
begin
1122-
ut.expect(9).to_be_within_pct(10).of_(10);
1123-
end;
1124-
/
1125-
```
1126-
1127-
**Example 3.**
1128-
```sql
11291121
begin
11301122
ut.expect(3).to_be_within(1).of_(5);
11311123
end;
@@ -1142,7 +1134,7 @@ Failures:
11421134
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
11431135
```
11441136
1145-
**Example 4.**
1137+
**Example 3.**
11461138
```sql
11471139
begin
11481140
ut.expect(sysdate).to_be_within(interval '1' day).of_(sysdate+2);
@@ -1160,6 +1152,30 @@ Failures:
11601152
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
11611153
```
11621154
1155+
1156+
## to_be_within_pct of
1157+
1158+
This matcher is created to determine wheter expected value is approximately equal or "close" to another value within percentage value of expected.
1159+
1160+
Matcher will allow to compare numbers.
1161+
1162+
When comparing a number the tolerance / distance can be expressed as another postive number or a percentage.
1163+
1164+
When comparing a two dates tolerance can be expressed in interval time either Day-To-Second or Year-To-Month.
1165+
1166+
Matcher for numbers will calculate a absolute distance between expected and actual and check whether that value is within a tolerance.
1167+
1168+
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.
1169+
1170+
**Example 1.**
1171+
```sql
1172+
begin
1173+
ut.expect(9).to_be_within_pct(10).of_(10);
1174+
end;
1175+
/
1176+
```
1177+
1178+
11631179
## Comparing cursors, object types, nested tables and varrays
11641180
11651181
utPLSQL is capable of comparing compound data-types including:

source/expectations/matchers/ut_be_within.tpb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,14 @@ create or replace type body ut_be_within as
103103
end;
104104

105105
overriding member function failure_message(a_actual ut_data_value) return varchar2 is
106-
l_distance_from_expected varchar2(32767);
107-
begin
108-
l_distance_from_expected := case
109-
when self.distance_from_expected is of (ut_data_value_number) then
110-
treat(self.distance_from_expected as ut_data_value_number).to_string
111-
when self.distance_from_expected is of (ut_data_value_yminterval) then
112-
treat(self.distance_from_expected as ut_data_value_yminterval).to_string
113-
when self.distance_from_expected is of (ut_data_value_dsinterval) then
114-
treat(self.distance_from_expected as ut_data_value_dsinterval).to_string
115-
else
116-
null
117-
end;
118-
119-
return (self as ut_matcher).failure_message(a_actual) || ' '||l_distance_from_expected ||' of '|| expected.to_string_report();
106+
begin
107+
return (self as ut_matcher).failure_message(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
120108
end;
121109

122110
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is
123111
l_result varchar2(32767);
124-
begin
125-
return (self as ut_matcher).failure_message_when_negated(a_actual) || ': '|| expected.to_string_report();
112+
begin
113+
return (self as ut_matcher).failure_message_when_negated(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
126114
end;
127115

128116
end;

source/expectations/ut_expectation.tpb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -695,43 +695,43 @@ create or replace type body ut_expectation as
695695
end;
696696

697697
member function to_be_within(a_dist natural) return ut_be_within is
698-
l_result ut_matcher;
698+
l_result ut_be_within;
699699
begin
700700
l_result := ut_be_within(a_dist);
701701
l_result.expectation := self;
702-
return treat(l_result as ut_be_within);
702+
return l_result;
703703
end;
704704

705705
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
706-
l_result ut_matcher;
706+
l_result ut_be_within;
707707
begin
708708
l_result := ut_be_within(a_dist);
709709
l_result.expectation := self;
710-
return treat(l_result as ut_be_within);
710+
return l_result;
711711
end;
712712

713713
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
714-
l_result ut_matcher;
714+
l_result ut_be_within;
715715
begin
716716
l_result := ut_be_within(a_dist);
717717
l_result.expectation := self;
718-
return treat(l_result as ut_be_within);
718+
return l_result;
719719
end;
720720

721721
member function to_be_within_pct(a_dist natural) return ut_be_within_pct is
722-
l_result ut_matcher;
722+
l_result ut_be_within_pct;
723723
begin
724724
l_result := ut_be_within_pct(a_dist);
725725
l_result.expectation := self;
726-
return treat(l_result as ut_be_within_pct);
726+
return l_result;
727727
end;
728728

729729
member function not_to_be_within(a_dist natural) return ut_be_within is
730730
l_result ut_matcher;
731731
begin
732732
l_result := ut_be_within(a_dist).negated();
733733
l_result.expectation := self;
734-
return treat(l_result as ut_be_within);
734+
return treat(l_result as ut_be_within);
735735
end;
736736

737737
member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is

test/ut3_user/expectations/binary/test_to_be_within.pkb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,20 @@ create or replace package body test_to_be_within is
192192
ut.expect(l_actual_message).to_be_like(l_expected_message);
193193
end;
194194

195+
procedure fail_msg_when_not_within is
196+
l_actual_message varchar2(32767);
197+
l_expected_message varchar2(32767);
198+
begin
199+
--Arrange
200+
--Act
201+
ut3_develop.ut.expect(1).to_be_within(3).of_(12);
202+
--Assert
203+
l_expected_message := q'[Actual: 1 (number) was expected to be within 3 of 12 (number)]';
204+
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
205+
--Assert
206+
ut.expect(l_actual_message).to_be_like(l_expected_message);
207+
end;
208+
209+
195210
end;
196211
/

test/ut3_user/expectations/binary/test_to_be_within.pks

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ create or replace package test_to_be_within is
1212
--%test(gives failure when number is not within distance)
1313
procedure failed_tests;
1414

15-
--%test(Check failure message for number not within)
15+
--%test(check failure message for number not within)
1616
procedure fail_for_number_not_within;
1717

18-
--%test(Check failure message for inteval of 1 sec not within)
18+
--%test(check failure message for inteval of 1 sec not within)
1919
procedure fail_for_ds_int_not_within;
2020

21-
--%test(Check failure message for custom ds interval not within)
21+
--%test(check failure message for custom ds interval not within)
2222
procedure fail_for_custom_ds_int;
2323

24-
--%test(Check failure message for inteval of 1 month not within)
24+
--%test(check failure message for inteval of 1 month not within)
2525
procedure fail_for_ym_int_not_within;
2626

27-
--%test(Check failure message for custom ym interval not within)
27+
--%test(check failure message for custom ym interval not within)
2828
procedure fail_for_custom_ym_int;
29-
29+
30+
--%test(check failure message for simple within)
31+
procedure fail_msg_when_not_within;
32+
3033
end;
3134
/

0 commit comments

Comments
 (0)