Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Feature/rework matcher #1076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Feb 4, 2022
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 documentation and tests
  • Loading branch information
lwasylow committed Jun 7, 2020
commit 9ee0e75cfa6f3e8cfef95e7f47d54f62c1990d93
76 changes: 73 additions & 3 deletions 76 docs/userguide/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1096,15 +1096,85 @@ SUCCESS

## to_be_within of

This fuzzy matcher is designed to allow user to compare a numbers and dates within distance of error.
This matcher is created to determine wheter expected value is approximately equal or "close" to another value.

We are allowing a numbers to be compared within a absolute distance from other number of within a percentage calculated based on expected value.
Matcher will allow to compare numbers as well as dates.

When comparing a date a distance is measured in interval.
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(3).to_be_within(1).of_(4);
end;
/
```

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

**Example 3.**
```sql
begin
ut.expect(sysdate).to_be_within_pct(interval '1' day).of_(sysdate + 1);
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
end;
/
```

**Example 4.**
```sql
begin
ut.expect(sysdate).to_be_within_pct(interval '1' month).of_(add_months(sysdate,1));
end;
/
```

**Example 5.**
```sql
begin
ut.expect(3).to_be_within(1).of_(5);
end;
/
```

Returns following output via DBMS_OUTPUT:
```
Failures:

1) wihtin_test
Actual: 3 (number) was expected to be within 1 of 5 (number)
at "UT3_DEVELOP.UT_BE_WITHIN.OF_", line 48 l_result.expectation.to_(l_result );
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
```

**Example 6.**
```sql
begin
ut.expect(sysdate).to_be_within(interval '1' day).of_(sysdate+2);
end;
/
```

Returns following output via DBMS_OUTPUT:
```
Failures:

