Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions source/api/be_within.syn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create synonym be_within for ut_be_within;
1 change: 1 addition & 0 deletions source/create_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ grant execute on &&ut3_owner..ut_be_like to &ut3_user;
grant execute on &&ut3_owner..ut_be_not_null to &ut3_user;
grant execute on &&ut3_owner..ut_be_null to &ut3_user;
grant execute on &&ut3_owner..ut_be_true to &ut3_user;
grant execute on &&ut3_owner..ut_be_within to &ut3_user;
grant execute on &&ut3_owner..ut_contain to &ut3_user;
grant execute on &&ut3_owner..ut_equal to &ut3_user;
grant execute on &&ut3_owner..ut_have_count to &ut3_user;
Expand Down
1 change: 1 addition & 0 deletions source/create_synonyms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ create &action_type. synonym &ut3_user.be_like for &&ut3_owner..be_like;
create &action_type. synonym &ut3_user.be_not_null for &&ut3_owner..be_not_null;
create &action_type. synonym &ut3_user.be_null for &&ut3_owner..be_null;
create &action_type. synonym &ut3_user.be_true for &&ut3_owner..be_true;
create &action_type. synonym &ut3_user.be_within for &&ut3_owner..be_within;
create &action_type. synonym &ut3_user.contain for &&ut3_owner..contain;
create &action_type. synonym &ut3_user.equal for &&ut3_owner..equal;
create &action_type. synonym &ut3_user.have_count for &&ut3_owner..have_count;
Expand Down
42 changes: 25 additions & 17 deletions source/expectations/matchers/ut_be_within.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@ create or replace type body ut_be_within as
limitations under the License.
*/

member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value, a_is_pct number , a_self_type varchar2 := null) is
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value) is
begin
self.distance_from_expected := a_distance_from_expected;
self.is_pct := nvl(a_is_pct,0);
self.self_type := nvl( a_self_type, $$plsql_unit );
self.self_type := $$plsql_unit;
end;

constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number, a_is_pct number) return self as result is
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result is
begin
init(ut_data_value_number(a_distance_from_expected),a_is_pct);
init(ut_data_value_number(a_distance_from_expected));
return;
end;

constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained, a_is_pct number) return self as result is
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result is
begin
init(ut_data_value_dsinterval(a_distance_from_expected),a_is_pct);
init(ut_data_value_dsinterval(a_distance_from_expected));
return;
end;

constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained, a_is_pct number) return self as result is
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result is
begin
init(ut_data_value_yminterval(a_distance_from_expected),a_is_pct);
init(ut_data_value_yminterval(a_distance_from_expected));
return;
end;

Expand All @@ -62,20 +61,29 @@ create or replace type body ut_be_within as
l_result.expectation.to_(l_result );
end if;
end;


member function of_(self in ut_be_within, a_expected number) return ut_be_within is
l_result ut_be_within := self;
begin
l_result.expected := ut_data_value_number(a_expected);
return l_result;
end;

member function of_(self in ut_be_within, a_expected date) return ut_be_within is
l_result ut_be_within := self;
begin
l_result.expected := ut_data_value_date(a_expected);
return l_result;
end;

overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is
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) and self.is_pct = 0 then
if self.expected is of (ut_data_value_number) 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.distance_from_expected 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.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)) ;
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected is of ( ut_data_value_yminterval) then
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected 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.distance_from_expected as ut_data_value_yminterval).data_value
Expand Down
14 changes: 7 additions & 7 deletions source/expectations/matchers/ut_be_within.tps
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ create or replace type ut_be_within under ut_comparison_matcher(
* Holds information about mather options
*/
distance_from_expected ut_data_value,
is_pct number(1,0),

member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value, a_is_pct number , a_self_type varchar2 := null),
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number, a_is_pct number) return self as result,
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained, a_is_pct number) return self as result,
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained, a_is_pct number) return self as result,
member procedure init(self in out nocopy ut_be_within, a_distance_from_expected ut_data_value),
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected number) return self as result,
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected dsinterval_unconstrained) return self as result,
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result,
member procedure of_(self in ut_be_within, a_expected number),
member procedure of_(self in ut_be_within, a_expected date),

member function of_(self in ut_be_within, a_expected number) return ut_be_within,
member function of_(self in ut_be_within, a_expected date) return ut_be_within,

overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean,
overriding member function failure_message(a_actual ut_data_value) return varchar2,
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2
Expand Down
42 changes: 42 additions & 0 deletions source/expectations/matchers/ut_be_within_pct.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
create or replace type body ut_be_within_pct 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.
*/

constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_distance_from_expected number) return self as result is
begin
self.init(ut_data_value_number(a_distance_from_expected));
return;
end;

overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean is
l_result boolean;
begin
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)) ;
end if;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
end if;
return l_result;
end;

