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

Skip to content

Commit fd7ef9c

Browse files
committed
Fixed issues with precission of distance. NATURAL is a subtype of integer and cannot be used to express a decimal distace value.
Improved tests coverage for various scenarios.
1 parent 7fec0f9 commit fd7ef9c

3 files changed

Lines changed: 33 additions & 27 deletions

File tree

source/expectations/ut_expectation.tpb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ create or replace type body ut_expectation as
694694
self.not_to( ut_contain(a_expected).negated() );
695695
end;
696696

697-
member function to_be_within(a_dist natural) return ut_be_within is
697+
member function to_be_within(a_dist number) return ut_be_within is
698698
l_result ut_be_within;
699699
begin
700700
l_result := ut_be_within(a_dist);
@@ -718,15 +718,15 @@ create or replace type body ut_expectation as
718718
return l_result;
719719
end;
720720

721-
member function to_be_within_pct(a_dist natural) return ut_be_within_pct is
721+
member function to_be_within_pct(a_dist number) return ut_be_within_pct is
722722
l_result ut_be_within_pct;
723723
begin
724724
l_result := ut_be_within_pct(a_dist);
725725
l_result.expectation := self;
726726
return l_result;
727727
end;
728728

729-
member function not_to_be_within(a_dist natural) return ut_be_within is
729+
member function not_to_be_within(a_dist number) return ut_be_within is
730730
l_result ut_be_within;
731731
begin
732732
l_result := treat( ut_be_within(a_dist).negated() as ut_be_within);
@@ -750,7 +750,7 @@ create or replace type body ut_expectation as
750750
return l_result;
751751
end;
752752

753-
member function not_to_be_within_pct(a_dist natural) return ut_be_within_pct is
753+
member function not_to_be_within_pct(a_dist number) return ut_be_within_pct is
754754
l_result ut_be_within_pct;
755755
begin
756756
l_result := treat( ut_be_within_pct(a_dist).negated() as ut_be_within_pct);