1) wihtin_test
Actual: 2020-06-07T13:32:58 (date) was expected to be within 1 day of 2020-06-09T13:32:58 (date)
at "UT3_DEVELOP.UT_BE_WITHIN.OF_", line 55 l_result.expectation.to_(l_result );
at "UT3_DEVELOP.TEST_BETWNSTR.WIHTIN_TEST", line 5
```

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

Expand Down
40 changes: 34 additions & 6 deletions 40 source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,29 @@ create or replace package body ut_utils is
l_second varchar2(100) := extract(second from a_interval);
l_result varchar2(32767);
begin
l_result := case when l_day > 0 then l_day ||' day' else null end;
l_result := l_result || case when l_hour > 0 then ' '|| l_hour ||' hour' else null end;
l_result := l_result || case when l_minute> 0 then ' '||l_minute ||' minute' else null end;
l_result := l_result || case when l_second > 0 then ' '||l_second ||' second' else null end;
l_result := case
when l_day = 1 then l_day ||' day'
when l_day > 1 then l_day ||' days'
else null
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
end;
l_result := l_result ||
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
case
when l_hour = 1 then ' '|| l_hour ||' hour'
when l_hour > 1 then ' '|| l_hour ||' hours'
else null
end;
l_result := l_result ||
case
when l_minute = 1 then ' '||l_minute ||' minute'
when l_minute > 1 then ' '||l_minute ||' minutes'
else null
end;
l_result := l_result ||
case
when l_second = 1 then ' '||l_second ||' second'
when l_second > 1 then ' '||l_second ||' seconds'
else null
end;
return trim(leading ' ' from l_result);
end;

Expand All @@ -896,8 +915,17 @@ create or replace package body ut_utils is
l_month varchar2(20) := extract(month from a_interval);
l_result varchar2(32767);
begin
l_result := case when l_year > 0 then l_year ||' year' else null end;
l_result := l_result || case when l_month > 0 then ' '||l_month ||' month' else null end;
l_result := case
when l_year = 1 then l_year ||' year'
when l_year > 1 then l_year ||' years'
else null
end;
l_result := l_result ||
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
case
when l_month = 1 then ' '||l_month ||' month'
when l_month > 1 then ' '||l_month ||' months'
else null
end;
return trim(leading ' ' from l_result);
end;

Expand Down
23 changes: 16 additions & 7 deletions 23 source/expectations/matchers/ut_be_within.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ create or replace type body ut_be_within as
begin
if self.expected.data_type = a_actual.data_type then
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
if self.expected is of (ut_data_value_number) and self.is_pct = 0 then
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;
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;
elsif self.expected is of (ut_data_value_number) and self.is_pct = 1 then
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 ) /
(treat(self.expected as ut_data_value_number).data_value) ;
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 ) /
(treat(self.expected as ut_data_value_number).data_value)) ;
elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_yminterval) then
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
and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_yminterval).data_value;
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
and
(treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_yminterval).data_value;
elsif self.expected is of (ut_data_value_date) and self.dist is of ( ut_data_value_dsinterval) then
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
and (treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_dsinterval).data_value;
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
and
(treat(self.expected as ut_data_value_date).data_value) + treat(self.dist as ut_data_value_dsinterval).data_value;
end if;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
Expand Down
57 changes: 57 additions & 0 deletions 57 test/ut3_tester/core/test_ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,62 @@ end;
--Assert
ut.expect(l_actual).to_equal(l_expected);
end;

procedure int_conv_ds_sec is
l_expected varchar2(100) := '1 second';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' second);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ds_minute is
l_expected varchar2(100) := '1 minute';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' minute);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ds_hour is
l_expected varchar2(100) := '1 hour';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' hour);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ds_day is
l_expected varchar2(100) := '1 day';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' day);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ds_date is
l_expected varchar2(100) := '2 days 3 hours 4 minutes 11.333 seconds';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(INTERVAL '2 3:04:11.333' DAY TO SECOND);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ym_year is
l_expected varchar2(100) := '1 year';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' year);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ym_month is
l_expected varchar2(100) := '1 month';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(interval '1' month);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

procedure int_conv_ym_date is
l_expected varchar2(100) := '1 year 2 months';
l_actual varchar2(200) := ut3_develop.ut_utils.interval_to_text(INTERVAL '1-2' YEAR TO MONTH);
begin
ut.expect(l_expected).to_equal(l_actual);
end;

end test_ut_utils;
/
29 changes: 29 additions & 0 deletions 29 test/ut3_tester/core/test_ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,34 @@ create or replace package test_ut_utils is
--%test(replace_multiline_comments - replaces multi-line comments with empty lines)
procedure replace_multiline_comments;

--%context(interval_converter_to_strin)

--%test(Test day to second interval passing a second)
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
procedure int_conv_ds_sec;

--%test(Test day to second interval passing a minute)
procedure int_conv_ds_minute;

--%test(Test day to second interval passing a hour)
procedure int_conv_ds_hour;

--%test(Test day to second interval passing a day)
procedure int_conv_ds_day;

--%test(Test day to second interval passing a custom date )
lwasylow marked this conversation as resolved.
Show resolved Hide resolved
procedure int_conv_ds_date;

--%test(Test year to month interval passing a hour)
procedure int_conv_ym_year;

--%test(Test year to month interval passing a day)
procedure int_conv_ym_month;

--%test(Test year to month interval passing a custom date )
procedure int_conv_ym_date;


--%endcontext

end test_ut_utils;
/
4 changes: 2 additions & 2 deletions 4 test/ut3_user/expectations/binary/test_to_be_within.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ create or replace package body test_to_be_within is
--Act
ut3_develop.ut.expect(sysdate).to_be_within(INTERVAL '2 3:04:11.333' DAY TO SECOND).of_(sysdate+100);
--Assert
l_expected_message := q'[Actual: % (date) was expected to be within 2 day 3 hour 4 minute 11.333 second of % (date)]';
l_expected_message := q'[Actual: % (date) was expected to be within 2 days 3 hours 4 minutes 11.333 seconds of % (date)]';
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
Expand Down Expand Up @@ -131,7 +131,7 @@ create or replace package body test_to_be_within is
--Act
ut3_develop.ut.expect(sysdate).to_be_within(INTERVAL '1-3' YEAR TO MONTH).of_(sysdate+720);
--Assert
l_expected_message := q'[Actual: % (date) was expected to be within 1 year 3 month % (date)]';
l_expected_message := q'[Actual: % (date) was expected to be within 1 year 3 months % (date)]';
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.