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
Added tests for 0 value of actual and expected and actual greater tha…
…n expected (not only smaller).

Updated documentation.
  • Loading branch information
jgebal committed Feb 2, 2022
commit 7fec0f998c59fcd2fac6f4d97f508b53bd6d3d15
43 changes: 25 additions & 18 deletions docs/userguide/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,17 @@ SUCCESS

## to_be_within of

This matcher determines wheter expected value is within range from another value.
Determines wheter expected value is within range (tolerance) from another value.

The logical formual used for calcuating the matcher is:
`abs( expected - actual ) <= distance`
The matcher will succeed if the `expected` and `actual` are not more than `distance` apart from each other.
The logical formual used for calcuating the matcher is:
```
result := ( abs( expected - actual ) <= distance )
```
The actual formula used for calculation is more complex to handle different data-types of expected/actual values as well as differnet types of distance value.
The matcher will fail if the `expected` and `actual` are more than `distance` apart from each other.
The matcher will fail if the dataypes of `expected` and `actual` are not the same.

The matcher works with data-type number, date, timestamp, timestamp with time zone, timestamp with local time zone.
The matcher works with data-types: `number`, `date`, `timestamp`, `timestamp with time zone`, `timestamp with local time zone`
The data-types of compared values must match exactly and if type does not match, the expectation will fail.

| expected/actual<br>data-type | distance data-type |
Expand All @@ -1118,12 +1122,13 @@ The data-types of compared values must match exactly and if type does not match,
| timestamp with local time zone | interval year to month |


The distance can be expressed as a postive number or positive interval.
The distance must be expressed as a non-negative number or non-negative interval.

>Note:
> Interval year-to-moth as a distance is giving sucess if the distance between the given dates/timestamps evaluates to value less or equal of the specified interval
> Keep in mind that a distance of `interval '0-1' year to month` will actuall be successful if the distance isnot greater than a month and a half.
> This is due to how oracle evaluates conversion between timestamp difference converted to `year to month interval`.
> Keep in mind that a checking for distance of `interval '0-1' year to month` will actuall be successful if the distance is less than a month and 15 days.
> This is due to how oracle evaluates conversion between timestamp difference converted to `year to month interval`.
> The behavior is similar to a call to `months_between()` function with results rounded to full monts ie. round(months_between(date, date))

**Example 1.**
```sql
Expand Down Expand Up @@ -1172,17 +1177,14 @@ Failures:

## 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.
Determines wheter actual value is within percentage range of expected value.
The matcher only works with `number` data-type.

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.
The percentage deviation (distance) must be expressed as a non-negative number.
The formula used for calcuation of expectation is:
```
result := ( ( distance ) * expected >= abs( expected - actual ) * 100 )
```

**Example 1.**
```sql
Expand All @@ -1192,6 +1194,11 @@ end;
/
```

```
SUCCESS
Actual: 9 (number) was expected to be within 10 % of 10 (number)
```


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

Expand Down
5 changes: 2 additions & 3 deletions source/expectations/matchers/ut_be_within_pct.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ create or replace type body ut_be_within_pct as
if self.expected.data_type = a_actual.data_type then
if self.expected is of (ut_data_value_number) then
l_result :=
treat(self.distance_from_expected 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 ) /
treat(self.expected as ut_data_value_number).data_value;
abs(treat(self.distance_from_expected as ut_data_value_number).data_value) * treat(self.expected as ut_data_value_number).data_value
>= abs( ( treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value ) * 100 );
end if;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
Expand Down
36 changes: 36 additions & 0 deletions test/ut3_user/expectations/binary/test_to_be_within_pct.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ create or replace package body test_to_be_within_pct is

ut3_develop.ut.expect( 2.987654321 ).not_to( ut3_develop.be_within_pct( 0.1 ).of_(3) );
expect_success;

ut3_develop.ut.expect( 3.012345679 ).to_be_within_pct( 1 ).of_(3);
expect_success;

ut3_develop.ut.expect( 3.012345679 ).to_( ut3_develop.be_within_pct( 1 ).of_(3) );
expect_success;

ut3_develop.ut.expect( 3.012345679 ).not_to_be_within_pct( 0.1 ).of_(3);
expect_success;

ut3_develop.ut.expect( 3.012345679 ).not_to( ut3_develop.be_within_pct( 0.1 ).of_(3) );
expect_success;

ut3_develop.ut.expect( 0 ).to_be_within_pct( 10 ).of_( 0 );
expect_success;

ut3_develop.ut.expect( 0 ).to_be_within_pct( 100 ).of_( 1 );
expect_success;

ut3_develop.ut.expect( -1 ).to_be_within_pct( 200 ).of_( 1 );
expect_success;
end;

procedure failed_tests is
Expand All @@ -140,6 +161,21 @@ create or replace package body test_to_be_within_pct is

ut3_develop.ut.expect( 2.987654321 ).not_to( ut3_develop.be_within_pct( 1 ).of_(3) );
expect_failure;

ut3_develop.ut.expect( 3.012345679 ).to_be_within_pct( 0.1 ).of_(3);
expect_failure;

ut3_develop.ut.expect( 3.012345679 ).to_( ut3_develop.be_within_pct( 0.1 ).of_(3) );
expect_failure;

ut3_develop.ut.expect( 3.012345679 ).not_to_be_within_pct( 1 ).of_(3);
expect_failure;

ut3_develop.ut.expect( 3.012345679 ).not_to( ut3_develop.be_within_pct( 1 ).of_(3) );
expect_failure;

ut3_develop.ut.expect( 0.1 ).to_be_within_pct( 10 ).of_( 0 );
expect_failure;
end;

procedure fail_for_number_not_within is
Expand Down