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

Skip to content

Commit 322e0a1

Browse files
committed
Making code a bit more readable
1 parent e3fb2d7 commit 322e0a1

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

source/expectations/matchers/ut_be_within.tpb

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,39 @@ create or replace type body ut_be_within as
7575
l_result.expected := ut_data_value_date(a_expected);
7676
return l_result;
7777
end;
78-
78+
7979
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is
8080
l_result boolean;
81+
function l_result_from_number return boolean is
82+
l_expected number := treat(self.expected as ut_data_value_number).data_value;
83+
l_actual number := treat(a_actual as ut_data_value_number).data_value;
84+
l_distance number := treat(self.distance_from_expected as ut_data_value_number).data_value;
85+
begin
86+
return abs(l_expected - l_actual) <= l_distance;
87+
end;
88+
89+
function l_result_from_date(a_distance ut_data_value) return boolean is
90+
l_expected date := treat(self.expected as ut_data_value_date).data_value;
91+
l_actual date := treat(a_actual as ut_data_value_date).data_value;
92+
l_distance_ym yminterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_yminterval)
93+
then treat(self.distance_from_expected as ut_data_value_yminterval).data_value
94+
end;
95+
l_distance_ds dsinterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_dsinterval)
96+
then treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
97+
end;
98+
begin
99+
return case when l_distance_ym is not null
100+
then l_actual between l_expected - l_distance_ym and l_expected + l_distance_ym
101+
else l_actual between l_expected - l_distance_ds and l_expected + l_distance_ds
102+
end;
103+
end;
104+
81105
begin
82106
if self.expected.data_type = a_actual.data_type then
83107
if self.expected is of (ut_data_value_number) then
84-
l_result := abs((treat(self.expected as ut_data_value_number).data_value - treat(a_actual as ut_data_value_number).data_value)) <=
85-
treat(self.distance_from_expected as ut_data_value_number).data_value;
86-
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected is of ( ut_data_value_yminterval) then
87-
l_result := treat(a_actual as ut_data_value_date).data_value
88-
between
89-
(treat(self.expected as ut_data_value_date).data_value) - treat(self.distance_from_expected as ut_data_value_yminterval).data_value
90-
and
91-
(treat(self.expected as ut_data_value_date).data_value) + treat(self.distance_from_expected as ut_data_value_yminterval).data_value;
92-
elsif self.expected is of (ut_data_value_date) and self.distance_from_expected is of ( ut_data_value_dsinterval) then
93-
l_result := treat(a_actual as ut_data_value_date).data_value
94-
between
95-
(treat(self.expected as ut_data_value_date).data_value) - treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
96-
and
97-
(treat(self.expected as ut_data_value_date).data_value) + treat(self.distance_from_expected as ut_data_value_dsinterval).data_value;
108+
l_result := l_result_from_number;
109+
elsif self.expected is of (ut_data_value_date)then
110+
l_result := l_result_from_date(self.distance_from_expected);
98111
end if;
99112
else
100113
l_result := (self as ut_matcher).run_matcher(a_actual);

test/ut3_user/expectations/binary/test_to_be_within.pks

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ create or replace package test_to_be_within is
1212
--%test(gives failure when number is not within distance)
1313
procedure failed_tests;
1414

15-
--%test(check failure message for number not within)
15+
--%test(returns well formatted failure message when expectation fails)
1616
procedure fail_for_number_not_within;
1717

18-
--%test(check failure message for inteval of 1 sec not within)
18+
--%test(returns well formatted failure message for inteval of 1 sec not within)
1919
procedure fail_for_ds_int_not_within;
2020

21-
--%test(check failure message for custom ds interval not within)
21+
--%test(returns well formatted failure message for custom ds interval not within)
2222
procedure fail_for_custom_ds_int;
2323

24-
--%test(check failure message for inteval of 1 month not within)
24+
--%test(returns well formatted failure message for inteval of 1 month not within)
2525
procedure fail_for_ym_int_not_within;
2626

27-
--%test(check failure message for custom ym interval not within)
27+
--%test(returns well formatted failure message for custom ym interval not within)
2828
procedure fail_for_custom_ym_int;
2929

30-
--%test(check failure message for simple within)
30+
--%test(returns well formatted failure message for simple within)
3131
procedure fail_msg_when_not_within;
3232

3333
end;

0 commit comments

Comments
 (0)