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

Skip to content

Commit 02bff05

Browse files
committed
be_between implementation
tests included
1 parent ec2bb11 commit 02bff05

20 files changed

Lines changed: 240 additions & 9 deletions
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
create or replace type body be_between is
2+
3+
member procedure init(self in out nocopy be_between, a_lower_bound ut_data_value, a_upper_bound ut_data_value) is
4+
begin
5+
self.name := lower($$plsql_unit);
6+
self.lower_bound := a_lower_bound;
7+
self.upper_bound := a_upper_bound;
8+
self.additional_info := 'between ' || a_lower_bound.to_string || ' and ' || a_upper_bound.to_string;
9+
end;
10+
11+
constructor function be_between(self in out nocopy be_between, a_lower_bound date, a_upper_bound date)
12+
return self as result is
13+
begin
14+
init(ut_data_value_date(a_lower_bound), ut_data_value_date(a_upper_bound));
15+
return;
16+
end;
17+
constructor function be_between(self in out nocopy be_between, a_lower_bound number, a_upper_bound number)
18+
return self as result is
19+
begin
20+
init(ut_data_value_number(a_lower_bound), ut_data_value_number(a_upper_bound));
21+
return;
22+
end;
23+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_unconstrained, a_upper_bound timestamp_unconstrained)
24+
return self as result is
25+
begin
26+
init(ut_data_value_timestamp(a_lower_bound), ut_data_value_timestamp(a_upper_bound));
27+
return;
28+
end;
29+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_tz_unconstrained, a_upper_bound timestamp_tz_unconstrained)
30+
return self as result is
31+
begin
32+
init(ut_data_value_timestamp_tz(a_lower_bound), ut_data_value_timestamp_tz(a_upper_bound));
33+
return;
34+
end;
35+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_ltz_unconstrained, a_upper_bound timestamp_ltz_unconstrained)
36+
return self as result is
37+
begin
38+
init(ut_data_value_timestamp_ltz(a_lower_bound), ut_data_value_timestamp_ltz(a_upper_bound));
39+
return;
40+
end;
41+
42+
overriding member function run_matcher(self in out nocopy be_between, a_actual ut_data_value) return boolean is
43+
l_result boolean;
44+
begin
45+
if self.lower_bound is of(ut_data_value_date) and self.lower_bound is of(ut_data_value_date) and a_actual is of(ut_data_value_date) then
46+
declare
47+
l_lower ut_data_value_date := treat(self.lower_bound as ut_data_value_date);
48+
l_upper ut_data_value_date := treat(self.upper_bound as ut_data_value_date);
49+
l_actual ut_data_value_date := treat(a_actual as ut_data_value_date);
50+
begin
51+
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
52+
end;
53+
elsif self.lower_bound is of(ut_data_value_number) and self.lower_bound is of(ut_data_value_number) and a_actual is of(ut_data_value_number) then
54+
declare
55+
l_lower ut_data_value_number := treat(self.lower_bound as ut_data_value_number);
56+
l_upper ut_data_value_number := treat(self.upper_bound as ut_data_value_number);
57+
l_actual ut_data_value_number := treat(a_actual as ut_data_value_number);
58+
begin
59+
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
60+
end;
61+
elsif self.lower_bound is of(ut_data_value_timestamp) and self.lower_bound is of(ut_data_value_timestamp) and a_actual is of(ut_data_value_timestamp) then
62+
declare
63+
l_lower ut_data_value_timestamp := treat(self.lower_bound as ut_data_value_timestamp);
64+
l_upper ut_data_value_timestamp := treat(self.upper_bound as ut_data_value_timestamp);
65+
l_actual ut_data_value_timestamp := treat(a_actual as ut_data_value_timestamp);
66+
begin
67+
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
68+
end;
69+
elsif self.lower_bound is of(ut_data_value_timestamp_tz) and self.lower_bound is of(ut_data_value_timestamp_tz) and a_actual is of(ut_data_value_timestamp_tz) then
70+
declare
71+
l_lower ut_data_value_timestamp_tz := treat(self.lower_bound as ut_data_value_timestamp_tz);
72+
l_upper ut_data_value_timestamp_tz := treat(self.upper_bound as ut_data_value_timestamp_tz);
73+
l_actual ut_data_value_timestamp_tz := treat(a_actual as ut_data_value_timestamp_tz);
74+
begin
75+
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
76+
end;
77+
elsif self.lower_bound is of(ut_data_value_timestamp_ltz) and self.lower_bound is of(ut_data_value_timestamp_ltz) and a_actual is of(ut_data_value_timestamp_ltz) then
78+
declare
79+
l_lower ut_data_value_timestamp_ltz := treat(self.lower_bound as ut_data_value_timestamp_ltz);
80+
l_upper ut_data_value_timestamp_ltz := treat(self.upper_bound as ut_data_value_timestamp_ltz);
81+
l_actual ut_data_value_timestamp_ltz := treat(a_actual as ut_data_value_timestamp_ltz);
82+
begin
83+
l_result := l_actual.datavalue between l_lower.datavalue and l_upper.datavalue;
84+
end;
85+
else
86+
l_result := (self as ut_matcher).run_matcher(a_actual);
87+
end if;
88+
return l_result;
89+
end;
90+
91+
end;
92+
/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
create or replace type be_between under ut_matcher
2+
(
3+
lower_bound ut_data_value,
4+
upper_bound ut_data_value,
5+
6+
member procedure init(self in out nocopy be_between, a_lower_bound ut_data_value, a_upper_bound ut_data_value),
7+
8+
constructor function be_between(self in out nocopy be_between, a_lower_bound date, a_upper_bound date)
9+
return self as result,
10+
constructor function be_between(self in out nocopy be_between, a_lower_bound number, a_upper_bound number)
11+
return self as result,
12+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_unconstrained, a_upper_bound timestamp_unconstrained)
13+
return self as result,
14+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_tz_unconstrained, a_upper_bound timestamp_tz_unconstrained)
15+
return self as result,
16+
constructor function be_between(self in out nocopy be_between, a_lower_bound timestamp_ltz_unconstrained, a_upper_bound timestamp_ltz_unconstrained)
17+
return self as result,
18+
19+
overriding member function run_matcher(self in out nocopy be_between, a_actual ut_data_value) return boolean
20+
)
21+
/

