-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestValues.pas
More file actions
167 lines (146 loc) · 4.96 KB
/
TestValues.pas
File metadata and controls
167 lines (146 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
unit TestValues;
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (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.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is DUnitLite.
//
// The Initial Developer of the Original Code is Joe White.
// Portions created by Joe White are Copyright (C) 2007
// Joe White. All Rights Reserved.
//
// Contributor(s):
//
// Alternatively, the contents of this file may be used under the terms
// of the LGPL license (the "LGPL License"), in which case the
// provisions of LGPL License are applicable instead of those
// above. If you wish to allow use of your version of this file only
// under the terms of the LGPL License and not to allow others to use
// your version of this file under the MPL, indicate your decision by
// deleting the provisions above and replace them with the notice and
// other provisions required by the LGPL License. If you do not delete
// the provisions above, a recipient may use your version of this file
// under either the MPL or the LGPL License.
interface
uses
Specifications;
type
IFoo = interface
['{2D8CD618-C413-4926-AA3E-325C45812AC0}']
end;
IBar = interface
['{5157E28C-B514-4811-AAB9-DE06D63B5CC1}']
end;
TFooBar = class(TInterfacedObject, IFoo, IBar)
end;
TBase = class
end;
TSub = class(TBase)
end;
EpsilonTestValues = class
const
BaseValue = 42.0;
SameAtDefaultEpsilon = 42.00000000001;
DifferentAtDefaultEpsilon = 42.0000000001;
BarelyDifferent = 42.00000000000000001;
end;
TestEpsilonTestValues = class(TRegisterableSpecification)
strict private
FComparisonValue: Extended;
procedure CheckBaseIsEqualAsDouble;
procedure CheckBaseIsSameValueAsDouble;
procedure CheckBaseIsSameValueAsExtended;
procedure CheckBaseNotEqualAsDouble;
procedure CheckBaseNotEqualAsExtended;
procedure CheckBaseNotSameValueAsDouble;
procedure CheckBaseNotSameValueAsExtended;
published
procedure TestSameAtDefaultEpsilon;
procedure TestDifferentAtDefaultEpsilon;
procedure TestBarelyDifferent;
end;
implementation
uses
Math;
{ TestInterestingEpsilons }
procedure TestEpsilonTestValues.CheckBaseIsEqualAsDouble;
var
Base: Double;
Comparison: Double;
begin
Base := EpsilonTestValues.BaseValue;
Comparison := FComparisonValue;
CheckTrue(Base = Comparison, 'Should be equal at Double precision');
end;
procedure TestEpsilonTestValues.CheckBaseIsSameValueAsDouble;
var
Base: Double;
Comparison: Double;
begin
Base := EpsilonTestValues.BaseValue;
Comparison := FComparisonValue;
CheckTrue(SameValue(Base, Comparison), 'Should be SameValue at Double precision');
end;
procedure TestEpsilonTestValues.CheckBaseIsSameValueAsExtended;
begin
CheckTrue(SameValue(EpsilonTestValues.BaseValue, FComparisonValue),
'Should be SameValue at Extended precision');
end;
procedure TestEpsilonTestValues.CheckBaseNotEqualAsDouble;
var
Base: Double;
Comparison: Double;
begin
Base := EpsilonTestValues.BaseValue;
Comparison := FComparisonValue;
CheckFalse(Base = Comparison, 'Should not be equal at Double precision');
end;
procedure TestEpsilonTestValues.CheckBaseNotEqualAsExtended;
begin
CheckFalse(EpsilonTestValues.BaseValue = FComparisonValue,
'Should not be equal at Extended precision');
end;
procedure TestEpsilonTestValues.CheckBaseNotSameValueAsDouble;
var
Base: Double;
Comparison: Double;
begin
Base := EpsilonTestValues.BaseValue;
Comparison := FComparisonValue;
CheckFalse(SameValue(Base, Comparison), 'Should not be SameValue at Double precision');
end;
procedure TestEpsilonTestValues.CheckBaseNotSameValueAsExtended;
begin
CheckFalse(SameValue(EpsilonTestValues.BaseValue, FComparisonValue),
'Should not be SameValue at Extended precision');
end;
procedure TestEpsilonTestValues.TestBarelyDifferent;
begin
FComparisonValue := EpsilonTestValues.BarelyDifferent;
CheckBaseIsEqualAsDouble;
CheckBaseNotEqualAsExtended;
CheckBaseIsSameValueAsDouble;
CheckBaseIsSameValueAsExtended;
end;
procedure TestEpsilonTestValues.TestDifferentAtDefaultEpsilon;
begin
FComparisonValue := EpsilonTestValues.DifferentAtDefaultEpsilon;
CheckBaseNotEqualAsDouble;
CheckBaseNotSameValueAsDouble;
end;
procedure TestEpsilonTestValues.TestSameAtDefaultEpsilon;
begin
FComparisonValue := EpsilonTestValues.SameAtDefaultEpsilon;
CheckBaseNotEqualAsDouble;
CheckBaseIsSameValueAsDouble;
CheckBaseNotSameValueAsExtended;
end;
initialization
TestEpsilonTestValues.Register;
end.