Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
48abf1a
Initial checkin
lwasylow Jun 1, 2020
7041912
added expectation
lwasylow Jun 2, 2020
13d86b6
Adding more methods
lwasylow Jun 2, 2020
caeeb30
Adding contain and not contain
lwasylow Jun 2, 2020
8ff4f6b
Adding code and tests,.
lwasylow Jun 6, 2020
89cb0bc
Fixingtoo long names
lwasylow Jun 6, 2020
a5481ac
fixing issue
lwasylow Jun 6, 2020
9ee0e75
Update documentation and tests
lwasylow Jun 7, 2020
a660208
First code corrections
lwasylow Jun 14, 2020
ada1ea4
Resolving another comment
lwasylow Jun 14, 2020
fe1b0cb
Updating issues
lwasylow Jun 14, 2020
013db74
Update tble
lwasylow Jun 14, 2020
b5c73b4
Separated into two different matchers
jgebal Jun 19, 2020
2e721da
CHECKPOINT
lwasylow Jun 19, 2020
fbc0f26
Merge branch 'feature/rework_matcher' of https://github.com/utPLSQL/u…
lwasylow Jun 19, 2020
f182430
Update uninstall
lwasylow Jun 19, 2020
e3fb2d7
Update progress
lwasylow Jun 19, 2020
322e0a1
Making code a bit more readable
lwasylow Jun 19, 2020
ff15596
Added tests for `be_within_pct`
jgebal Jun 20, 2020
3cae9a2
Fixed test issue
jgebal Jun 20, 2020
22549db
Fixed stacktrace for failed expectations on chained matchers.
jgebal Jun 21, 2020
1d771a5
Update timestamps
lwasylow Jun 25, 2020
363c333
Fixed and simplified matcher
jgebal Jun 27, 2020
0ea8925
Fixed native dynamic SQL types compatibility for 11g
jgebal Jun 28, 2020
7c01afb
Fixed native dynamic SQL types compatibility for 11g
jgebal Jun 28, 2020
66d92fc
Merge branch 'develop' into feature/rework_matcher
jgebal Jan 28, 2022
590fb38
Improving test stability (flaky tests)
jgebal Jan 28, 2022
5e2642a
Removing reference to ut3_develop schema.
jgebal Jan 28, 2022
ed06e33
Relaxed sql-injection check to work with 11g2
jgebal Jan 28, 2022
38f3cbc
Fixed issues with comparison of dates&timestamps using interval year-…
jgebal Jan 30, 2022
86e84c8
Improving code coverage.
jgebal Jan 31, 2022
718ac0d
Improved test stability.
jgebal Jan 31, 2022
6dbef20
Fixing build process to build using develop branch as testing framewo…
jgebal Jan 31, 2022
25b55b4
Improving test coverage.
jgebal Jan 31, 2022
5b5a5c0
Improving matcher documentation
jgebal Jan 31, 2022
7fec0f9
Added tests for 0 value of actual and expected and actual greater tha…
jgebal Feb 2, 2022
fd7ef9c
Fixed issues with precission of distance. `NATURAL` is a subtype of i…
jgebal Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update progress
  • Loading branch information
lwasylow committed Jun 19, 2020
commit e3fb2d7f15062b91a81570973f56209be8f89cb3
36 changes: 26 additions & 10 deletions docs/userguide/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ The matrix below illustrates the data types supported by different matchers.
| **be_empty** | X | | X | | | | | | | | | X | X | | X |
| **have_count** | | | | | | | | | | | | X | X | | X |
| **be_within().of_()** | | | | x | x | | | | | | | | | | |

| **be_within_pct().of()**| | | | | x | | | | | | | | | | |

# Expecting exceptions

Expand Down Expand Up @@ -1118,14 +1118,6 @@ end;

**Example 2.**
```sql
begin
ut.expect(9).to_be_within_pct(10).of_(10);
end;
/
```

**Example 3.**
```sql
begin
ut.expect(3).to_be_within(1).of_(5);
end;
Expand All @@ -1142,7 +1134,7 @@ Failures:
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
```

**Example 4.**
**Example 3.**
```sql
begin
ut.expect(sysdate).to_be_within(interval '1' day).of_(sysdate+2);
Expand All @@ -1160,6 +1152,30 @@ Failures:
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
```