source/expectations/ut_expectation.tps

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_expectation under ut_expectation_base(
1+
create or replace type ut_expectation force under ut_expectation_base(
22
/*
33
utPLSQL - Version 3
44
Copyright 2016 - 2021 utPLSQL Project
@@ -164,14 +164,14 @@ create or replace type ut_expectation under ut_expectation_base(
164164
member procedure to_contain(self in ut_expectation, a_expected anydata),
165165
member procedure not_to_contain(self in ut_expectation, a_expected anydata),
166166

167-
member function to_be_within(a_dist natural) return ut_be_within,
167+
member function to_be_within(a_dist number) return ut_be_within,
168168
member function to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
169169
member function to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
170-
member function to_be_within_pct(a_dist natural) return ut_be_within_pct,
171-
member function not_to_be_within(a_dist natural) return ut_be_within,
170+
member function to_be_within_pct(a_dist number) return ut_be_within_pct,
171+
member function not_to_be_within(a_dist number) return ut_be_within,
172172
member function not_to_be_within(a_dist dsinterval_unconstrained) return ut_be_within,
173173
member function not_to_be_within(a_dist yminterval_unconstrained) return ut_be_within,
174-
member function not_to_be_within_pct(a_dist natural) return ut_be_within_pct
174+
member function not_to_be_within_pct(a_dist number) return ut_be_within_pct
175175
)
176176
not final
177177
/

test/ut3_user/expectations/binary/test_to_be_within_pct.pkb

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,31 @@ create or replace package body test_to_be_within_pct is
114114

115115
procedure success_tests is
116116
begin
117-
ut3_develop.ut.expect( 2.987654321 ).to_be_within_pct( 1 ).of_(3);
117+
ut3_develop.ut.expect( 1 ).to_be_within_pct( 0.01 ).of_(1.0001);
118118
expect_success;
119119

120-
ut3_develop.ut.expect( 2.987654321 ).to_( ut3_develop.be_within_pct( 1 ).of_(3) );
120+
ut3_develop.ut.expect( 1.0001 ).to_( ut3_develop.be_within_pct( 0.01 ).of_(1) );
121121
expect_success;
122122

123-
ut3_develop.ut.expect( 2.987654321 ).not_to_be_within_pct( 0.1 ).of_(3);
123+
ut3_develop.ut.expect( 1.0002 ).not_to_be_within_pct( 0.01 ).of_(1);
124124
expect_success;
125125

126-
ut3_develop.ut.expect( 2.987654321 ).not_to( ut3_develop.be_within_pct( 0.1 ).of_(3) );
126+
ut3_develop.ut.expect( 1 ).not_to( ut3_develop.be_within_pct( 0.01 ).of_(1.0002) );
127127
expect_success;
128128

129-
ut3_develop.ut.expect( 3.012345679 ).to_be_within_pct( 1 ).of_(3);
129+
ut3_develop.ut.expect( 1.0001 ).to_be_within_pct( -0.01 ).of_(1);
130130
expect_success;
131131

132-
ut3_develop.ut.expect( 3.012345679 ).to_( ut3_develop.be_within_pct( 1 ).of_(3) );
132+
ut3_develop.ut.expect( 1 ).to_( ut3_develop.be_within_pct( -0.01 ).of_(1.0001) );
133133
expect_success;
134134

135-
ut3_develop.ut.expect( 3.012345679 ).not_to_be_within_pct( 0.1 ).of_(3);
135+
ut3_develop.ut.expect( 1.00000001 ).not_to_be_within_pct( 0 ).of_(1);
136136
expect_success;
137137

138-
ut3_develop.ut.expect( 3.012345679 ).not_to( ut3_develop.be_within_pct( 0.1 ).of_(3) );
138+
ut3_develop.ut.expect( 0 ).not_to( ut3_develop.be_within_pct( 0.01 ).of_(0.000001) );
139139
expect_success;
140140

141-
ut3_develop.ut.expect( 0 ).to_be_within_pct( 10 ).of_( 0 );
141+
ut3_develop.ut.expect( 0 ).to_be_within_pct( 0 ).of_( 0 );
142142
expect_success;
143143

144144
ut3_develop.ut.expect( 0 ).to_be_within_pct( 100 ).of_( 1 );
@@ -150,31 +150,37 @@ create or replace package body test_to_be_within_pct is
150150

151151
procedure failed_tests is
152152
begin
153-
ut3_develop.ut.expect( 2.987654321 ).to_be_within_pct( 0.1 ).of_(3);
153+
ut3_develop.ut.expect( 1 ).not_to_be_within_pct( 0.01 ).of_(1.0001);
154154
expect_failure;
155155

156-
ut3_develop.ut.expect( 2.987654321 ).to_( ut3_develop.be_within_pct( 0.1 ).of_(3) );
156+
ut3_develop.ut.expect( 1.0001 ).not_to( ut3_develop.be_within_pct( 0.01 ).of_(1) );
157157
expect_failure;
158158

159-
ut3_develop.ut.expect( 2.987654321 ).not_to_be_within_pct( 1 ).of_(3);
159+
ut3_develop.ut.expect( 1.0002 ).to_be_within_pct( 0.01 ).of_(1);
160160
expect_failure;
161161

162-
ut3_develop.ut.expect( 2.987654321 ).not_to( ut3_develop.be_within_pct( 1 ).of_(3) );
162+
ut3_develop.ut.expect( 1 ).to_( ut3_develop.be_within_pct( 0.01 ).of_(1.0002) );
163163
expect_failure;
164164

165-
ut3_develop.ut.expect( 3.012345679 ).to_be_within_pct( 0.1 ).of_(3);
165+
ut3_develop.ut.expect( 1.0001 ).not_to_be_within_pct( -0.01 ).of_(1);
166166
expect_failure;
167167

168-
ut3_develop.ut.expect( 3.012345679 ).to_( ut3_develop.be_within_pct( 0.1 ).of_(3) );
168+
ut3_develop.ut.expect( 1 ).not_to( ut3_develop.be_within_pct( -0.01 ).of_(1.0001) );
169169
expect_failure;
170170

171-
ut3_develop.ut.expect( 3.012345679 ).not_to_be_within_pct( 1 ).of_(3);
171+
ut3_develop.ut.expect( 1.00000001 ).to_be_within_pct( 0 ).of_(1);
172172
expect_failure;
173173

174-
ut3_develop.ut.expect( 3.012345679 ).not_to( ut3_develop.be_within_pct( 1 ).of_(3) );
174+
ut3_develop.ut.expect( 0 ).to_( ut3_develop.be_within_pct( 0.01 ).of_(0.000001) );
175175
expect_failure;
176176

177-
ut3_develop.ut.expect( 0.1 ).to_be_within_pct( 10 ).of_( 0 );
177+
ut3_develop.ut.expect( 0 ).not_to_be_within_pct( 0 ).of_( 0 );
178+
expect_failure;
179+
180+
ut3_develop.ut.expect( 0 ).not_to_be_within_pct( 100 ).of_( 1 );
181+
expect_failure;
182+
183+
ut3_develop.ut.expect( -1 ).not_to_be_within_pct( 200 ).of_( 1 );
178184
expect_failure;
179185
end;
180186

0 commit comments

Comments
 (0)