source/expectations/ut_expectation_date.tpb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ create or replace type body ut_expectation_date as
55
ut_utils.debug_log('ut_expectation_date.to_equal(self in ut_expectation, a_expected date, a_nulls_are_equal boolean := null)');
66
self.to_( equal(a_expected, a_nulls_are_equal) );
77
end;
8+
9+
member procedure to_be_between(self in ut_expectation_date, a_lower_bound date, a_higher_bound date) is
10+
begin
11+
ut_utils.debug_log('ut_expectation_date.to_be_between(self in ut_expectation_date, a_lower_bound date, a_higher_bound date)');
12+
self.to_( be_between(a_lower_bound,a_higher_bound) );
13+
end;
814

915
end;
1016
/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
create or replace type ut_expectation_date under ut_expectation
22
(
3-
overriding member procedure to_equal(self in ut_expectation_date, a_expected date, a_nulls_are_equal boolean := null)
3+
overriding member procedure to_equal(self in ut_expectation_date, a_expected date, a_nulls_are_equal boolean := null),
4+
member procedure to_be_between(self in ut_expectation_date, a_lower_bound date, a_higher_bound date)
45
)
56
/

source/expectations/ut_expectation_number.tpb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ create or replace type body ut_expectation_number as
55
ut_utils.debug_log('ut_expectation_number.to_equal(self in ut_expectation, a_expected number, a_nulls_are_equal boolean := null)');
66
self.to_( equal(a_expected, a_nulls_are_equal) );
77
end;
8+
9+
member procedure to_be_between(self in ut_expectation_number, a_lower_bound number, a_higher_bound number) is
10+
begin
11+
ut_utils.debug_log('ut_expectation_date.to_be_between(self in ut_expectation_date, a_lower_bound number, a_higher_bound number)');
12+
self.to_( be_between(a_lower_bound,a_higher_bound) );
13+
end;
814

915
end;
1016
/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
create or replace type ut_expectation_number under ut_expectation
22
(
3-
overriding member procedure to_equal(self in ut_expectation_number, a_expected number, a_nulls_are_equal boolean := null)
3+
overriding member procedure to_equal(self in ut_expectation_number, a_expected number, a_nulls_are_equal boolean := null),
4+
member procedure to_be_between(self in ut_expectation_number, a_lower_bound number, a_higher_bound number)
45
)
56
/

source/expectations/ut_expectation_timestamp.tpb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ create or replace type body ut_expectation_timestamp as
55
ut_utils.debug_log('ut_expectation_timestamp.to_equal(self in ut_expectation, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null)');
66
self.to_( equal(a_expected, a_nulls_are_equal) );
77
end;
8+
9+
member procedure to_be_between(self in ut_expectation_timestamp, a_lower_bound timestamp_unconstrained, a_higher_bound timestamp_unconstrained) is
10+
begin
11+
ut_utils.debug_log('ut_expectation_date.to_be_between(self in ut_expectation_timestamp, a_lower_bound timestamp_unconstrained, a_higher_bound timestamp_unconstrained)');
12+
self.to_( be_between(a_lower_bound, a_higher_bound) );
13+
end;
814

915
end;
1016
/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
create or replace type ut_expectation_timestamp under ut_expectation
22
(
3-
overriding member procedure to_equal(self in ut_expectation_timestamp, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null)
3+
overriding member procedure to_equal(self in ut_expectation_timestamp, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null),
4+
member procedure to_be_between(self in ut_expectation_timestamp, a_lower_bound timestamp_unconstrained, a_higher_bound timestamp_unconstrained)
45
)
56
/

source/expectations/ut_expectation_timestamp_ltz.tpb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ create or replace type body ut_expectation_timestamp_ltz as
55
ut_utils.debug_log('ut_expectation_timestamp_ltz.to_equal(self in ut_expectation, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null)');
66
self.to_( equal(a_expected, a_nulls_are_equal) );
77
end;
8+
9+
member procedure to_be_between(self in ut_expectation_timestamp_ltz, a_lower_bound timestamp_ltz_unconstrained, a_higher_bound timestamp_ltz_unconstrained) is
10+
begin
11+
ut_utils.debug_log('ut_expectation_date.to_be_between(self in ut_expectation_timestamp_ltz, a_lower_bound timestamp_ltz_unconstrained, a_higher_bound timestamp_ltz_unconstrained)');
12+
self.to_( be_between(a_lower_bound, a_higher_bound) );
13+
end;
814

915
end;
1016
/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
create or replace type ut_expectation_timestamp_ltz under ut_expectation
22
(
3-
overriding member procedure to_equal(self in ut_expectation_timestamp_ltz, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null)
3+
overriding member procedure to_equal(self in ut_expectation_timestamp_ltz, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null),
4+
member procedure to_be_between(self in ut_expectation_timestamp_ltz, a_lower_bound timestamp_ltz_unconstrained, a_higher_bound timestamp_ltz_unconstrained)
45
)
56
/

0 commit comments

Comments
 (0)