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
Fixed and simplified matcher
  • Loading branch information
jgebal committed Jun 27, 2020
commit 363c333ba466eef38b57992f821afd397bb08d6a
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ create or replace type ut_data_value_dsinterval under ut_data_value(
See the License for the specific language governing permissions and
limitations under the License.
*/
data_value dsinterval_unconstrained,
data_value interval day(9) to second(9),
constructor function ut_data_value_dsinterval(self in out nocopy ut_data_value_dsinterval, a_value dsinterval_unconstrained) return self as result,
overriding member function is_null return boolean,
overriding member function to_string return varchar2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ create or replace type ut_data_value_yminterval under ut_data_value(
See the License for the specific language governing permissions and
limitations under the License.
*/
data_value yminterval_unconstrained,
data_value interval year(9) to month,
constructor function ut_data_value_yminterval(self in out nocopy ut_data_value_yminterval, a_value yminterval_unconstrained) return self as result,
overriding member function is_null return boolean,
overriding member function to_string return varchar2,
Expand Down
63 changes: 6 additions & 57 deletions source/expectations/matchers/ut_be_within.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -107,64 +107,13 @@ create or replace type body ut_be_within as
end;

overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is
l_result boolean;
function l_result_from_number return boolean is
l_expected number := treat(self.expected as ut_data_value_number).data_value;
l_actual number := treat(a_actual as ut_data_value_number).data_value;
l_distance number := treat(self.distance_from_expected as ut_data_value_number).data_value;
begin
return abs(l_expected - l_actual) <= l_distance;
end;

function l_result_from_date(a_distance ut_data_value) return boolean is
l_expected date := treat(self.expected as ut_data_value_date).data_value;
l_actual date := treat(a_actual as ut_data_value_date).data_value;
l_distance_ym yminterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_yminterval)
then treat(self.distance_from_expected as ut_data_value_yminterval).data_value
end;
l_distance_ds dsinterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_dsinterval)
then treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
end;
begin
return case when l_distance_ym is not null
then l_actual between l_expected - l_distance_ym and l_expected + l_distance_ym
else l_actual between l_expected - l_distance_ds and l_expected + l_distance_ds
end;
end;

function l_result_from_timestamp (a_distance ut_data_value) return boolean is
l_expected timestamp := case when self.expected is of ( ut_data_value_timestamp) then
treat(self.expected as ut_data_value_timestamp).data_value
when self.expected is of ( ut_data_value_timestamp_tz) then
treat(self.expected as ut_data_value_timestamp_tz).data_value
when self.expected is of ( ut_data_value_timestamp_ltz) then
treat(self.expected as ut_data_value_timestamp_ltz).data_value
end;
l_actual timestamp with time zone := treat(a_actual as ut_data_value_date).data_value;
l_distance_ym yminterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_yminterval)
then treat(self.distance_from_expected as ut_data_value_yminterval).data_value
end;
l_distance_ds dsinterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_dsinterval)
then treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
end;
begin
return case when l_distance_ym is not null
then l_actual between l_expected - l_distance_ym and l_expected + l_distance_ym
else l_actual between l_expected - l_distance_ds and l_expected + l_distance_ds
end;
end;