## to_be_within_pct of

This matcher is created to determine wheter expected value is approximately equal or "close" to another value within percentage value of expected.

Matcher will allow to compare numbers.

When comparing a number the tolerance / distance can be expressed as another postive number or a percentage.

When comparing a two dates tolerance can be expressed in interval time either Day-To-Second or Year-To-Month.

Matcher for numbers will calculate a absolute distance between expected and actual and check whether that value is within a tolerance.

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.

**Example 1.**
```sql
begin
ut.expect(9).to_be_within_pct(10).of_(10);
end;
/
```


## Comparing cursors, object types, nested tables and varrays

utPLSQL is capable of comparing compound data-types including:
Expand Down
20 changes: 4 additions & 16 deletions source/expectations/matchers/ut_be_within.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,14 @@ create or replace type body ut_be_within as
end;

overriding member function failure_message(a_actual ut_data_value) return varchar2 is
l_distance_from_expected varchar2(32767);
begin
l_distance_from_expected := case
when self.distance_from_expected is of (ut_data_value_number) then
treat(self.distance_from_expected as ut_data_value_number).to_string
when self.distance_from_expected is of (ut_data_value_yminterval) then
treat(self.distance_from_expected as ut_data_value_yminterval).to_string
when self.distance_from_expected is of (ut_data_value_dsinterval) then
treat(self.distance_from_expected as ut_data_value_dsinterval).to_string
else
null
end;

return (self as ut_matcher).failure_message(a_actual) || ' '||l_distance_from_expected ||' of '|| expected.to_string_report();
begin
return (self as ut_matcher).failure_message(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
end;

overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is
Comment thread
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();
begin
return (self as ut_matcher).failure_message_when_negated(a_actual) || ' '||self.distance_from_expected.to_string ||' of '|| expected.to_string_report();
end;

end;
Expand Down
18 changes: 9 additions & 9 deletions source/expectations/ut_expectation.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -695,43 +695,43 @@ create or replace type body ut_expectation as
end;

member function to_be_within(a_dist natural) return ut_be_within is
l_result ut_matcher;
l_result ut_be_within;
begin
l_result := ut_be_within(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within);
return l_result;
end;

member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
l_result ut_matcher;
l_result ut_be_within;
begin
l_result := ut_be_within(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within);
return l_result;
end;

member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
l_result ut_matcher;
l_result ut_be_within;
begin
l_result := ut_be_within(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within);
return l_result;
end;

member function to_be_within_pct(a_dist natural) return ut_be_within_pct is
l_result ut_matcher;
l_result ut_be_within_pct;
begin
l_result := ut_be_within_pct(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within_pct);
return l_result;
end;

member function not_to_be_within(a_dist natural) return ut_be_within is
l_result ut_matcher;
begin
l_result := ut_be_within(a_dist).negated();
l_result.expectation := self;
return treat(l_result as ut_be_within);
return treat(l_result as ut_be_within);
end;

member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
Expand Down
15 changes: 15 additions & 0 deletions test/ut3_user/expectations/binary/test_to_be_within.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,20 @@ create or replace package body test_to_be_within is
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure fail_msg_when_not_within is
l_actual_message varchar2(32767);
l_expected_message varchar2(32767);
begin
--Arrange
--Act
ut3_develop.ut.expect(1).to_be_within(3).of_(12);
--Assert
l_expected_message := q'[Actual: 1 (number) was expected to be within 3 of 12 (number)]';
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;


end;
/
15 changes: 9 additions & 6 deletions test/ut3_user/expectations/binary/test_to_be_within.pks
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ create or replace package test_to_be_within is
--%test(gives failure when number is not within distance)
procedure failed_tests;

--%test(Check failure message for number not within)
--%test(check failure message for number not within)
procedure fail_for_number_not_within;
Comment thread
lwasylow marked this conversation as resolved.

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

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

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

--%test(Check failure message for custom ym interval not within)
--%test(check failure message for custom ym interval not within)
procedure fail_for_custom_ym_int;


--%test(check failure message for simple within)
procedure fail_msg_when_not_within;

end;
/