-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRangChecker.dpr
183 lines (151 loc) · 6.48 KB
/
RangChecker.dpr
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
program RangChecker;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Types,
DateUtils,
System.Generics.Defaults,
API.Utils in 'API\API.Utils.pas',
API.Objects.Comparer in 'API\API.Objects.Comparer.pas';
var
gPoint1, gPoint2, gPoint3: TPoint;
gRec1, gRec2, gRec3: ICustomRecord;
gRecordComparer: IComparer<ICustomRecord>;
gProduct1, gProduct2, gProduct3: IProduct;
gProductComparer: IComparer<IProduct>;
gClient1, gClient2, gClient3: IClient;
gClientComparer: IComparer<IClient>;
gEndDateStr: string;
begin
gPoint1 := TPoint.Create(1, 2);
gPoint2 := TPoint.Create(0, 0);
gPoint3 := TPoint.Create(3, 4);
gRec1 := GetTCustomRecord('Low', 10);
gRec2 := GetTCustomRecord('Mid', 20);
gRec3 := GetTCustomRecord('High', 30);
gRecordComparer := TComparer<ICustomRecord>.Construct(CompareCustomRecord);
gProduct1 := GetTProduct(1, 10.0);
gProduct2 := GetTProduct(2, 20.0);
gProduct3 := GetTProduct(3, 30.0);
gProductComparer := TComparer<IProduct>.Construct(CompareProductByPrice);
gClient1 := GetTClient('Alice', 25);
gClient2 := GetTClient('Bob', 30);
gClient3 := GetTClient('Charlie', 35);
gClientComparer := TComparer<IClient>.Construct(CompareClientByAge);
with FormatSettings do begin
ShortDateFormat := 'DD MMMM YYYY';
CurrencyString := 'DA';
DecimalSeparator := ',';
ThousandSeparator := '.';
end;
gEndDateStr := DateToStr(Today +10, FormatSettings);
try
Writeln('-----------------<< Integer Tests >>--------------------------------');
{$REGION ' Integer Tests .. '}
if TRange<Integer>.IsIn(5, 1, 10) then
Writeln('5 is within the range [1, 10]')
else
Writeln('5 is outside the range [1, 10]');
if TRange<Integer>.IsIn(5, 6, 10) then
Writeln('5 is within the range [6, 10]')
else
Writeln('5 is outside the range [6, 10]');
{$ENDREGION}
Writeln('-----------------<< Int64 Tests >>--------------------------------');
{$REGION ' Int64 Tests .. '}
if TRange<Int64>.IsIn(5_000_000_000_000_000_001, 5_000_000_000_000_000_000, 5_000_000_000_000_000_010) then
Writeln('5_000_000_000_000_000_001 is within the range [5_000_000_000_000_000_000, 5_000_000_000_000_000_010]')
else
Writeln('5 is outside the range [5_000_000_000_000_000_000, 5_000_000_000_000_000_010]');
if TRange<Int64>.IsIn(5_000_000_000_000_000_000, 5_000_000_000_000_000_001, 5_000_000_000_000_000_010) then
Writeln('5_000_000_000_000_000_000 is within the range [5_000_000_000_000_000_001, 5_000_000_000_000_000_010]')
else
Writeln('5_000_000_000_000_000_000 is outside the range [5_000_000_000_000_000_001, 5_000_000_000_000_000_010]');
{$ENDREGION}
Writeln('-----------------<< Float Tests >>----------------------------------');
{$REGION ' Float Tests .. '}
if TRange<Double>.IsIn(7.5, 5.0, 10.0) then
Writeln('7.5 is within the range [5.0, 10.0]')
else
Writeln('7.5 is outside the range [5.0, 10.0]');
if TRange<Double>.IsIn(7.5, 7.6, 10.0) then
Writeln('7.5 is within the range [7.6, 10.0]')
else
Writeln('7.5 is outside the range [7.6, 10.0]');
{$ENDREGION}
Writeln('-----------------<< DateTime Tests >>------------------------------');
{$REGION ' DateTime Tests .. '}
if TRange<TDateTime>.IsIn(Today, Today, Today +10) then
Writeln('Today is within ['+Today.ToString+'] and ['+gEndDateStr+']')
else
Writeln('Today is outside ['+Today.ToString+'] and ['+gEndDateStr+']');
if TRange<TDateTime>.IsIn(Yesterday, Today, Today +10) then
Writeln('Yesterday is within ['+Today.ToString+'] and ['+gEndDateStr+']')
else
Writeln('Yesterday is outside ['+Today.ToString+'] and ['+gEndDateStr+']');
{$ENDREGION}
Writeln('-----------------<< String Tests >>--------------------------------');
{$REGION ' String Tests .. '}
if TRange<string>.IsIn('hello', 'alpha', 'zulu') then
Writeln('"hello" is within the range [alpha, zulu]')
else
Writeln('"hello" is outside the range [alpha, zulu]');
if TRange<string>.IsIn('zulu', 'alpha', 'omega') then
Writeln('"zulu" is within the range [alpha, omega]')
else
Writeln('"zulu" is outside the range [alpha, omega]');
{$ENDREGION}
Writeln('-----------------<< TPoint Tests >>-----------------------------');
{$REGION ' TPoint Tests .. '}
if TRange<TPoint>.IsIn(gPoint1, gPoint2, gPoint3, PointComparer) then
Writeln('Point(1, 2) is within the range [Point(0, 0), Point(3, 4)]')
else
Writeln('Point(1, 2) is outside the range [Point(0, 0), Point(3, 4)]');
if TRange<TPoint>.IsIn(Point(5, 5), Point(0, 0), Point(3, 4), PointComparer) then
Writeln('Point(5, 5) is within the range [Point(0, 0), Point(3, 4)]')
else
Writeln('Point(5, 5) is outside the range [Point(0, 0), Point(3, 4)]');
{$ENDREGION}
Writeln('-----------------<< TCustomRecord Tests >>-----------------------------');
{$REGION ' TCustomRecord Tests .. '}
if TRange<ICustomRecord>.IsIn(gRec2, gRec1, gRec3, gRecordComparer) then
Writeln('Record is within the range')
else
Writeln('Record is outside the range');
gRec2.New.Edit('Mid', 40);
if TRange<ICustomRecord>.IsIn(gRec2, gRec1, gRec3, gRecordComparer) then
Writeln('Record is within the range')
else
Writeln('Record is outside the range');
{$ENDREGION}
Writeln('-----------------<< TProduct Tests >>-----------------------------');
{$REGION ' TProduct Tests .. '}
if TRange<IProduct>.IsIn(gProduct2, gProduct1, gProduct3, gProductComparer) then
Writeln('Product price is within the range')
else
Writeln('Product price is outside the range');
gProduct2.New.Edit(2, 40);
if TRange<IProduct>.IsIn(gProduct2, gProduct1, gProduct3, gProductComparer) then
Writeln('Product price is within the range')
else
Writeln('Product price is outside the range');
{$ENDREGION}
Writeln('-----------------<< TClient Tests >>-----------------------------');
{$REGION ' TClient Tests .. '}
if TRange<IClient>.IsIn(gClient2, gClient1, gClient3, gClientComparer) then
Writeln('Client age is within the range')
else
Writeln('Client age is outside the range');
gClient2.New.Edit('Bob', 40);
if TRange<IClient>.IsIn(gClient2, gClient1, gClient3, gClientComparer) then
Writeln('Client age is within the range')
else
Writeln('Client age is outside the range');
{$ENDREGION}
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.