Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Adds interval support to be_between matcher
  • Loading branch information
Pablo Roldán Ruíz committed Dec 20, 2016
commit 11006d47c7a9c3d2972910dc09eb34df717a7028
30 changes: 30 additions & 0 deletions source/expectations/matchers/be_between.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ create or replace type body be_between is
init(ut_data_value_timestamp_ltz(a_lower_bound), ut_data_value_timestamp_ltz(a_upper_bound));
return;
end;

constructor function be_between(self in out nocopy be_between, a_lower_bound yminterval_unconstrained, a_upper_bound yminterval_unconstrained)
return self as result is
begin
init(ut_data_value_yminterval(a_lower_bound), ut_data_value_yminterval(a_upper_bound));
return;
end;

constructor function be_between(self in out nocopy be_between, a_lower_bound dsinterval_unconstrained, a_upper_bound dsinterval_unconstrained)
return self as result is
begin
init(ut_data_value_dsinterval(a_lower_bound), ut_data_value_dsinterval(a_upper_bound));
return;
end;

overriding member function run_matcher(self in out nocopy be_between, a_actual ut_data_value) return boolean is
l_result boolean;
Expand Down Expand Up @@ -96,6 +110,22 @@ create or replace type body be_between is
begin
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
end;
elsif self.lower_bound is of(ut_data_value_yminterval) and self.upper_bound is of(ut_data_value_yminterval) and a_actual is of(ut_data_value_yminterval) then
declare
l_lower ut_data_value_yminterval := treat(self.lower_bound as ut_data_value_yminterval);
l_upper ut_data_value_yminterval := treat(self.upper_bound as ut_data_value_yminterval);
l_actual ut_data_value_yminterval := treat(a_actual as ut_data_value_yminterval);
begin
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
end;
elsif self.lower_bound is of(ut_data_value_dsinterval) and self.upper_bound is of(ut_data_value_dsinterval) and a_actual is of(ut_data_value_dsinterval) then
declare
l_lower ut_data_value_dsinterval := treat(self.lower_bound as ut_data_value_dsinterval);
l_upper ut_data_value_dsinterval := treat(self.upper_bound as ut_data_value_dsinterval);
l_actual ut_data_value_dsinterval := treat(a_actual as ut_data_value_dsinterval);
begin
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
end;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
end if;
Expand Down
4 changes: 4 additions & 0 deletions source/expectations/matchers/be_between.tps
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ create or replace type be_between under ut_matcher
return self as result,
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_ltz_unconstrained, a_upper_bound timestamp_ltz_unconstrained)
return self as result,
constructor function be_between(self in out nocopy be_between, a_lower_bound yminterval_unconstrained, a_upper_bound yminterval_unconstrained)
return self as result,
constructor function be_between(self in out nocopy be_between, a_lower_bound dsinterval_unconstrained, a_upper_bound dsinterval_unconstrained)
return self as result,

overriding member function run_matcher(self in out nocopy be_between, a_actual ut_data_value) return boolean
)
Expand Down
7 changes: 7 additions & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ create table ut$test_table (val varchar2(1));
@@lib/RunTest.sql ut_expectations/greater_than.sql
@@lib/RunTest.sql ut_expectations/less_or_equal.sql
@@lib/RunTest.sql ut_expectations/less_than.sql
@@lib/RunTest.sql ut_expectations/be_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_ltz_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_ltz_not_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_not_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_tz_between.sql
@@lib/RunTest.sql ut_expectations/timestamp_tz_not_between.sql

--Global cleanup
drop package ut_example_tests;
Expand Down
15 changes: 15 additions & 0 deletions tests/ut_expectations/be_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PROMPT Be between

