@@ -12,14 +12,19 @@ TestTArrayUtils = class(TTestCase)
12
12
fSA0: TArray<string>;
13
13
fSA1: TArray<string>;
14
14
fSA2: TArray<string>;
15
+ fSA2R: TArray<string>;
15
16
fSAM: TArray<string>;
16
17
fSAN: TArray<string>;
18
+ fSAR: TArray<string>;
17
19
fIA0: TArray<Integer>;
18
20
fIA1: TArray<Integer>;
19
21
fIA2: TArray<Integer>;
22
+ fIA3: TArray<Integer>;
23
+ fIA3R: TArray<Integer>;
20
24
fIAM: TArray<Integer>;
21
25
fIAN: TArray<Integer>;
22
26
fIAP: TArray<Integer>;
27
+ fIAR: TArray<Integer>;
23
28
fIAX: TArray<Integer>;
24
29
fIAY: TArray<Integer>;
25
30
protected
@@ -30,12 +35,16 @@ TestTArrayUtils = class(TTestCase)
30
35
procedure TestLast ;
31
36
procedure TestIndexOf ;
32
37
procedure TestEqual ;
38
+ // TestReverse must come after TestEqual since the test calls TArrayUtils.Equal<T>
39
+ procedure TestReverse ;
33
40
procedure TestSameStart ;
34
41
end ;
35
42
36
43
TestArraysCatSnippets = class (TTestCase)
37
44
published
38
45
procedure TestByteArraysEqual ;
46
+ // The following test must come after TestByteArraysEqual since the test calls it
47
+ procedure TestReverseByteArray ;
39
48
end ;
40
49
41
50
implementation
@@ -54,13 +63,18 @@ procedure TestTArrayUtils.SetUp;
54
63
fSA0 := TArray<string>.Create();
55
64
fSA1 := TArray<string>.Create(' foo' );
56
65
fSA2 := TArray<string>.Create(' foo' , ' bar' );
66
+ fSA2R := TArray<string>.Create(' bar' , ' foo' );
57
67
fSAM := TArray<string>.Create(' a' , ' stitch' , ' in' , ' time' , ' saves' , ' nine' );
58
68
fSAN := TArray<string>.Create(' a' , ' stitch' , ' in' , ' time' , ' saves' , ' nine' );
69
+ fSAR := TArray<string>.Create(' nine' , ' saves' , ' time' , ' in' , ' stitch' , ' a' );
59
70
fIA0 := TArray<Integer>.Create();
60
71
fIA1 := TArray<Integer>.Create(42 );
61
72
fIA2 := TArray<Integer>.Create(42 , 56 );
73
+ fIA3 := TArray<Integer>.Create(56 , 42 , 102 );
74
+ fIA3R := TArray<Integer>.Create(102 , 42 , 56 );
62
75
fIAM := TArray<Integer>.Create(1 , 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 );
63
76
fIAN := TArray<Integer>.Create(1 , 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 );
77
+ fIAR := TArray<Integer>.Create(37 , 31 , 29 , 23 , 19 , 17 , 13 , 11 , 7 , 5 , 3 , 2 , 1 );
64
78
fIAP := TArray<Integer>.Create(1 , 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 );
65
79
fIAX := TArray<Integer>.Create(1 , 2 , 3 , 5 , 4 , 11 , 13 , 17 , 19 , 23 , 29 , 31 );
66
80
fIAY := TArray<Integer>.Create(0 , 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 );
@@ -153,6 +167,25 @@ procedure TestTArrayUtils.TestLast;
153
167
CheckEquals(37 , TArrayUtils.Last<Integer>(fIAN), ' Test 6' );
154
168
end ;
155
169
170
+ procedure TestTArrayUtils.TestReverse ;
171
+ var
172
+ RS: TArray<string>;
173
+ RI: TArray<Integer>;
174
+ begin
175
+ RS := TArrayUtils.Reverse<string>(fSAM);
176
+ CheckTrue(TArrayUtils.Equal<string>(fSAR, RS, StringCompareFn), ' Test 1' );
177
+ RI := TArrayUtils.Reverse<Integer>(fIAM);
178
+ CheckTrue(TArrayUtils.Equal<Integer>(fIAR, RI, IntegerCompareFn), ' Test 2' );
179
+ RS := TArrayUtils.Reverse<string>(fSA2);
180
+ CheckTrue(TArrayUtils.Equal<string>(fSA2R, RS, StringCompareFn), ' Test 3' );
181
+ RI := TArrayUtils.Reverse<Integer>(fIA0);
182
+ CheckTrue(TArrayUtils.Equal<Integer>(fIA0, RI, IntegerCompareFn), ' Test 4' );
183
+ RI := TArrayUtils.Reverse<Integer>(fIA1);
184
+ CheckTrue(TArrayUtils.Equal<Integer>(fIA1, RI, IntegerCompareFn), ' Test 5' );
185
+ RI := TArrayUtils.Reverse<Integer>(fIA3);
186
+ CheckTrue(TArrayUtils.Equal<Integer>(fIA3R, RI, IntegerCompareFn), ' Test 6' );
187
+ end ;
188
+
156
189
procedure TestTArrayUtils.TestSameStart ;
157
190
begin
158
191
CheckTrue(
@@ -233,6 +266,32 @@ procedure TestArraysCatSnippets.TestByteArraysEqual;
233
266
CheckFalse(ByteArraysEqual(A0L, A1L), ' #10' );
234
267
end ;
235
268
269
+ procedure TestArraysCatSnippets.TestReverseByteArray ;
270
+ var
271
+ A0, A1, A2, A6, A7, A4Sym, A5Sym: TBytes;
272
+ R0, R1, R2, R6, R7: TBytes;
273
+ begin
274
+ SetLength(A0, 0 );
275
+ SetLength(R0, 0 );
276
+ A1 := TBytes.Create(42 );
277
+ R1 := TBytes.Create(42 );
278
+ A2 := TBytes.Create(42 ,56 );
279
+ R2 := TBytes.Create(56 ,42 );
280
+ A6 := TBytes.Create(1 , 1 , 2 , 3 , 5 , 8 );
281
+ R6 := TBytes.Create(8 , 5 , 3 , 2 , 1 , 1 );
282
+ A7 := TBytes.Create(0 , 1 , 1 , 2 , 3 , 5 , 8 );
283
+ R7 := TBytes.Create(8 , 5 , 3 , 2 , 1 , 1 , 0 );
284
+ A4Sym := TBytes.Create(3 , 5 , 5 , 3 );
285
+ A5Sym := TBytes.Create(3 , 5 , 8 , 5 , 3 );
286
+ CheckTrue(ByteArraysEqual(R0, ReverseByteArray(A0)), ' #0' );
287
+ CheckTrue(ByteArraysEqual(R1, ReverseByteArray(A1)), ' #1' );
288
+ CheckTrue(ByteArraysEqual(R2, ReverseByteArray(A2)), ' #2' );
289
+ CheckTrue(ByteArraysEqual(R6, ReverseByteArray(A6)), ' #6' );
290
+ CheckTrue(ByteArraysEqual(R7, ReverseByteArray(A7)), ' #7' );
291
+ CheckTrue(ByteArraysEqual(A4Sym, ReverseByteArray(A4Sym)), ' #4 sym' );
292
+ CheckTrue(ByteArraysEqual(A5Sym, ReverseByteArray(A5Sym)), ' #5 sym' );
293
+ end ;
294
+
236
295
initialization
237
296
238
297
IntegerCompareFn := function (const Left, Right: Integer): Boolean
0 commit comments