begin
l_result boolean;
begin
if self.expected.data_type = a_actual.data_type then
Comment thread
lwasylow marked this conversation as resolved.
Outdated
if self.expected is of (ut_data_value_number) then
l_result := l_result_from_number;
elsif self.expected is of (ut_data_value_date)then
l_result := l_result_from_date(self.distance_from_expected);
elsif self.expected is of (ut_data_value_timestamp_tz)then
l_result := l_result_from_date(self.distance_from_expected);
elsif self.expected is of (ut_data_value_timestamp_ltz)then
l_result := l_result_from_date(self.distance_from_expected);
if self.expected is of (ut_data_value_date, ut_data_value_number, ut_data_value_timestamp, ut_data_value_timestamp_tz, ut_data_value_timestamp_ltz) then
l_result := ut_be_within_helper.values_within_abs_distance(self.expected, a_actual, self.distance_from_expected) ;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
end if;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
Expand Down
41 changes: 41 additions & 0 deletions source/expectations/matchers/ut_be_within_helper.pkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
create or replace package body ut_be_within_helper as
/*
utPLSQL - Version 3
Copyright 2016 - 2019 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

function values_within_abs_distance(
a_value_1 ut_data_value, a_value_2 ut_data_value, a_distance ut_data_value
) return boolean is
l_result boolean;
begin
execute immediate q'[
begin
:result :=
treat(:a_value_1 as ut3_develop.]'||a_value_1.self_type||q'[).data_value
between
treat(:a_value_2 as ut3_develop.]'||a_value_2.self_type||q'[).data_value
- treat(:a_distance as ut3_develop.]'||a_distance.self_type||q'[).data_value
and
treat(:a_value_2 as ut3_develop.]'||a_value_2.self_type||q'[).data_value
+ treat(:a_distance as ut3_develop.]'||a_distance.self_type||q'[).data_value;
end;
]'
using out l_result, a_value_1, a_value_2, a_distance;
return l_result;
end;

end;
/
24 changes: 24 additions & 0 deletions source/expectations/matchers/ut_be_within_helper.pks
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create or replace package ut_be_within_helper authid definer as
/*
utPLSQL - Version 3
Copyright 2016 - 2019 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

function values_within_abs_distance(
a_value_1 ut_data_value, a_value_2 ut_data_value, a_distance ut_data_value
) return boolean;

end;
/
2 changes: 2 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'expectations/matchers/ut_comparison_matcher.tps'
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tps'
@@install_component.sql 'expectations/matchers/ut_be_within.tps'
@@install_component.sql 'expectations/matchers/ut_be_within_helper.pks'
@@install_component.sql 'expectations/ut_expectation.tps'
@@install_component.sql 'expectations/matchers/ut_be_false.tps'
@@install_component.sql 'expectations/matchers/ut_be_greater_or_equal.tps'
Expand Down Expand Up @@ -299,6 +300,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'expectations/matchers/ut_equal.tpb'
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tpb'
@@install_component.sql 'expectations/matchers/ut_be_within.tpb'
@@install_component.sql 'expectations/matchers/ut_be_within_helper.pkb'
@@install_component.sql 'expectations/matchers/ut_contain.tpb'
@@install_component.sql 'expectations/matchers/ut_have_count.tpb'
@@install_component.sql 'expectations/matchers/ut_be_between.tpb'
Expand Down
2 changes: 2 additions & 0 deletions source/uninstall_objects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ drop type ut_be_within_pct force;

drop type ut_be_within force;

drop package ut_be_within_helper;

drop type ut_comparison_matcher force;

drop type ut_matcher force;
Expand Down
18 changes: 13 additions & 5 deletions test/ut3_user/expectations/binary/test_to_be_within.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ create or replace package body test_to_be_within is
test_to_be_within_success('to_be_within','date', 'sysdate', 'sysdate+200','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','date', 'sysdate+200', 'sysdate','''1-0''','interval year to month');

test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate+1','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate+200','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', 'sysdate+200', 'sysdate','''1-0''','interval year to month');

test_to_be_within_success('to_be_within','timestamp', q'[TIMESTAMP '2017-08-09 07:00:00']', q'[TIMESTAMP '2017-08-08 06:59:48.667']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp', q'[TIMESTAMP '2017-08-08 06:59:48.667']', q'[TIMESTAMP '2017-08-09 07:00:00']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp', q'[TIMESTAMP '2017-08-09 07:00:00']', q'[TIMESTAMP '2018-08-09 07:00:00']','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp', q'[TIMESTAMP '2018-08-09 07:00:00']', q'[TIMESTAMP '2017-08-09 07:00:00']','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2017-08-08 05:59:48.668 -8:00']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-08 05:59:48.668 -8:00']', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2018-08-09 07:00:00 -7:00']','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2018-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2017-08-08 05:59:48.668 -8:00']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2017-08-08 05:59:48.668 -8:00']', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']','''1 0:00:11.333''','interval day to second');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2018-08-09 07:00:00 -7:00']','''1-0''','interval year to month');
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2018-08-09 07:00:00 -7:00']', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']','''1-0''','interval year to month');

test_to_be_within_success('to_( ut3_develop.be_within','number', '2', '4','2','number', ')');
test_to_be_within_success('to_( ut3_develop.be_within','number', '4', '2','2','number', ')');
test_to_be_within_success('to_( ut3_develop.be_within','date', 'sysdate+1', 'sysdate','''1 0:00:11.333''','interval day to second', ')');
Expand Down