end;
/
24 changes: 24 additions & 0 deletions source/expectations/matchers/ut_be_within_pct.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create or replace type ut_be_within_pct under ut_be_within(
/*
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.
*/


constructor function ut_be_within_pct(self in out nocopy ut_be_within_pct, a_distance_from_expected number) return self as result,
overriding member function run_matcher(self in out nocopy ut_be_within_pct, a_actual ut_data_value) return boolean
)
not final
/
5 changes: 0 additions & 5 deletions source/expectations/matchers/ut_matcher.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ create or replace type body ut_matcher as
begin
ut_utils.debug_log('Failure - ut_matcher.run_matcher'||'(a_actual '||a_actual.data_type||')');
self.is_errored := ut_utils.boolean_to_int(true);
-- self.error_message := 'The matcher '''||name()||''' cannot be used';
-- if self.expected is not null then
-- self.error_message := self.error_message ||' for comparison of data type ('||self.expected.data_type||')';
-- end if;
-- self.error_message := self.error_message ||' with data type ('||a_actual.data_type||').';
return null;
end;

Expand Down
64 changes: 32 additions & 32 deletions source/expectations/ut_expectation.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -694,70 +694,70 @@ create or replace type body ut_expectation as
self.not_to( ut_contain(a_expected).negated() );
end;

member function to_be_within(a_dist natural) return ut_be_within is
member function to_be_within(a_dist natural) return ut_be_within is
l_result ut_matcher;
Comment thread
lwasylow marked this conversation as resolved.
Outdated
begin
l_result := ut_be_within(a_dist,0);
l_result := ut_be_within(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within);
end;

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

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

member function to_be_within_pct(a_dist natural) return ut_be_within is
l_result ut_matcher;
begin
l_result := ut_be_within(a_dist,1);
l_result.expectation := self;
return treat(l_result as ut_be_within);
member function to_be_within_pct(a_dist natural) return ut_be_within_pct is
l_result ut_matcher;
begin
l_result := ut_be_within_pct(a_dist);
l_result.expectation := self;
return treat(l_result as ut_be_within_pct);
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,0).negated;
l_result.expectation := self;
return treat(l_result as ut_be_within);
end;

member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within is
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,0).negated;
l_result := ut_be_within(a_dist).negated();
l_result.expectation := self;
return treat(l_result as ut_be_within);
end;
member function not_to_be_within(a_dist yminterval_unconstrained) return ut_be_within is
end;

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

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

end;

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

end;
/

6 changes: 2 additions & 4 deletions source/expectations/ut_expectation.tps
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,11 @@ create or replace type ut_expectation under ut_expectation_base(
member function to_be_within(a_dist natural) return ut_be_within,
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
member function to_be_within_pct(a_dist natural) return ut_be_within,

member function to_be_within_pct(a_dist natural) return ut_be_within_pct,
member function not_to_be_within(a_dist natural) return ut_be_within,
member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
member function not_to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
member function not_to_be_within_pct(a_dist natural) return ut_be_within

member function not_to_be_within_pct(a_dist natural) return ut_be_within_pct
)
not final
/
3 changes: 3 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'expectations/matchers/ut_matcher.tps'
@@install_component.sql 'expectations/matchers/ut_comparison_matcher.tps'
@@install_component.sql 'expectations/matchers/ut_be_within.tps'
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tps'
@@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 @@ -297,6 +298,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'expectations/matchers/ut_be_true.tpb'
@@install_component.sql 'expectations/matchers/ut_equal.tpb'
@@install_component.sql 'expectations/matchers/ut_be_within.tpb'
@@install_component.sql 'expectations/matchers/ut_be_within_pct.tpb'
@@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 Expand Up @@ -360,6 +362,7 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'api/be_not_null.syn'
@@install_component.sql 'api/be_null.syn'
@@install_component.sql 'api/be_true.syn'
@@install_component.sql 'api/be_within.syn'
@@install_component.sql 'api/equal.syn'
@@install_component.sql 'api/have_count.syn'
@@install_component.sql 'api/match.syn'
Expand Down
24 changes: 0 additions & 24 deletions test/ut3_tester_helper/expectations_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,5 @@ create or replace package body expectations_helper is
return l_execute;
end;

function be_within_expectation_block(
a_matcher_name varchar2,
a_actual_data_type varchar2,
a_actual_data varchar2,
a_expected_data_type varchar2,
a_expected_data varchar2,
a_distance varchar2,
a_distance_data_type varchar2
) return varchar2
is
l_execute varchar2(32000);
begin
l_execute := '
declare
l_actual '||a_actual_data_type||' := '||a_actual_data||';
l_expected '||a_expected_data_type||' := '||a_expected_data||';
l_distance '||a_distance_data_type||' := '||a_distance||';
begin
--act - execute the expectation
ut3_develop.ut.expect( l_actual ).'||a_matcher_name||'(l_distance).of_(l_expected);
end;';
return l_execute;
end;

end;
/
10 changes: 0 additions & 10 deletions test/ut3_tester_helper/expectations_helper.pks
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,5 @@ create or replace package expectations_helper is
a_expected_data varchar2
) return varchar2;

function be_within_expectation_block(
a_matcher_name varchar2,
a_actual_data_type varchar2,
a_actual_data varchar2,
a_expected_data_type varchar2,
a_expected_data varchar2,
a_distance varchar2,
a_distance_data_type varchar2
) return varchar2;

end;
/
Loading