@@ut_expectations/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-2' 'sysdate-1' 'ut_utils.tr_failure'
@@ut_expectations/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '1.999' 'ut_utils.tr_failure'
@@ut_expectations/common/ut.expect.common.be_between.sql 'varchar2(1)' '''c''' '''a''' '''b''' 'ut_utils.tr_failure'
@@ut_expectations/common/ut.expect.common.be_between.sql 'interval year to month' '''2-2''' '''2-0''' '''2-1''' 'ut_utils.tr_failure'
@@ut_expectations/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 00:59:59''' 'ut_utils.tr_failure'

@@ut_expectations/common/ut.expect.common.be_between.sql 'date' 'sysdate' 'sysdate-1' 'sysdate+1' 'ut_utils.tr_success'
@@ut_expectations/common/ut.expect.common.be_between.sql 'number' '2.0' '1.99' '2.01' 'ut_utils.tr_success'
@@ut_expectations/common/ut.expect.common.be_between.sql 'varchar2(1)' '''b''' '''a''' '''c''' 'ut_utils.tr_success'
@@ut_expectations/common/ut.expect.common.be_between.sql 'interval year to month' '''2-1''' '''2-0''' '''2-2''' 'ut_utils.tr_success'
@@ut_expectations/common/ut.expect.common.be_between.sql 'interval day to second' '''2 01:00:00''' '''2 00:59:58''' '''2 01:00:01''' 'ut_utils.tr_success'


21 changes: 21 additions & 0 deletions tests/ut_expectations/common/ut.expect.common.be_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--Arrange
declare
l_value1 &&1 := &&2;
l_value_lower &&1 := &&3;
l_value_upper &&1 := &&4;
l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value1).to_(be_between(l_value_lower,l_value_upper));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&5 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&5||''', got: '''||l_result||'''' );
end if;
end;
/
23 changes: 23 additions & 0 deletions tests/ut_expectations/timestamp_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_value timestamp := to_timestamp('1997-01-31 09:26:50.13','YYYY-MM-DD HH24.MI.SSXFF');
l_value_lower timestamp := to_timestamp('1997-01-31 09:26:50.11','YYYY-MM-DD HH24.MI.SSXFF');
l_value_upper timestamp := to_timestamp('1997-01-31 09:26:50.14','YYYY-MM-DD HH24.MI.SSXFF');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value).to_(be_between(l_value_lower,l_value_upper));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_success then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_success||''', got: '''||l_result||'''' );
end if;
end;
/

22 changes: 22 additions & 0 deletions tests/ut_expectations/timestamp_ltz_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--Arrange
declare
l_value timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_lower timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_upper timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SSXFF TZR');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value).to_(be_between(l_value_lower,l_value_upper));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_success then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_success||''', got: '''||l_result||'''' );
end if;
end;
/
23 changes: 23 additions & 0 deletions tests/ut_expectations/timestamp_ltz_not_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_value_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_lower_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_upper_tlz timestamp with local time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SSXFF TZR');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value_tlz).to_(be_between(l_value_lower_tlz,l_value_upper_tlz));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_failure then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' );
end if;
end;
/

23 changes: 23 additions & 0 deletions tests/ut_expectations/timestamp_not_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_value timestamp := to_timestamp('1997-01-31 09:26:50.13','YYYY-MM-DD HH24.MI.SSXFF');
l_value_lower timestamp := to_timestamp('1997-01-31 09:26:50.11','YYYY-MM-DD HH24.MI.SSXFF');
l_value_upper timestamp := to_timestamp('1997-01-31 09:26:50.12','YYYY-MM-DD HH24.MI.SSXFF');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value).to_(be_between(l_value_lower,l_value_upper));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_failure then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' );
end if;
end;
/

23 changes: 23 additions & 0 deletions tests/ut_expectations/timestamp_tz_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_value timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_lower timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_upper timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SSXFF TZR');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value).to_(be_between(l_value_lower,l_value_upper));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_success then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_success||''', got: '''||l_result||'''' );
end if;
end;
/

23 changes: 23 additions & 0 deletions tests/ut_expectations/timestamp_tz_not_between.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_value_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +01:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_lower_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +02:00','YYYY-MM-DD HH24.MI.SSXFF TZR');
l_value_upper_tz timestamp with time zone := to_timestamp_tz('1997-01-31 09:26:50.12 +03:00','YYYY-MM-DD HH24.MI.SSXFF TZR');

l_result integer;
l_asserts_results ut_objects_list;
begin
--Act
ut.expect(l_value_tz).to_(be_between(l_value_lower_tz,l_value_upper_tz));
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = ut_utils.tr_failure then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' );
end if;
end;
/