1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using C5;
|
24
|
using NUnit.Framework;
|
25
|
using SCG = System.Collections.Generic;
|
26
|
|
27
|
namespace C5UnitTests.arrays.list
|
28
|
{
|
29
|
using CollectionOfInt = ArrayList<int>;
|
30
|
|
31
|
[TestFixture]
|
32
|
public class GenericTesters
|
33
|
{
|
34
|
[Test]
|
35
|
public void TestEvents()
|
36
|
{
|
37
|
Fun<CollectionOfInt> factory = delegate() { return new CollectionOfInt(TenEqualityComparer.Default); };
|
38
|
new C5UnitTests.Templates.Events.ListTester<CollectionOfInt>().Test(factory);
|
39
|
new C5UnitTests.Templates.Events.QueueTester<CollectionOfInt>().Test(factory);
|
40
|
new C5UnitTests.Templates.Events.StackTester<CollectionOfInt>().Test(factory);
|
41
|
}
|
42
|
|
43
|
[Test]
|
44
|
public void Extensible()
|
45
|
{
|
46
|
C5UnitTests.Templates.Extensible.Clone.Tester<CollectionOfInt>();
|
47
|
C5UnitTests.Templates.Extensible.Clone.ViewTester<CollectionOfInt>();
|
48
|
C5UnitTests.Templates.Extensible.Serialization.Tester<CollectionOfInt>();
|
49
|
C5UnitTests.Templates.Extensible.Serialization.ViewTester<CollectionOfInt>();
|
50
|
}
|
51
|
|
52
|
[Test]
|
53
|
public void List()
|
54
|
{
|
55
|
C5UnitTests.Templates.List.Dispose.Tester<CollectionOfInt>();
|
56
|
C5UnitTests.Templates.List.SCG_IList.Tester<CollectionOfInt>();
|
57
|
}
|
58
|
}
|
59
|
|
60
|
static class Factory
|
61
|
{
|
62
|
public static ICollection<T> New<T>() { return new ArrayList<T>(); }
|
63
|
}
|
64
|
|
65
|
namespace Events
|
66
|
{
|
67
|
[TestFixture]
|
68
|
public class IList_
|
69
|
{
|
70
|
private ArrayList<int> list;
|
71
|
CollectionEventList<int> seen;
|
72
|
|
73
|
[SetUp]
|
74
|
public void Init()
|
75
|
{
|
76
|
list = new ArrayList<int>(TenEqualityComparer.Default);
|
77
|
seen = new CollectionEventList<int>(IntEqualityComparer.Default);
|
78
|
}
|
79
|
|
80
|
private void listen() { seen.Listen(list, EventTypeEnum.Added); }
|
81
|
|
82
|
[Test]
|
83
|
public void Listenable()
|
84
|
{
|
85
|
Assert.AreEqual(EventTypeEnum.All, list.ListenableEvents);
|
86
|
Assert.AreEqual(EventTypeEnum.None, list.ActiveEvents);
|
87
|
listen();
|
88
|
Assert.AreEqual(EventTypeEnum.Added, list.ActiveEvents);
|
89
|
}
|
90
|
|
91
|
[Test]
|
92
|
public void SetThis()
|
93
|
{
|
94
|
list.Add(4); list.Add(56); list.Add(8);
|
95
|
listen();
|
96
|
list[1] = 45;
|
97
|
seen.Check(new CollectionEvent<int>[] {
|
98
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
|
99
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
|
100
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
|
101
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
|
102
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
103
|
});
|
104
|
}
|
105
|
|
106
|
[Test]
|
107
|
public void Insert()
|
108
|
{
|
109
|
list.Add(4); list.Add(56); list.Add(8);
|
110
|
listen();
|
111
|
list.Insert(1, 45);
|
112
|
seen.Check(new CollectionEvent<int>[] {
|
113
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
|
114
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
|
115
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
116
|
});
|
117
|
}
|
118
|
|
119
|
[Test]
|
120
|
public void InsertAll()
|
121
|
{
|
122
|
list.Add(4); list.Add(56); list.Add(8);
|
123
|
listen();
|
124
|
list.InsertAll<int>(1, new int[] { 666, 777, 888 });
|
125
|
//seen.Print(Console.Error);
|
126
|
seen.Check(new CollectionEvent<int>[] {
|
127
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(666,1), list),
|
128
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(666, 1), list),
|
129
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(777,2), list),
|
130
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(777, 1), list),
|
131
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(888,3), list),
|
132
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(888, 1), list),
|
133
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
134
|
});
|
135
|
list.InsertAll<int>(1, new int[] {});
|
136
|
seen.Check(new CollectionEvent<int>[] {});
|
137
|
}
|
138
|
|
139
|
[Test]
|
140
|
public void InsertFirstLast()
|
141
|
{
|
142
|
list.Add(4); list.Add(56); list.Add(8);
|
143
|
listen();
|
144
|
list.InsertFirst(45);
|
145
|
seen.Check(new CollectionEvent<int>[] {
|
146
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,0), list),
|
147
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
|
148
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
149
|
});
|
150
|
list.InsertLast(88);
|
151
|
seen.Check(new CollectionEvent<int>[] {
|
152
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(88,4), list),
|
153
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(88, 1), list),
|
154
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
155
|
});
|
156
|
}
|
157
|
|
158
|
[Test]
|
159
|
public void Remove()
|
160
|
{
|
161
|
list.Add(4); list.Add(56); list.Add(8);
|
162
|
listen();
|
163
|
list.Remove();
|
164
|
seen.Check(new CollectionEvent<int>[] {
|
165
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
|
166
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
167
|
}
|
168
|
|
169
|
[Test]
|
170
|
public void RemoveFirst()
|
171
|
{
|
172
|
list.Add(4); list.Add(56); list.Add(8);
|
173
|
listen();
|
174
|
list.RemoveFirst();
|
175
|
seen.Check(new CollectionEvent<int>[] {
|
176
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(4,0), list),
|
177
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), list),
|
178
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
179
|
}
|
180
|
|
181
|
[Test]
|
182
|
public void RemoveLast()
|
183
|
{
|
184
|
list.Add(4); list.Add(56); list.Add(8);
|
185
|
listen();
|
186
|
list.RemoveLast();
|
187
|
seen.Check(new CollectionEvent<int>[] {
|
188
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(8,2), list),
|
189
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
|
190
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
191
|
}
|
192
|
|
193
|
[Test]
|
194
|
public void Reverse()
|
195
|
{
|
196
|
list.Add(4); list.Add(56); list.Add(8);
|
197
|
listen();
|
198
|
list.Reverse();
|
199
|
seen.Check(new CollectionEvent<int>[] {
|
200
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
201
|
});
|
202
|
list.View(1, 0).Reverse();
|
203
|
seen.Check(new CollectionEvent<int>[] {});
|
204
|
}
|
205
|
|
206
|
|
207
|
[Test]
|
208
|
public void Sort()
|
209
|
{
|
210
|
list.Add(4); list.Add(56); list.Add(8);
|
211
|
listen();
|
212
|
list.Sort();
|
213
|
seen.Check(new CollectionEvent<int>[] {
|
214
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
215
|
});
|
216
|
list.View(1, 0).Sort();
|
217
|
seen.Check(new CollectionEvent<int>[] {});
|
218
|
}
|
219
|
|
220
|
[Test]
|
221
|
public void Shuffle()
|
222
|
{
|
223
|
list.Add(4); list.Add(56); list.Add(8);
|
224
|
listen();
|
225
|
list.Shuffle();
|
226
|
seen.Check(new CollectionEvent<int>[] {
|
227
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
228
|
});
|
229
|
list.View(1, 0).Shuffle();
|
230
|
seen.Check(new CollectionEvent<int>[] {});
|
231
|
}
|
232
|
|
233
|
[Test]
|
234
|
public void RemoveAt()
|
235
|
{
|
236
|
list.Add(4); list.Add(56); list.Add(8);
|
237
|
listen();
|
238
|
list.RemoveAt(1);
|
239
|
seen.Check(new CollectionEvent<int>[] {
|
240
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
|
241
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
|
242
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
243
|
}
|
244
|
|
245
|
[Test]
|
246
|
public void RemoveInterval()
|
247
|
{
|
248
|
list.Add(4); list.Add(56); list.Add(8);
|
249
|
listen();
|
250
|
list.RemoveInterval(1, 2);
|
251
|
seen.Check(new CollectionEvent<int>[] {
|
252
|
new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,2,1), list),
|
253
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
254
|
});
|
255
|
list.RemoveInterval(1, 0);
|
256
|
seen.Check(new CollectionEvent<int>[] {});
|
257
|
}
|
258
|
|
259
|
[Test]
|
260
|
public void Update()
|
261
|
{
|
262
|
list.Add(4); list.Add(56); list.Add(8);
|
263
|
listen();
|
264
|
list.Update(53);
|
265
|
seen.Check(new CollectionEvent<int>[] {
|
266
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
|
267
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
|
268
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
269
|
});
|
270
|
list.Update(67);
|
271
|
seen.Check(new CollectionEvent<int>[] {});
|
272
|
}
|
273
|
|
274
|
[Test]
|
275
|
public void FindOrAdd()
|
276
|
{
|
277
|
list.Add(4); list.Add(56); list.Add(8);
|
278
|
listen();
|
279
|
int val = 53;
|
280
|
list.FindOrAdd(ref val);
|
281
|
seen.Check(new CollectionEvent<int>[] {});
|
282
|
val = 67;
|
283
|
list.FindOrAdd(ref val);
|
284
|
seen.Check(new CollectionEvent<int>[] {
|
285
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
|
286
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
287
|
});
|
288
|
}
|
289
|
|
290
|
[Test]
|
291
|
public void UpdateOrAdd()
|
292
|
{
|
293
|
list.Add(4); list.Add(56); list.Add(8);
|
294
|
listen();
|
295
|
int val = 53;
|
296
|
list.UpdateOrAdd(val);
|
297
|
seen.Check(new CollectionEvent<int>[] {
|
298
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
|
299
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
|
300
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
301
|
});
|
302
|
val = 67;
|
303
|
list.UpdateOrAdd(val);
|
304
|
seen.Check(new CollectionEvent<int>[] {
|
305
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
|
306
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
307
|
});
|
308
|
list.UpdateOrAdd(51, out val);
|
309
|
seen.Check(new CollectionEvent<int>[] {
|
310
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(53, 1), list),
|
311
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(51, 1), list),
|
312
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
313
|
});
|
314
|
val = 67;
|
315
|
list.UpdateOrAdd(81, out val);
|
316
|
seen.Check(new CollectionEvent<int>[] {
|
317
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(81, 1), list),
|
318
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
319
|
});
|
320
|
}
|
321
|
|
322
|
[Test]
|
323
|
public void RemoveItem()
|
324
|
{
|
325
|
list.Add(4); list.Add(56); list.Add(18);
|
326
|
listen();
|
327
|
list.Remove(53);
|
328
|
seen.Check(new CollectionEvent<int>[] {
|
329
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
|
330
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
331
|
list.Remove(11);
|
332
|
seen.Check(new CollectionEvent<int>[] {
|
333
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), list),
|
334
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
335
|
}
|
336
|
|
337
|
[Test]
|
338
|
public void RemoveAll()
|
339
|
{
|
340
|
for (int i = 0; i < 10; i++)
|
341
|
{
|
342
|
list.Add(10 * i + 5);
|
343
|
}
|
344
|
listen();
|
345
|
list.RemoveAll<int>(new int[] { 32, 187, 45 });
|
346
|
//TODO: the order depends on internals of the HashSet
|
347
|
seen.Check(new CollectionEvent<int>[] {
|
348
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(35, 1), list),
|
349
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(45, 1), list),
|
350
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
351
|
list.RemoveAll<int>(new int[] { 200, 300 });
|
352
|
seen.Check(new CollectionEvent<int>[] {});
|
353
|
}
|
354
|
|
355
|
[Test]
|
356
|
public void Clear()
|
357
|
{
|
358
|
list.Add(4); list.Add(56); list.Add(8);
|
359
|
listen();
|
360
|
list.View(1, 1).Clear();
|
361
|
seen.Check(new CollectionEvent<int>[] {
|
362
|
new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,1,1), list),
|
363
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
364
|
});
|
365
|
list.Clear();
|
366
|
seen.Check(new CollectionEvent<int>[] {
|
367
|
new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,2,0), list),
|
368
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
369
|
});
|
370
|
list.Clear();
|
371
|
seen.Check(new CollectionEvent<int>[] {});
|
372
|
}
|
373
|
|
374
|
[Test]
|
375
|
public void ListDispose()
|
376
|
{
|
377
|
list.Add(4); list.Add(56); list.Add(8);
|
378
|
listen();
|
379
|
list.View(1, 1).Dispose();
|
380
|
seen.Check(new CollectionEvent<int>[] {});
|
381
|
list.Dispose();
|
382
|
seen.Check(new CollectionEvent<int>[] {
|
383
|
new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,3,0), list),
|
384
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
|
385
|
});
|
386
|
list.Dispose();
|
387
|
seen.Check(new CollectionEvent<int>[] {});
|
388
|
}
|
389
|
|
390
|
|
391
|
[Test]
|
392
|
public void RetainAll()
|
393
|
{
|
394
|
for (int i = 0; i < 10; i++)
|
395
|
{
|
396
|
list.Add(10 * i + 5);
|
397
|
}
|
398
|
listen();
|
399
|
list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
|
400
|
seen.Check(new CollectionEvent<int>[] {
|
401
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), list),
|
402
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), list),
|
403
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(55, 1), list),
|
404
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), list),
|
405
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
406
|
list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
|
407
|
seen.Check(new CollectionEvent<int>[] {});
|
408
|
}
|
409
|
|
410
|
[Test]
|
411
|
public void RemoveAllCopies()
|
412
|
{
|
413
|
for (int i = 0; i < 10; i++)
|
414
|
{
|
415
|
list.Add(3 * i + 5);
|
416
|
}
|
417
|
listen();
|
418
|
list.RemoveAllCopies(14);
|
419
|
seen.Check(new CollectionEvent<int>[] {
|
420
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), list),
|
421
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(14, 1), list),
|
422
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(17, 1), list),
|
423
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
424
|
list.RemoveAllCopies(14);
|
425
|
seen.Check(new CollectionEvent<int>[] {});
|
426
|
}
|
427
|
|
428
|
[Test]
|
429
|
public void Add()
|
430
|
{
|
431
|
listen();
|
432
|
seen.Check(new CollectionEvent<int>[0]);
|
433
|
list.Add(23);
|
434
|
seen.Check(new CollectionEvent<int>[] {
|
435
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
|
436
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
437
|
}
|
438
|
|
439
|
[Test]
|
440
|
public void AddAll()
|
441
|
{
|
442
|
for (int i = 0; i < 10; i++)
|
443
|
{
|
444
|
list.Add(10 * i + 5);
|
445
|
}
|
446
|
listen();
|
447
|
list.AddAll<int>(new int[] { 45, 56, 67 });
|
448
|
seen.Check(new CollectionEvent<int>[] {
|
449
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
|
450
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), list),
|
451
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
|
452
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
453
|
list.AddAll<int>(new int[] { });
|
454
|
seen.Check(new CollectionEvent<int>[] {});
|
455
|
}
|
456
|
|
457
|
[TearDown]
|
458
|
public void Dispose() { list = null; seen = null; }
|
459
|
|
460
|
[Test]
|
461
|
[ExpectedException(typeof(UnlistenableEventException))]
|
462
|
public void ViewChanged()
|
463
|
{
|
464
|
IList<int> w = list.View(0, 0);
|
465
|
w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
|
466
|
}
|
467
|
|
468
|
[Test]
|
469
|
[ExpectedException(typeof(UnlistenableEventException))]
|
470
|
public void ViewCleared()
|
471
|
{
|
472
|
IList<int> w = list.View(0, 0);
|
473
|
w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
|
474
|
}
|
475
|
|
476
|
[Test]
|
477
|
[ExpectedException(typeof(UnlistenableEventException))]
|
478
|
public void ViewAdded()
|
479
|
{
|
480
|
IList<int> w = list.View(0, 0);
|
481
|
w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
|
482
|
}
|
483
|
|
484
|
[Test]
|
485
|
[ExpectedException(typeof(UnlistenableEventException))]
|
486
|
public void ViewInserted()
|
487
|
{
|
488
|
IList<int> w = list.View(0, 0);
|
489
|
w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
|
490
|
}
|
491
|
|
492
|
[Test]
|
493
|
[ExpectedException(typeof(UnlistenableEventException))]
|
494
|
public void ViewRemoved()
|
495
|
{
|
496
|
IList<int> w = list.View(0, 0);
|
497
|
w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
|
498
|
}
|
499
|
|
500
|
[Test]
|
501
|
[ExpectedException(typeof(UnlistenableEventException))]
|
502
|
public void ViewRemovedAt()
|
503
|
{
|
504
|
IList<int> w = list.View(0, 0);
|
505
|
w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
|
506
|
}
|
507
|
|
508
|
void w_CollectionChanged(object sender)
|
509
|
{
|
510
|
throw new NotImplementedException();
|
511
|
}
|
512
|
|
513
|
void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
|
514
|
{
|
515
|
throw new NotImplementedException();
|
516
|
}
|
517
|
|
518
|
void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
|
519
|
{
|
520
|
throw new NotImplementedException();
|
521
|
}
|
522
|
|
523
|
void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
|
524
|
{
|
525
|
throw new NotImplementedException();
|
526
|
}
|
527
|
|
528
|
void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
|
529
|
{
|
530
|
throw new NotImplementedException();
|
531
|
}
|
532
|
|
533
|
void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
|
534
|
{
|
535
|
throw new NotImplementedException();
|
536
|
}
|
537
|
}
|
538
|
|
539
|
[TestFixture]
|
540
|
public class StackQueue
|
541
|
{
|
542
|
|
543
|
private ArrayList<int> list;
|
544
|
CollectionEventList<int> seen;
|
545
|
|
546
|
[SetUp]
|
547
|
public void Init()
|
548
|
{
|
549
|
list = new ArrayList<int>(TenEqualityComparer.Default);
|
550
|
seen = new CollectionEventList<int>(IntEqualityComparer.Default);
|
551
|
}
|
552
|
|
553
|
private void listen() { seen.Listen(list, EventTypeEnum.All); }
|
554
|
|
555
|
[Test]
|
556
|
public void EnqueueDequeue()
|
557
|
{
|
558
|
listen();
|
559
|
list.Enqueue(67);
|
560
|
seen.Check(new CollectionEvent<int>[] {
|
561
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(67,0), list),
|
562
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
|
563
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
564
|
list.Enqueue(2);
|
565
|
seen.Check(new CollectionEvent<int>[] {
|
566
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(2,1), list),
|
567
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), list),
|
568
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
569
|
list.Dequeue();
|
570
|
seen.Check(new CollectionEvent<int>[] {
|
571
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(67,0), list),
|
572
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(67, 1), list),
|
573
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
574
|
list.Dequeue();
|
575
|
seen.Check(new CollectionEvent<int>[] {
|
576
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(2,0), list),
|
577
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(2, 1), list),
|
578
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
579
|
}
|
580
|
|
581
|
[Test]
|
582
|
public void PushPop()
|
583
|
{
|
584
|
listen();
|
585
|
seen.Check(new CollectionEvent<int>[0]);
|
586
|
list.Push(23);
|
587
|
seen.Check(new CollectionEvent<int>[] {
|
588
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(23,0), list),
|
589
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
|
590
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
591
|
list.Push(-12);
|
592
|
seen.Check(new CollectionEvent<int>[] {
|
593
|
new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(-12,1), list),
|
594
|
new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(-12, 1), list),
|
595
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
596
|
list.Pop();
|
597
|
seen.Check(new CollectionEvent<int>[] {
|
598
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(-12,1), list),
|
599
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(-12, 1), list),
|
600
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
601
|
list.Pop();
|
602
|
seen.Check(new CollectionEvent<int>[] {
|
603
|
new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(23,0), list),
|
604
|
new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(23, 1), list),
|
605
|
new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
|
606
|
}
|
607
|
|
608
|
[TearDown]
|
609
|
public void Dispose() { list = null; seen = null; }
|
610
|
}
|
611
|
}
|
612
|
|
613
|
namespace Safety
|
614
|
{
|
615
|
/// <summary>
|
616
|
/// Tests to see if the collection classes are robust for enumerable arguments that throw exceptions.
|
617
|
/// </summary>
|
618
|
[TestFixture]
|
619
|
public class BadEnumerable
|
620
|
{
|
621
|
private ArrayList<int> list;
|
622
|
|
623
|
[SetUp]
|
624
|
public void Init()
|
625
|
{
|
626
|
list = new ArrayList<int>();
|
627
|
}
|
628
|
|
629
|
[Test]
|
630
|
public void InsertAll()
|
631
|
{
|
632
|
list.Add(4); list.Add(56); list.Add(8);
|
633
|
try
|
634
|
{
|
635
|
list.InsertAll<int>(1, new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
|
636
|
Assert.Fail("Should not get here");
|
637
|
}
|
638
|
catch (BadEnumerableException) { }
|
639
|
Assert.IsTrue(list.Check());
|
640
|
Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
|
641
|
|
642
|
}
|
643
|
|
644
|
[Test]
|
645
|
public void AddAll()
|
646
|
{
|
647
|
list.Add(4); list.Add(56); list.Add(8);
|
648
|
try
|
649
|
{
|
650
|
list.View(0, 1).AddAll<int>(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
|
651
|
Assert.Fail("Should not get here");
|
652
|
}
|
653
|
catch (BadEnumerableException) { }
|
654
|
Assert.IsTrue(list.Check());
|
655
|
Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
|
656
|
}
|
657
|
|
658
|
[Test]
|
659
|
public void RemoveAll()
|
660
|
{
|
661
|
list.Add(4); list.Add(56); list.Add(8);
|
662
|
try
|
663
|
{
|
664
|
list.RemoveAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
|
665
|
Assert.Fail("Should not get here");
|
666
|
}
|
667
|
catch (BadEnumerableException) { }
|
668
|
Assert.IsTrue(list.Check());
|
669
|
Assert.IsTrue(IC.eq(list, 4, 56, 8));
|
670
|
}
|
671
|
|
672
|
[Test]
|
673
|
public void RetainAll()
|
674
|
{
|
675
|
list.Add(4); list.Add(56); list.Add(8);
|
676
|
try
|
677
|
{
|
678
|
list.RetainAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
|
679
|
Assert.Fail("Should not get here");
|
680
|
}
|
681
|
catch (BadEnumerableException) { }
|
682
|
Assert.IsTrue(list.Check());
|
683
|
Assert.IsTrue(IC.eq(list, 4, 56, 8));
|
684
|
}
|
685
|
|
686
|
|
687
|
[Test]
|
688
|
public void ContainsAll()
|
689
|
{
|
690
|
list.Add(4); list.Add(56); list.Add(8);
|
691
|
try
|
692
|
{
|
693
|
list.ContainsAll(new BadEnumerable<int>(new BadEnumerableException(), 4, 18));
|
694
|
Assert.Fail("Should not get here");
|
695
|
}
|
696
|
catch (BadEnumerableException) { }
|
697
|
Assert.IsTrue(list.Check());
|
698
|
Assert.IsTrue(IC.eq(list, 4, 56, 8));
|
699
|
}
|
700
|
|
701
|
|
702
|
[TearDown]
|
703
|
public void Dispose() { list = null; }
|
704
|
}
|
705
|
|
706
|
/// <summary>
|
707
|
/// Tests to see if the collection classes are robust for delegate arguments that throw exceptions.
|
708
|
/// </summary>
|
709
|
[TestFixture]
|
710
|
public class BadFun
|
711
|
{
|
712
|
private ArrayList<int> list;
|
713
|
|
714
|
[SetUp]
|
715
|
public void Init()
|
716
|
{
|
717
|
list = new ArrayList<int>();
|
718
|
}
|
719
|
|
720
|
[Test]
|
721
|
public void NoTests() { }
|
722
|
|
723
|
[TearDown]
|
724
|
public void Dispose() { list = null; }
|
725
|
}
|
726
|
}
|
727
|
|
728
|
namespace Enumerable
|
729
|
{
|
730
|
[TestFixture]
|
731
|
public class Multiops
|
732
|
{
|
733
|
private ArrayList<int> list;
|
734
|
|
735
|
private Fun<int, bool> always, never, even;
|
736
|
|
737
|
|
738
|
[SetUp]
|
739
|
public void Init()
|
740
|
{
|
741
|
list = new ArrayList<int>();
|
742
|
always = delegate { return true; };
|
743
|
never = delegate { return false; };
|
744
|
even = delegate(int i) { return i % 2 == 0; };
|
745
|
}
|
746
|
|
747
|
|
748
|
[Test]
|
749
|
public void All()
|
750
|
{
|
751
|
Assert.IsTrue(list.All(always));
|
752
|
Assert.IsTrue(list.All(never));
|
753
|
Assert.IsTrue(list.All(even));
|
754
|
list.Add(8);
|
755
|
Assert.IsTrue(list.All(always));
|
756
|
Assert.IsFalse(list.All(never));
|
757
|
Assert.IsTrue(list.All(even));
|
758
|
list.Add(5);
|
759
|
Assert.IsTrue(list.All(always));
|
760
|
Assert.IsFalse(list.All(never));
|
761
|
Assert.IsFalse(list.All(even));
|
762
|
}
|
763
|
|
764
|
|
765
|
[Test]
|
766
|
public void Exists()
|
767
|
{
|
768
|
Assert.IsFalse(list.Exists(always));
|
769
|
Assert.IsFalse(list.Exists(never));
|
770
|
Assert.IsFalse(list.Exists(even));
|
771
|
list.Add(5);
|
772
|
Assert.IsTrue(list.Exists(always));
|
773
|
Assert.IsFalse(list.Exists(never));
|
774
|
Assert.IsFalse(list.Exists(even));
|
775
|
list.Add(8);
|
776
|
Assert.IsTrue(list.Exists(always));
|
777
|
Assert.IsFalse(list.Exists(never));
|
778
|
Assert.IsTrue(list.Exists(even));
|
779
|
}
|
780
|
|
781
|
|
782
|
[Test]
|
783
|
public void Apply()
|
784
|
{
|
785
|
int sum = 0;
|
786
|
Act<int> a = delegate(int i) { sum = i + 10 * sum; };
|
787
|
|
788
|
list.Apply(a);
|
789
|
Assert.AreEqual(0, sum);
|
790
|
sum = 0;
|
791
|
list.Add(5); list.Add(8); list.Add(7); list.Add(5);
|
792
|
list.Apply(a);
|
793
|
Assert.AreEqual(5875, sum);
|
794
|
}
|
795
|
|
796
|
|
797
|
[TearDown]
|
798
|
public void Dispose() { list = null; }
|
799
|
}
|
800
|
|
801
|
|
802
|
|
803
|
[TestFixture]
|
804
|
public class GetEnumerator
|
805
|
{
|
806
|
private ArrayList<int> list;
|
807
|
|
808
|
|
809
|
[SetUp]
|
810
|
public void Init() { list = new ArrayList<int>(); }
|
811
|
|
812
|
|
813
|
[Test]
|
814
|
public void Empty()
|
815
|
{
|
816
|
SCG.IEnumerator<int> e = list.GetEnumerator();
|
817
|
|
818
|
Assert.IsFalse(e.MoveNext());
|
819
|
}
|
820
|
|
821
|
|
822
|
[Test]
|
823
|
public void Normal()
|
824
|
{
|
825
|
list.Add(5);
|
826
|
list.Add(8);
|
827
|
list.Add(5);
|
828
|
list.Add(5);
|
829
|
list.Add(10);
|
830
|
list.Add(1);
|
831
|
|
832
|
SCG.IEnumerator<int> e = list.GetEnumerator();
|
833
|
|
834
|
Assert.IsTrue(e.MoveNext());
|
835
|
Assert.AreEqual(5, e.Current);
|
836
|
Assert.IsTrue(e.MoveNext());
|
837
|
Assert.AreEqual(8, e.Current);
|
838
|
Assert.IsTrue(e.MoveNext());
|
839
|
Assert.AreEqual(5, e.Current);
|
840
|
Assert.IsTrue(e.MoveNext());
|
841
|
Assert.AreEqual(5, e.Current);
|
842
|
Assert.IsTrue(e.MoveNext());
|
843
|
Assert.AreEqual(10, e.Current);
|
844
|
Assert.IsTrue(e.MoveNext());
|
845
|
Assert.AreEqual(1, e.Current);
|
846
|
Assert.IsFalse(e.MoveNext());
|
847
|
}
|
848
|
|
849
|
|
850
|
[Test]
|
851
|
public void DoDispose()
|
852
|
{
|
853
|
list.Add(5);
|
854
|
list.Add(8);
|
855
|
list.Add(5);
|
856
|
|
857
|
SCG.IEnumerator<int> e = list.GetEnumerator();
|
858
|
|
859
|
e.MoveNext();
|
860
|
e.MoveNext();
|
861
|
e.Dispose();
|
862
|
}
|
863
|
|
864
|
|
865
|
[Test]
|
866
|
[ExpectedException(typeof(CollectionModifiedException))]
|
867
|
public void MoveNextAfterUpdate()
|
868
|
{
|
869
|
list.Add(5);
|
870
|
list.Add(8);
|
871
|
list.Add(5);
|
872
|
|
873
|
SCG.IEnumerator<int> e = list.GetEnumerator();
|
874
|
|
875
|
e.MoveNext();
|
876
|
list.Add(99);
|
877
|
e.MoveNext();
|
878
|
}
|
879
|
|
880
|
[TearDown]
|
881
|
public void Dispose() { list = null; }
|
882
|
}
|
883
|
}
|
884
|
|
885
|
namespace CollectionOrSink
|
886
|
{
|
887
|
[TestFixture]
|
888
|
public class Formatting
|
889
|
{
|
890
|
ICollection<int> coll;
|
891
|
IFormatProvider rad16;
|
892
|
[SetUp]
|
893
|
public void Init() { coll = Factory.New<int>(); rad16 = new RadixFormatProvider(16); }
|
894
|
[TearDown]
|
895
|
public void Dispose() { coll = null; rad16 = null; }
|
896
|
[Test]
|
897
|
public void Format()
|
898
|
{
|
899
|
Assert.AreEqual("[ ]", coll.ToString());
|
900
|
coll.AddAll<int>(new int[] { -4, 28, 129, 65530 });
|
901
|
Assert.AreEqual("[ 0:-4, 1:28, 2:129, 3:65530 ]", coll.ToString());
|
902
|
Assert.AreEqual("[ 0:-4, 1:1C, 2:81, 3:FFFA ]", coll.ToString(null, rad16));
|
903
|
Assert.AreEqual("[ 0:-4, 1:28... ]", coll.ToString("L14", null));
|
904
|
Assert.AreEqual("[ 0:-4, 1:1C... ]", coll.ToString("L14", rad16));
|
905
|
}
|
906
|
}
|
907
|
|
908
|
[TestFixture]
|
909
|
public class CollectionOrSink
|
910
|
{
|
911
|
private ArrayList<int> list;
|
912
|
|
913
|
|
914
|
[SetUp]
|
915
|
public void Init() { list = new ArrayList<int>(); }
|
916
|
|
917
|
[Test]
|
918
|
public void Choose()
|
919
|
{
|
920
|
list.Add(7);
|
921
|
Assert.AreEqual(7, list.Choose());
|
922
|
}
|
923
|
|
924
|
[Test]
|
925
|
[ExpectedException(typeof(NoSuchItemException))]
|
926
|
public void BadChoose()
|
927
|
{
|
928
|
list.Choose();
|
929
|
}
|
930
|
|
931
|
[Test]
|
932
|
public void CountEtAl()
|
933
|
{
|
934
|
Assert.AreEqual(0, list.Count);
|
935
|
Assert.IsTrue(list.IsEmpty);
|
936
|
Assert.IsTrue(list.AllowsDuplicates);
|
937
|
list.Add(5);
|
938
|
Assert.AreEqual(1, list.Count);
|
939
|
Assert.IsFalse(list.IsEmpty);
|
940
|
list.Add(5);
|
941
|
Assert.AreEqual(2, list.Count);
|
942
|
Assert.IsFalse(list.IsEmpty);
|
943
|
list.Add(8);
|
944
|
Assert.AreEqual(3, list.Count);
|
945
|
}
|
946
|
|
947
|
|
948
|
[Test]
|
949
|
public void AddAll()
|
950
|
{
|
951
|
list.Add(3); list.Add(4); list.Add(5);
|
952
|
|
953
|
ArrayList<int> list2 = new ArrayList<int>();
|
954
|
|
955
|
list2.AddAll(list);
|
956
|
Assert.IsTrue(IC.eq(list2, 3, 4, 5));
|
957
|
list.AddAll(list2);
|
958
|
Assert.IsTrue(IC.eq(list2, 3, 4, 5));
|
959
|
Assert.IsTrue(IC.eq(list, 3, 4, 5, 3, 4, 5));
|
960
|
}
|
961
|
|
962
|
|
963
|
[TearDown]
|
964
|
public void Dispose() { list = null; }
|
965
|
}
|
966
|
|
967
|
[TestFixture]
|
968
|
public class FindPredicate
|
969
|
{
|
970
|
private ArrayList<int> list;
|
971
|
Fun<int, bool> pred;
|
972
|
|
973
|
[SetUp]
|
974
|
public void Init()
|
975
|
{
|
976
|
list = new ArrayList<int>(TenEqualityComparer.Default);
|
977
|
pred = delegate(int i) { return i % 5 == 0; };
|
978
|
}
|
979
|
|
980
|
[TearDown]
|
981
|
public void Dispose() { list = null; }
|
982
|
|
983
|
[Test]
|
984
|
public void Find()
|
985
|
{
|
986
|
int i;
|
987
|
Assert.IsFalse(list.Find(pred, out i));
|
988
|
list.AddAll<int>(new int[] { 4, 22, 67, 37 });
|
989
|
Assert.IsFalse(list.Find(pred, out i));
|
990
|
list.AddAll<int>(new int[] { 45, 122, 675, 137 });
|
991
|
Assert.IsTrue(list.Find(pred, out i));
|
992
|
Assert.AreEqual(45, i);
|
993
|
}
|
994
|
|
995
|
[Test]
|
996
|
public void FindLast()
|
997
|
{
|
998
|
int i;
|
999
|
Assert.IsFalse(list.FindLast(pred, out i));
|
1000
|
list.AddAll<int>(new int[] { 4, 22, 67, 37 });
|
1001
|
Assert.IsFalse(list.FindLast(pred, out i));
|
1002
|
list.AddAll<int>(new int[] { 45, 122, 675, 137 });
|
1003
|
Assert.IsTrue(list.FindLast(pred, out i));
|
1004
|
Assert.AreEqual(675, i);
|
1005
|
}
|
1006
|
|
1007
|
[Test]
|
1008
|
public void FindIndex()
|
1009
|
{
|
1010
|
Assert.IsFalse(0 <= list.FindIndex(pred));
|
1011
|
list.AddAll<int>(new int[] { 4, 22, 67, 37 });
|
1012
|
Assert.IsFalse(0 <= list.FindIndex(pred));
|
1013
|
list.AddAll<int>(new int[] { 45, 122, 675, 137 });
|
1014
|
Assert.AreEqual(4, list.FindIndex(pred));
|
1015
|
}
|
1016
|
|
1017
|
[Test]
|
1018
|
public void FindLastIndex()
|
1019
|
{
|
1020
|
Assert.IsFalse(0 <= list.FindLastIndex(pred));
|
1021
|
list.AddAll<int>(new int[] { 4, 22, 67, 37 });
|
1022
|
Assert.IsFalse(0 <= list.FindLastIndex(pred));
|
1023
|
list.AddAll<int>(new int[] { 45, 122, 675, 137 });
|
1024
|
Assert.AreEqual(6, list.FindLastIndex(pred));
|
1025
|
}
|
1026
|
}
|
1027
|
|
1028
|
[TestFixture]
|
1029
|
public class UniqueItems
|
1030
|
{
|
1031
|
private ArrayList<int> list;
|
1032
|
|
1033
|
[SetUp]
|
1034
|
public void Init() { list = new ArrayList<int>(); }
|
1035
|
|
1036
|
[TearDown]
|
1037
|
public void Dispose() { list = null; }
|
1038
|
|
1039
|
[Test]
|
1040
|
public void Test()
|
1041
|
{
|
1042
|
Assert.IsTrue(IC.seteq(list.UniqueItems()));
|
1043
|
Assert.IsTrue(IC.seteq(list.ItemMultiplicities()));
|
1044
|
list.AddAll<int>(new int[] { 7, 9, 7 });
|
1045
|
Assert.IsTrue(IC.seteq(list.UniqueItems(), 7, 9));
|
1046
|
Assert.IsTrue(IC.seteq(list.ItemMultiplicities(), 7, 2, 9, 1));
|
1047
|
}
|
1048
|
}
|
1049
|
|
1050
|
[TestFixture]
|
1051
|
public class ArrayTest
|
1052
|
{
|
1053
|
private ArrayList<int> list;
|
1054
|
|
1055
|
int[] a;
|
1056
|
|
1057
|
|
1058
|
[SetUp]
|
1059
|
public void Init()
|
1060
|
{
|
1061
|
list = new ArrayList<int>();
|
1062
|
a = new int[10];
|
1063
|
for (int i = 0; i < 10; i++)
|
1064
|
a[i] = 1000 + i;
|
1065
|
}
|
1066
|
|
1067
|
|
1068
|
[TearDown]
|
1069
|
public void Dispose() { list = null; }
|
1070
|
|
1071
|
|
1072
|
private string aeq(int[] a, params int[] b)
|
1073
|
{
|
1074
|
if (a.Length != b.Length)
|
1075
|
return "Lengths differ: " + a.Length + " != " + b.Length;
|
1076
|
|
1077
|
for (int i = 0; i < a.Length; i++)
|
1078
|
if (a[i] != b[i])
|
1079
|
return String.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]);
|
1080
|
|
1081
|
return "Alles klar";
|
1082
|
}
|
1083
|
|
1084
|
|
1085
|
[Test]
|
1086
|
public void ToArray()
|
1087
|
{
|
1088
|
Assert.AreEqual("Alles klar", aeq(list.ToArray()));
|
1089
|
list.Add(7);
|
1090
|
list.Add(7);
|
1091
|
Assert.AreEqual("Alles klar", aeq(list.ToArray(), 7, 7));
|
1092
|
}
|
1093
|
|
1094
|
|
1095
|
[Test]
|
1096
|
public void CopyTo()
|
1097
|
{
|
1098
|
list.CopyTo(a, 1);
|
1099
|
Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
|
1100
|
list.Add(6);
|
1101
|
list.CopyTo(a, 2);
|
1102
|
Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
|
1103
|
list.Add(4);
|
1104
|
list.Add(4);
|
1105
|
list.Add(9);
|
1106
|
list.CopyTo(a, 4);
|
1107
|
Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009));
|
1108
|
list.Clear();
|
1109
|
list.Add(7);
|
1110
|
list.CopyTo(a, 9);
|
1111
|
Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7));
|
1112
|
}
|
1113
|
|
1114
|
|
1115
|
[Test]
|
1116
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
1117
|
public void CopyToBad()
|
1118
|
{
|
1119
|
list.CopyTo(a, 11);
|
1120
|
}
|
1121
|
|
1122
|
|
1123
|
[Test]
|
1124
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
1125
|
public void CopyToBad2()
|
1126
|
{
|
1127
|
list.CopyTo(a, -1);
|
1128
|
}
|
1129
|
|
1130
|
|
1131
|
[Test]
|
1132
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
1133
|
public void CopyToTooFar()
|
1134
|
{
|
1135
|
list.Add(3);
|
1136
|
list.Add(3);
|
1137
|
list.CopyTo(a, 9);
|
1138
|
}
|
1139
|
}
|
1140
|
|
1141
|
[TestFixture]
|
1142
|
public class Sync
|
1143
|
{
|
1144
|
private ArrayList<int> list;
|
1145
|
|
1146
|
|
1147
|
[SetUp]
|
1148
|
public void Init()
|
1149
|
{
|
1150
|
list = new ArrayList<int>();
|
1151
|
}
|
1152
|
|
1153
|
|
1154
|
[TearDown]
|
1155
|
public void Dispose() { list = null; }
|
1156
|
|
1157
|
|
1158
|
[Test]
|
1159
|
public void Get()
|
1160
|
{
|
1161
|
Assert.IsNotNull(((System.Collections.IList)list).SyncRoot);
|
1162
|
}
|
1163
|
}
|
1164
|
}
|
1165
|
|
1166
|
|
1167
|
|
1168
|
|
1169
|
namespace EditableCollection
|
1170
|
{
|
1171
|
[TestFixture]
|
1172
|
public class Searching
|
1173
|
{
|
1174
|
private ArrayList<int> list;
|
1175
|
|
1176
|
|
1177
|
[SetUp]
|
1178
|
public void Init() { list = new ArrayList<int>(); }
|
1179
|
|
1180
|
[Test]
|
1181
|
[ExpectedException(typeof(NullReferenceException))]
|
1182
|
public void NullEqualityComparerinConstructor1()
|
1183
|
{
|
1184
|
new ArrayList<int>(null);
|
1185
|
}
|
1186
|
|
1187
|
[Test]
|
1188
|
[ExpectedException(typeof(NullReferenceException))]
|
1189
|
public void NullEqualityComparerinConstructor2()
|
1190
|
{
|
1191
|
new ArrayList<int>(5, null);
|
1192
|
}
|
1193
|
|
1194
|
[Test]
|
1195
|
public void Contains()
|
1196
|
{
|
1197
|
Assert.IsFalse(list.Contains(5));
|
1198
|
list.Add(5);
|
1199
|
Assert.IsTrue(list.Contains(5));
|
1200
|
Assert.IsFalse(list.Contains(7));
|
1201
|
list.Add(8);
|
1202
|
list.Add(10);
|
1203
|
Assert.IsTrue(list.Contains(5));
|
1204
|
Assert.IsFalse(list.Contains(7));
|
1205
|
Assert.IsTrue(list.Contains(8));
|
1206
|
Assert.IsTrue(list.Contains(10));
|
1207
|
list.Remove(8);
|
1208
|
Assert.IsTrue(list.Contains(5));
|
1209
|
Assert.IsFalse(list.Contains(7));
|
1210
|
Assert.IsFalse(list.Contains(8));
|
1211
|
Assert.IsTrue(list.Contains(10));
|
1212
|
}
|
1213
|
|
1214
|
|
1215
|
[Test]
|
1216
|
public void ContainsCount()
|
1217
|
{
|
1218
|
Assert.AreEqual(0, list.ContainsCount(5));
|
1219
|
list.Add(5);
|
1220
|
Assert.AreEqual(1, list.ContainsCount(5));
|
1221
|
Assert.AreEqual(0, list.ContainsCount(7));
|
1222
|
list.Add(8);
|
1223
|
Assert.AreEqual(1, list.ContainsCount(5));
|
1224
|
Assert.AreEqual(0, list.ContainsCount(7));
|
1225
|
Assert.AreEqual(1, list.ContainsCount(8));
|
1226
|
list.Add(5);
|
1227
|
Assert.AreEqual(2, list.ContainsCount(5));
|
1228
|
Assert.AreEqual(0, list.ContainsCount(7));
|
1229
|
Assert.AreEqual(1, list.ContainsCount(8));
|
1230
|
}
|
1231
|
|
1232
|
|
1233
|
[Test]
|
1234
|
public void RemoveAllCopies()
|
1235
|
{
|
1236
|
list.Add(5); list.Add(7); list.Add(5);
|
1237
|
Assert.AreEqual(2, list.ContainsCount(5));
|
1238
|
Assert.AreEqual(1, list.ContainsCount(7));
|
1239
|
list.RemoveAllCopies(5);
|
1240
|
Assert.AreEqual(0, list.ContainsCount(5));
|
1241
|
Assert.AreEqual(1, list.ContainsCount(7));
|
1242
|
list.Add(5); list.Add(8); list.Add(5);
|
1243
|
list.RemoveAllCopies(8);
|
1244
|
Assert.IsTrue(IC.eq(list, 7, 5, 5));
|
1245
|
}
|
1246
|
|
1247
|
|
1248
|
[Test]
|
1249
|
public void FindAll()
|
1250
|
{
|
1251
|
Fun<int, bool> f = delegate(int i) { return i % 2 == 0; };
|
1252
|
|
1253
|
Assert.IsTrue(list.FindAll(f).IsEmpty);
|
1254
|
list.Add(5); list.Add(8); list.Add(5); list.Add(10); list.Add(8);
|
1255
|
Assert.IsTrue(((ArrayList<int>)list.FindAll(f)).Check());
|
1256
|
Assert.IsTrue(IC.eq(list.FindAll(f), 8, 10, 8));
|
1257
|
}
|
1258
|
|
1259
|
|
1260
|
[Test]
|
1261
|
public void ContainsAll()
|
1262
|
{
|
1263
|
ArrayList<int> list2 = new ArrayList<int>();
|
1264
|
|
1265
|
Assert.IsTrue(list.ContainsAll(list2));
|
1266
|
list2.Add(4);
|
1267
|
Assert.IsFalse(list.ContainsAll(list2));
|
1268
|
list.Add(4);
|
1269
|
Assert.IsTrue(list.ContainsAll(list2));
|
1270
|
list.Add(5);
|
1271
|
Assert.IsTrue(list.ContainsAll(list2));
|
1272
|
list2.Add(4);
|
1273
|
Assert.IsFalse(list.ContainsAll(list2));
|
1274
|
list.Add(4);
|
1275
|
Assert.IsTrue(list.ContainsAll(list2));
|
1276
|
}
|
1277
|
|
1278
|
|
1279
|
[Test]
|
1280
|
public void RetainAll()
|
1281
|
{
|
1282
|
ArrayList<int> list2 = new ArrayList<int>();
|
1283
|
|
1284
|
list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
|
1285
|
list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
|
1286
|
list.RetainAll(list2);
|
1287
|
Assert.IsTrue(list.Check());
|
1288
|
Assert.IsTrue(IC.eq(list, 4, 4, 5));
|
1289
|
list.Add(5); list.Add(4); list.Add(6);
|
1290
|
list2.Clear();
|
1291
|
list2.Add(5); list2.Add(5); list2.Add(6);
|
1292
|
list.RetainAll(list2);
|
1293
|
Assert.IsTrue(list.Check());
|
1294
|
Assert.IsTrue(IC.eq(list, 5, 5, 6));
|
1295
|
list2.Clear();
|
1296
|
list2.Add(7); list2.Add(8); list2.Add(9);
|
1297
|
list.RetainAll(list2);
|
1298
|
Assert.IsTrue(list.Check());
|
1299
|
Assert.IsTrue(IC.eq(list));
|
1300
|
}
|
1301
|
|
1302
|
|
1303
|
[Test]
|
1304
|
public void RemoveAll()
|
1305
|
{
|
1306
|
ArrayList<int> list2 = new ArrayList<int>();
|
1307
|
|
1308
|
list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
|
1309
|
list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
|
1310
|
list.RemoveAll(list2);
|
1311
|
Assert.IsTrue(list.Check());
|
1312
|
Assert.IsTrue(IC.eq(list, 4, 6));
|
1313
|
list.Add(5); list.Add(4); list.Add(6);
|
1314
|
list2.Clear();
|
1315
|
list2.Add(6); list2.Add(5); list2.Add(5); list2.Add(6);
|
1316
|
list.RemoveAll(list2);
|
1317
|
Assert.IsTrue(list.Check());
|
1318
|
Assert.IsTrue(IC.eq(list, 4, 4));
|
1319
|
list2.Clear();
|
1320
|
list2.Add(7); list2.Add(8); list2.Add(9);
|
1321
|
list.RemoveAll(list2);
|
1322
|
Assert.IsTrue(list.Check());
|
1323
|
Assert.IsTrue(IC.eq(list, 4, 4));
|
1324
|
}
|
1325
|
|
1326
|
|
1327
|
[Test]
|
1328
|
public void Remove()
|
1329
|
{
|
1330
|
Assert.IsFalse(list.FIFO);
|
1331
|
list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
|
1332
|
Assert.IsFalse(list.Remove(2));
|
1333
|
Assert.IsTrue(list.Check());
|
1334
|
Assert.IsTrue(list.Remove(4));
|
1335
|
Assert.IsTrue(list.Check());
|
1336
|
Assert.IsTrue(IC.eq(list, 4, 4, 5, 6));
|
1337
|
Assert.AreEqual(6, list.RemoveLast());
|
1338
|
Assert.IsTrue(list.Check());
|
1339
|
Assert.IsTrue(IC.eq(list, 4, 4, 5));
|
1340
|
list.Add(7);
|
1341
|
Assert.AreEqual(4, list.RemoveFirst());
|
1342
|
Assert.IsTrue(list.Check());
|
1343
|
Assert.IsTrue(IC.eq(list, 4, 5, 7));
|
1344
|
|
1345
|
list.FIFO = true;
|
1346
|
list.Clear();
|
1347
|
list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
|
1348
|
Assert.IsFalse(list.Remove(2));
|
1349
|
Assert.IsTrue(list.Check());
|
1350
|
Assert.IsTrue(list.Remove(4));
|
1351
|
Assert.IsTrue(list.Check());
|
1352
|
Assert.IsTrue(IC.eq(list, 4, 5, 4, 6));
|
1353
|
Assert.AreEqual(6, list.RemoveLast());
|
1354
|
Assert.IsTrue(list.Check());
|
1355
|
Assert.IsTrue(IC.eq(list, 4, 5, 4));
|
1356
|
list.Add(7);
|
1357
|
Assert.AreEqual(4, list.RemoveFirst());
|
1358
|
Assert.IsTrue(list.Check());
|
1359
|
Assert.IsTrue(IC.eq(list, 5, 4, 7));
|
1360
|
}
|
1361
|
|
1362
|
|
1363
|
[Test]
|
1364
|
public void Clear()
|
1365
|
{
|
1366
|
list.Add(7); list.Add(7);
|
1367
|
list.Clear();
|
1368
|
Assert.IsTrue(list.IsEmpty);
|
1369
|
}
|
1370
|
|
1371
|
|
1372
|
[TearDown]
|
1373
|
public void Dispose() { list = null; }
|
1374
|
}
|
1375
|
}
|
1376
|
|
1377
|
|
1378
|
|
1379
|
|
1380
|
namespace Indexed
|
1381
|
{
|
1382
|
[TestFixture]
|
1383
|
public class Searching
|
1384
|
{
|
1385
|
private IIndexed<int> dit;
|
1386
|
|
1387
|
|
1388
|
[SetUp]
|
1389
|
public void Init()
|
1390
|
{
|
1391
|
dit = new ArrayList<int>();
|
1392
|
}
|
1393
|
|
1394
|
|
1395
|
[Test]
|
1396
|
public void IndexOf()
|
1397
|
{
|
1398
|
Assert.AreEqual(~0, dit.IndexOf(6));
|
1399
|
dit.Add(7);
|
1400
|
Assert.AreEqual(~1, dit.IndexOf(6));
|
1401
|
Assert.AreEqual(~1, dit.LastIndexOf(6));
|
1402
|
Assert.AreEqual(0, dit.IndexOf(7));
|
1403
|
dit.Add(5); dit.Add(7); dit.Add(8); dit.Add(7);
|
1404
|
Assert.AreEqual(~5, dit.IndexOf(6));
|
1405
|
Assert.AreEqual(0, dit.IndexOf(7));
|
1406
|
Assert.AreEqual(4, dit.LastIndexOf(7));
|
1407
|
Assert.AreEqual(3, dit.IndexOf(8));
|
1408
|
Assert.AreEqual(1, dit.LastIndexOf(5));
|
1409
|
}
|
1410
|
|
1411
|
|
1412
|
[TearDown]
|
1413
|
public void Dispose()
|
1414
|
{
|
1415
|
dit = null;
|
1416
|
}
|
1417
|
}
|
1418
|
|
1419
|
|
1420
|
|
1421
|
[TestFixture]
|
1422
|
public class Removing
|
1423
|
{
|
1424
|
private IIndexed<int> dit;
|
1425
|
|
1426
|
|
1427
|
[SetUp]
|
1428
|
public void Init()
|
1429
|
{
|
1430
|
dit = new ArrayList<int>();
|
1431
|
}
|
1432
|
|
1433
|
|
1434
|
[Test]
|
1435
|
public void RemoveAt()
|
1436
|
{
|
1437
|
dit.Add(5); dit.Add(7); dit.Add(9); dit.Add(1); dit.Add(2);
|
1438
|
Assert.AreEqual(7, dit.RemoveAt(1));
|
1439
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1440
|
Assert.IsTrue(IC.eq(dit, 5, 9, 1, 2));
|
1441
|
Assert.AreEqual(5, dit.RemoveAt(0));
|
1442
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1443
|
Assert.IsTrue(IC.eq(dit, 9, 1, 2));
|
1444
|
Assert.AreEqual(2, dit.RemoveAt(2));
|
1445
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1446
|
Assert.IsTrue(IC.eq(dit, 9, 1));
|
1447
|
}
|
1448
|
|
1449
|
|
1450
|
[Test]
|
1451
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1452
|
public void RemoveAtBad0()
|
1453
|
{
|
1454
|
dit.RemoveAt(0);
|
1455
|
}
|
1456
|
|
1457
|
|
1458
|
[Test]
|
1459
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1460
|
public void RemoveAtBadM1()
|
1461
|
{
|
1462
|
dit.RemoveAt(-1);
|
1463
|
}
|
1464
|
|
1465
|
|
1466
|
[Test]
|
1467
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1468
|
public void RemoveAtBad1()
|
1469
|
{
|
1470
|
dit.Add(8);
|
1471
|
dit.RemoveAt(1);
|
1472
|
}
|
1473
|
|
1474
|
|
1475
|
[Test]
|
1476
|
public void RemoveInterval()
|
1477
|
{
|
1478
|
dit.RemoveInterval(0, 0);
|
1479
|
dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
|
1480
|
dit.RemoveInterval(3, 0);
|
1481
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1482
|
Assert.IsTrue(IC.eq(dit, 10, 20, 30, 40, 50, 60));
|
1483
|
dit.RemoveInterval(3, 1);
|
1484
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1485
|
Assert.IsTrue(IC.eq(dit, 10, 20, 30, 50, 60));
|
1486
|
dit.RemoveInterval(1, 3);
|
1487
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1488
|
Assert.IsTrue(IC.eq(dit, 10, 60));
|
1489
|
dit.RemoveInterval(0, 2);
|
1490
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1491
|
Assert.IsTrue(IC.eq(dit));
|
1492
|
dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
|
1493
|
dit.RemoveInterval(0, 2);
|
1494
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1495
|
Assert.IsTrue(IC.eq(dit, 30, 40, 50, 60));
|
1496
|
dit.RemoveInterval(2, 2);
|
1497
|
Assert.IsTrue(((ArrayList<int>)dit).Check());
|
1498
|
Assert.IsTrue(IC.eq(dit, 30, 40));
|
1499
|
}
|
1500
|
|
1501
|
|
1502
|
[TearDown]
|
1503
|
public void Dispose()
|
1504
|
{
|
1505
|
dit = null;
|
1506
|
}
|
1507
|
}
|
1508
|
}
|
1509
|
|
1510
|
|
1511
|
|
1512
|
|
1513
|
namespace List
|
1514
|
{
|
1515
|
[TestFixture]
|
1516
|
public class Searching
|
1517
|
{
|
1518
|
private IList<int> lst;
|
1519
|
|
1520
|
|
1521
|
[SetUp]
|
1522
|
public void Init() { lst = new ArrayList<int>(); }
|
1523
|
|
1524
|
|
1525
|
[TearDown]
|
1526
|
public void Dispose() { lst = null; }
|
1527
|
|
1528
|
|
1529
|
[Test]
|
1530
|
[ExpectedException(typeof(NoSuchItemException))]
|
1531
|
public void FirstBad()
|
1532
|
{
|
1533
|
int f = lst.First;
|
1534
|
}
|
1535
|
|
1536
|
|
1537
|
[Test]
|
1538
|
[ExpectedException(typeof(NoSuchItemException))]
|
1539
|
public void LastBad()
|
1540
|
{
|
1541
|
int f = lst.Last;
|
1542
|
}
|
1543
|
|
1544
|
|
1545
|
[Test]
|
1546
|
public void FirstLast()
|
1547
|
{
|
1548
|
lst.Add(19);
|
1549
|
Assert.AreEqual(19, lst.First);
|
1550
|
Assert.AreEqual(19, lst.Last);
|
1551
|
lst.Add(34); lst.InsertFirst(12);
|
1552
|
Assert.AreEqual(12, lst.First);
|
1553
|
Assert.AreEqual(34, lst.Last);
|
1554
|
}
|
1555
|
|
1556
|
|
1557
|
[Test]
|
1558
|
public void This()
|
1559
|
{
|
1560
|
lst.Add(34);
|
1561
|
Assert.AreEqual(34, lst[0]);
|
1562
|
lst[0] = 56;
|
1563
|
Assert.AreEqual(56, lst.First);
|
1564
|
lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7);
|
1565
|
lst[0] = 45; lst[2] = 78; lst[4] = 101;
|
1566
|
Assert.IsTrue(IC.eq(lst, 45, 7, 78, 7, 101));
|
1567
|
}
|
1568
|
|
1569
|
|
1570
|
[Test]
|
1571
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1572
|
public void ThisBadEmptyGet()
|
1573
|
{
|
1574
|
int f = lst[0];
|
1575
|
}
|
1576
|
|
1577
|
|
1578
|
[Test]
|
1579
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1580
|
public void ThisBadLowGet()
|
1581
|
{
|
1582
|
lst.Add(7);
|
1583
|
|
1584
|
int f = lst[-1];
|
1585
|
}
|
1586
|
|
1587
|
|
1588
|
[Test]
|
1589
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1590
|
public void ThisBadHiGet()
|
1591
|
{
|
1592
|
lst.Add(6);
|
1593
|
|
1594
|
int f = lst[1];
|
1595
|
}
|
1596
|
|
1597
|
|
1598
|
[Test]
|
1599
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1600
|
public void ThisBadEmptySet()
|
1601
|
{
|
1602
|
lst[0] = 4;
|
1603
|
}
|
1604
|
|
1605
|
|
1606
|
[Test]
|
1607
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1608
|
public void ThisBadLowSet()
|
1609
|
{
|
1610
|
lst.Add(7);
|
1611
|
lst[-1] = 9;
|
1612
|
}
|
1613
|
|
1614
|
|
1615
|
[Test]
|
1616
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1617
|
public void ThisBadHiSet()
|
1618
|
{
|
1619
|
lst.Add(6);
|
1620
|
lst[1] = 11;
|
1621
|
}
|
1622
|
}
|
1623
|
|
1624
|
|
1625
|
|
1626
|
[TestFixture]
|
1627
|
public class Inserting
|
1628
|
{
|
1629
|
private IList<int> lst;
|
1630
|
|
1631
|
|
1632
|
[SetUp]
|
1633
|
public void Init() { lst = new ArrayList<int>(); }
|
1634
|
|
1635
|
|
1636
|
[TearDown]
|
1637
|
public void Dispose() { lst = null; }
|
1638
|
|
1639
|
|
1640
|
[Test]
|
1641
|
public void Insert()
|
1642
|
{
|
1643
|
lst.Insert(0, 5);
|
1644
|
Assert.IsTrue(IC.eq(lst, 5));
|
1645
|
lst.Insert(0, 7);
|
1646
|
Assert.IsTrue(IC.eq(lst, 7, 5));
|
1647
|
lst.Insert(1, 4);
|
1648
|
Assert.IsTrue(IC.eq(lst, 7, 4, 5));
|
1649
|
lst.Insert(3, 2);
|
1650
|
Assert.IsTrue(IC.eq(lst, 7, 4, 5, 2));
|
1651
|
}
|
1652
|
|
1653
|
[Test]
|
1654
|
public void InsertDuplicate()
|
1655
|
{
|
1656
|
lst.Insert(0, 5);
|
1657
|
Assert.IsTrue(IC.eq(lst, 5));
|
1658
|
lst.Insert(0, 7);
|
1659
|
Assert.IsTrue(IC.eq(lst, 7, 5));
|
1660
|
lst.Insert(1, 5);
|
1661
|
Assert.IsTrue(IC.eq(lst, 7, 5, 5));
|
1662
|
}
|
1663
|
|
1664
|
|
1665
|
[Test]
|
1666
|
public void InsertAllDuplicate1()
|
1667
|
{
|
1668
|
lst.Insert(0, 3);
|
1669
|
Assert.IsTrue(IC.eq(lst, 3));
|
1670
|
lst.Insert(0, 7);
|
1671
|
Assert.IsTrue(IC.eq(lst, 7, 3));
|
1672
|
lst.InsertAll<int>(1, new int[] { 1, 2, 3, 4 });
|
1673
|
Assert.IsTrue(IC.eq(lst, 7, 1, 2, 3, 4, 3));
|
1674
|
Assert.IsTrue(lst.Check());
|
1675
|
}
|
1676
|
[Test]
|
1677
|
public void InsertAllDuplicate2()
|
1678
|
{
|
1679
|
lst.Insert(0, 3);
|
1680
|
Assert.IsTrue(IC.eq(lst, 3));
|
1681
|
lst.Insert(0, 7);
|
1682
|
Assert.IsTrue(IC.eq(lst, 7, 3));
|
1683
|
lst.InsertAll<int>(1, new int[] { 5, 6, 5, 8 });
|
1684
|
Assert.IsTrue(lst.Check());
|
1685
|
Assert.IsTrue(IC.eq(lst, 7, 5, 6, 5, 8, 3));
|
1686
|
}
|
1687
|
|
1688
|
|
1689
|
[Test]
|
1690
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1691
|
public void BadInsertLow()
|
1692
|
{
|
1693
|
lst.Add(7);
|
1694
|
lst.Insert(-1, 9);
|
1695
|
}
|
1696
|
|
1697
|
|
1698
|
[Test]
|
1699
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
1700
|
public void BadInsertHi()
|
1701
|
{
|
1702
|
lst.Add(6);
|
1703
|
lst.Insert(2, 11);
|
1704
|
}
|
1705
|
|
1706
|
|
1707
|
[Test]
|
1708
|
public void FIFO()
|
1709
|
{
|
1710
|
for (int i = 0; i < 7; i++)
|
1711
|
lst.Add(2 * i);
|
1712
|
|
1713
|
Assert.IsFalse(lst.FIFO);
|
1714
|
Assert.AreEqual(12, lst.Remove());
|
1715
|
Assert.AreEqual(10, lst.Remove());
|
1716
|
lst.FIFO = true;
|
1717
|
Assert.AreEqual(0, lst.Remove());
|
1718
|
Assert.AreEqual(2, lst.Remove());
|
1719
|
lst.FIFO = false;
|
1720
|
Assert.AreEqual(8, lst.Remove());
|
1721
|
Assert.AreEqual(6, lst.Remove());
|
1722
|
}
|
1723
|
|
1724
|
|
1725
|
[Test]
|
1726
|
public void InsertFirstLast()
|
1727
|
{
|
1728
|
lst.InsertFirst(4);
|
1729
|
lst.InsertLast(5);
|
1730
|
lst.InsertFirst(14);
|
1731
|
lst.InsertLast(15);
|
1732
|
lst.InsertFirst(24);
|
1733
|
lst.InsertLast(25);
|
1734
|
lst.InsertFirst(34);
|
1735
|
lst.InsertLast(55);
|
1736
|
Assert.IsTrue(IC.eq(lst, 34, 24, 14, 4, 5, 15, 25, 55));
|
1737
|
}
|
1738
|
|
1739
|
|
1740
|
[Test]
|
1741
|
public void InsertFirst()
|
1742
|
{
|
1743
|
lst.Add(2);
|
1744
|
lst.Add(3);
|
1745
|
lst.Add(2);
|
1746
|
lst.Add(5);
|
1747
|
lst.ViewOf(2).InsertFirst(7);
|
1748
|
Assert.IsTrue(lst.Check());
|
1749
|
Assert.IsTrue(IC.eq(lst, 7, 2, 3, 2, 5));
|
1750
|
lst.ViewOf(3).InsertFirst(8);
|
1751
|
Assert.IsTrue(lst.Check());
|
1752
|
Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 5));
|
1753
|
lst.ViewOf(5).InsertFirst(9);
|
1754
|
Assert.IsTrue(lst.Check());
|
1755
|
Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 9, 5));
|
1756
|
}
|
1757
|
|
1758
|
[Test]
|
1759
|
public void InsertAfter()
|
1760
|
{
|
1761
|
lst.Add(1);
|
1762
|
lst.Add(2);
|
1763
|
lst.Add(3);
|
1764
|
lst.Add(2);
|
1765
|
lst.Add(5);
|
1766
|
lst.LastViewOf(2).InsertLast(7);
|
1767
|
Assert.IsTrue(lst.Check());
|
1768
|
Assert.IsTrue(IC.eq(lst, 1, 2, 3, 2, 7, 5));
|
1769
|
lst.LastViewOf(1).InsertLast(8);
|
1770
|
Assert.IsTrue(lst.Check());
|
1771
|
Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5));
|
1772
|
lst.LastViewOf(5).InsertLast(9);
|
1773
|
Assert.IsTrue(lst.Check());
|
1774
|
Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5, 9));
|
1775
|
}
|
1776
|
|
1777
|
[Test]
|
1778
|
public void InsertAll()
|
1779
|
{
|
1780
|
lst.Add(1);
|
1781
|
lst.Add(2);
|
1782
|
lst.Add(3);
|
1783
|
lst.Add(4);
|
1784
|
|
1785
|
IList<int> lst2 = new ArrayList<int>();
|
1786
|
|
1787
|
lst2.Add(7); lst2.Add(8); lst2.Add(9);
|
1788
|
lst.InsertAll(0, lst2);
|
1789
|
Assert.IsTrue(lst.Check());
|
1790
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4));
|
1791
|
lst.InsertAll(7, lst2);
|
1792
|
Assert.IsTrue(lst.Check());
|
1793
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4, 7, 8, 9));
|
1794
|
lst.InsertAll(5, lst2);
|
1795
|
Assert.IsTrue(lst.Check());
|
1796
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9));
|
1797
|
}
|
1798
|
|
1799
|
|
1800
|
[Test]
|
1801
|
public void Map()
|
1802
|
{
|
1803
|
Fun<int, string> m = delegate(int i) { return "<<" + i + ">>"; };
|
1804
|
IList<string> r = lst.Map(m);
|
1805
|
|
1806
|
Assert.IsTrue(r.Check());
|
1807
|
Assert.IsTrue(r.IsEmpty);
|
1808
|
lst.Add(1);
|
1809
|
lst.Add(2);
|
1810
|
lst.Add(3);
|
1811
|
lst.Add(4);
|
1812
|
r = lst.Map(m);
|
1813
|
Assert.IsTrue(r.Check());
|
1814
|
Assert.AreEqual(4, r.Count);
|
1815
|
for (int i = 0; i < 4; i++)
|
1816
|
Assert.AreEqual("<<" + (i + 1) + ">>", r[i]);
|
1817
|
}
|
1818
|
|
1819
|
[Test]
|
1820
|
[ExpectedException(typeof(CollectionModifiedException))]
|
1821
|
public void BadMapper()
|
1822
|
{
|
1823
|
lst.Add(1);
|
1824
|
lst.Add(2);
|
1825
|
lst.Add(3);
|
1826
|
Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
|
1827
|
lst.Map(m);
|
1828
|
}
|
1829
|
|
1830
|
[Test]
|
1831
|
[ExpectedException(typeof(CollectionModifiedException))]
|
1832
|
public void ModifyingFindAll()
|
1833
|
{
|
1834
|
lst.Add(1);
|
1835
|
lst.Add(2);
|
1836
|
lst.Add(3);
|
1837
|
Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
|
1838
|
lst.FindAll(m);
|
1839
|
}
|
1840
|
|
1841
|
[Test]
|
1842
|
[ExpectedException(typeof(CollectionModifiedException))]
|
1843
|
public void BadMapperView()
|
1844
|
{
|
1845
|
lst = lst.View(0, 0);
|
1846
|
lst.Add(1);
|
1847
|
lst.Add(2);
|
1848
|
lst.Add(3);
|
1849
|
Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
|
1850
|
lst.Map(m);
|
1851
|
}
|
1852
|
|
1853
|
[Test]
|
1854
|
[ExpectedException(typeof(CollectionModifiedException))]
|
1855
|
public void ModifyingFindAllView()
|
1856
|
{
|
1857
|
lst = lst.View(0, 0);
|
1858
|
lst.Add(1);
|
1859
|
lst.Add(2);
|
1860
|
lst.Add(3);
|
1861
|
Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
|
1862
|
lst.FindAll(m);
|
1863
|
}
|
1864
|
|
1865
|
[Test]
|
1866
|
[ExpectedException(typeof(NoSuchItemException))]
|
1867
|
public void BadRemove() { lst.Remove(); }
|
1868
|
|
1869
|
[Test]
|
1870
|
[ExpectedException(typeof(NoSuchItemException))]
|
1871
|
public void BadRemoveFirst() { lst.RemoveFirst(); }
|
1872
|
|
1873
|
[Test]
|
1874
|
[ExpectedException(typeof(NoSuchItemException))]
|
1875
|
public void BadRemoveLast() { lst.RemoveLast(); }
|
1876
|
|
1877
|
|
1878
|
[Test]
|
1879
|
public void RemoveFirstLast()
|
1880
|
{
|
1881
|
lst.Add(1);
|
1882
|
lst.Add(2);
|
1883
|
lst.Add(3);
|
1884
|
lst.Add(4);
|
1885
|
Assert.AreEqual(1, lst.RemoveFirst());
|
1886
|
Assert.AreEqual(4, lst.RemoveLast());
|
1887
|
Assert.AreEqual(2, lst.RemoveFirst());
|
1888
|
Assert.AreEqual(3, lst.RemoveLast());
|
1889
|
Assert.IsTrue(lst.IsEmpty);
|
1890
|
}
|
1891
|
|
1892
|
|
1893
|
[Test]
|
1894
|
public void Reverse()
|
1895
|
{
|
1896
|
for (int i = 0; i < 10; i++)
|
1897
|
lst.Add(i);
|
1898
|
|
1899
|
lst.Reverse();
|
1900
|
Assert.IsTrue(lst.Check());
|
1901
|
Assert.IsTrue(IC.eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
|
1902
|
lst.View(0, 3).Reverse();
|
1903
|
Assert.IsTrue(lst.Check());
|
1904
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
|
1905
|
lst.View(7, 0).Reverse();
|
1906
|
Assert.IsTrue(lst.Check());
|
1907
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
|
1908
|
lst.View(7, 3).Reverse();
|
1909
|
Assert.IsTrue(lst.Check());
|
1910
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
|
1911
|
lst.View(5, 1).Reverse();
|
1912
|
Assert.IsTrue(lst.Check());
|
1913
|
Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
|
1914
|
}
|
1915
|
|
1916
|
|
1917
|
[Test]
|
1918
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
1919
|
public void BadReverse()
|
1920
|
{
|
1921
|
for (int i = 0; i < 10; i++)
|
1922
|
lst.Add(i);
|
1923
|
|
1924
|
lst.View(8, 3).Reverse();
|
1925
|
}
|
1926
|
}
|
1927
|
|
1928
|
[TestFixture]
|
1929
|
public class Combined
|
1930
|
{
|
1931
|
private IList<KeyValuePair<int, int>> lst;
|
1932
|
|
1933
|
|
1934
|
[SetUp]
|
1935
|
public void Init()
|
1936
|
{
|
1937
|
lst = new ArrayList<KeyValuePair<int, int>>(new KeyValuePairEqualityComparer<int, int>());
|
1938
|
for (int i = 0; i < 10; i++)
|
1939
|
lst.Add(new KeyValuePair<int, int>(i, i + 30));
|
1940
|
}
|
1941
|
|
1942
|
|
1943
|
[TearDown]
|
1944
|
public void Dispose() { lst = null; }
|
1945
|
|
1946
|
|
1947
|
[Test]
|
1948
|
public void Find()
|
1949
|
{
|
1950
|
KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
|
1951
|
Assert.IsTrue(lst.Find(ref p));
|
1952
|
Assert.AreEqual(3, p.Key);
|
1953
|
Assert.AreEqual(33, p.Value);
|
1954
|
p = new KeyValuePair<int, int>(13, 78);
|
1955
|
Assert.IsFalse(lst.Find(ref p));
|
1956
|
}
|
1957
|
|
1958
|
|
1959
|
[Test]
|
1960
|
public void FindOrAdd()
|
1961
|
{
|
1962
|
KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
|
1963
|
|
1964
|
Assert.IsTrue(lst.FindOrAdd(ref p));
|
1965
|
Assert.AreEqual(3, p.Key);
|
1966
|
Assert.AreEqual(33, p.Value);
|
1967
|
p = new KeyValuePair<int, int>(13, 79);
|
1968
|
Assert.IsFalse(lst.FindOrAdd(ref p));
|
1969
|
Assert.AreEqual(13, lst[10].Key);
|
1970
|
Assert.AreEqual(79, lst[10].Value);
|
1971
|
}
|
1972
|
|
1973
|
|
1974
|
[Test]
|
1975
|
public void Update()
|
1976
|
{
|
1977
|
KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
|
1978
|
|
1979
|
Assert.IsTrue(lst.Update(p));
|
1980
|
Assert.AreEqual(3, lst[3].Key);
|
1981
|
Assert.AreEqual(78, lst[3].Value);
|
1982
|
p = new KeyValuePair<int, int>(13, 78);
|
1983
|
Assert.IsFalse(lst.Update(p));
|
1984
|
}
|
1985
|
|
1986
|
|
1987
|
[Test]
|
1988
|
public void UpdateOrAdd1()
|
1989
|
{
|
1990
|
KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
|
1991
|
|
1992
|
Assert.IsTrue(lst.UpdateOrAdd(p));
|
1993
|
Assert.AreEqual(3, lst[3].Key);
|
1994
|
Assert.AreEqual(78, lst[3].Value);
|
1995
|
p = new KeyValuePair<int, int>(13, 79);
|
1996
|
Assert.IsFalse(lst.UpdateOrAdd(p));
|
1997
|
Assert.AreEqual(13, lst[10].Key);
|
1998
|
Assert.AreEqual(79, lst[10].Value);
|
1999
|
}
|
2000
|
|
2001
|
[Test]
|
2002
|
public void UpdateOrAdd2()
|
2003
|
{
|
2004
|
ICollection<String> coll = new ArrayList<String>();
|
2005
|
// s1 and s2 are distinct objects but contain the same text:
|
2006
|
String old, s1 = "abc", s2 = ("def" + s1).Substring(3);
|
2007
|
Assert.IsFalse(coll.UpdateOrAdd(s1, out old));
|
2008
|
Assert.AreEqual(null, old);
|
2009
|
Assert.IsTrue(coll.UpdateOrAdd(s2, out old));
|
2010
|
Assert.IsTrue(Object.ReferenceEquals(s1, old));
|
2011
|
Assert.IsFalse(Object.ReferenceEquals(s2, old));
|
2012
|
}
|
2013
|
|
2014
|
[Test]
|
2015
|
public void RemoveWithReturn()
|
2016
|
{
|
2017
|
KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
|
2018
|
|
2019
|
Assert.IsTrue(lst.Remove(p, out p));
|
2020
|
Assert.AreEqual(3, p.Key);
|
2021
|
Assert.AreEqual(33, p.Value);
|
2022
|
Assert.AreEqual(4, lst[3].Key);
|
2023
|
Assert.AreEqual(34, lst[3].Value);
|
2024
|
p = new KeyValuePair<int, int>(13, 78);
|
2025
|
Assert.IsFalse(lst.Remove(p, out p));
|
2026
|
}
|
2027
|
}
|
2028
|
|
2029
|
|
2030
|
[TestFixture]
|
2031
|
public class SortingTests
|
2032
|
{
|
2033
|
private IList<int> lst;
|
2034
|
|
2035
|
|
2036
|
[SetUp]
|
2037
|
public void Init() { lst = new ArrayList<int>(); }
|
2038
|
|
2039
|
|
2040
|
[TearDown]
|
2041
|
public void Dispose() { lst = null; }
|
2042
|
|
2043
|
|
2044
|
[Test]
|
2045
|
public void Sort()
|
2046
|
{
|
2047
|
lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
|
2048
|
Assert.IsFalse(lst.IsSorted(new IC()));
|
2049
|
lst.Sort(new IC());
|
2050
|
Assert.IsTrue(lst.IsSorted());
|
2051
|
Assert.IsTrue(lst.IsSorted(new IC()));
|
2052
|
Assert.IsTrue(IC.eq(lst, 3, 5, 5, 6, 7));
|
2053
|
}
|
2054
|
|
2055
|
|
2056
|
[Test]
|
2057
|
public void Stability()
|
2058
|
{
|
2059
|
IList<KeyValuePair<int, string>> lst2 = new ArrayList<KeyValuePair<int, string>>();
|
2060
|
SCG.IComparer<KeyValuePair<int, string>> c = new KeyValuePairComparer<int, string>(new IC());
|
2061
|
|
2062
|
lst2.Add(new KeyValuePair<int, string>(5, "a"));
|
2063
|
lst2.Add(new KeyValuePair<int, string>(5, "b"));
|
2064
|
lst2.Add(new KeyValuePair<int, string>(6, "c"));
|
2065
|
lst2.Add(new KeyValuePair<int, string>(4, "d"));
|
2066
|
lst2.Add(new KeyValuePair<int, string>(3, "e"));
|
2067
|
lst2.Add(new KeyValuePair<int, string>(4, "f"));
|
2068
|
lst2.Add(new KeyValuePair<int, string>(5, "handle"));
|
2069
|
Assert.IsFalse(lst2.IsSorted(c));
|
2070
|
lst2.Sort(c);
|
2071
|
Assert.IsTrue(lst2.IsSorted(c));
|
2072
|
|
2073
|
KeyValuePair<int, string> p = lst2.RemoveFirst();
|
2074
|
|
2075
|
Assert.AreEqual(3, p.Key);
|
2076
|
Assert.AreEqual("e", p.Value);
|
2077
|
p = lst2.RemoveFirst();
|
2078
|
Assert.AreEqual(4, p.Key);
|
2079
|
Assert.AreEqual("d", p.Value);
|
2080
|
p = lst2.RemoveFirst();
|
2081
|
Assert.AreEqual(4, p.Key);
|
2082
|
Assert.AreEqual("f", p.Value);
|
2083
|
p = lst2.RemoveFirst();
|
2084
|
Assert.AreEqual(5, p.Key);
|
2085
|
Assert.AreEqual("a", p.Value);
|
2086
|
p = lst2.RemoveFirst();
|
2087
|
Assert.AreEqual(5, p.Key);
|
2088
|
Assert.AreEqual("b", p.Value);
|
2089
|
p = lst2.RemoveFirst();
|
2090
|
Assert.AreEqual(5, p.Key);
|
2091
|
Assert.AreEqual("handle", p.Value);
|
2092
|
p = lst2.RemoveFirst();
|
2093
|
Assert.AreEqual(6, p.Key);
|
2094
|
Assert.AreEqual("c", p.Value);
|
2095
|
Assert.IsTrue(lst2.IsEmpty);
|
2096
|
}
|
2097
|
}
|
2098
|
|
2099
|
[TestFixture]
|
2100
|
public class ShuffleTests
|
2101
|
{
|
2102
|
private IList<int> lst;
|
2103
|
|
2104
|
|
2105
|
[SetUp]
|
2106
|
public void Init() { lst = new ArrayList<int>(); }
|
2107
|
|
2108
|
|
2109
|
[TearDown]
|
2110
|
public void Dispose() { lst = null; }
|
2111
|
|
2112
|
|
2113
|
[Test]
|
2114
|
public void Shuffle()
|
2115
|
{
|
2116
|
lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
|
2117
|
for (int i = 0; i < 100; i++)
|
2118
|
{
|
2119
|
lst.Shuffle(new C5Random(i + 1));
|
2120
|
Assert.IsTrue(lst.Check(), "Check " + i);
|
2121
|
int[] lst2 = lst.ToArray();
|
2122
|
Sorting.IntroSort<int>(lst2);
|
2123
|
Assert.IsTrue(IC.eq(lst2, 3, 5, 5, 6, 7), "Contents " + i);
|
2124
|
}
|
2125
|
}
|
2126
|
}
|
2127
|
|
2128
|
}
|
2129
|
|
2130
|
|
2131
|
namespace IStackQueue
|
2132
|
{
|
2133
|
[TestFixture]
|
2134
|
public class Stack
|
2135
|
{
|
2136
|
private IStack<int> list;
|
2137
|
|
2138
|
|
2139
|
[SetUp]
|
2140
|
public void Init() { list = new ArrayList<int>(); }
|
2141
|
|
2142
|
|
2143
|
[Test]
|
2144
|
public void Normal()
|
2145
|
{
|
2146
|
list.Push(7);
|
2147
|
list.Push(5);
|
2148
|
list.Push(7);
|
2149
|
list.Push(8);
|
2150
|
list.Push(9);
|
2151
|
Assert.AreEqual(9, list.Pop());
|
2152
|
Assert.AreEqual(8, list.Pop());
|
2153
|
Assert.AreEqual(7, list.Pop());
|
2154
|
Assert.AreEqual(5, list.Pop());
|
2155
|
Assert.AreEqual(7, list.Pop());
|
2156
|
}
|
2157
|
|
2158
|
|
2159
|
[Test]
|
2160
|
[ExpectedException(typeof(NoSuchItemException))]
|
2161
|
public void PopEmpty()
|
2162
|
{
|
2163
|
list.Push(5);
|
2164
|
Assert.AreEqual(5, list.Pop());
|
2165
|
list.Pop();
|
2166
|
}
|
2167
|
|
2168
|
|
2169
|
[TearDown]
|
2170
|
public void Dispose() { list = null; }
|
2171
|
}
|
2172
|
[TestFixture]
|
2173
|
public class Queue
|
2174
|
{
|
2175
|
private IQueue<int> list;
|
2176
|
|
2177
|
|
2178
|
[SetUp]
|
2179
|
public void Init() { list = new ArrayList<int>(); }
|
2180
|
|
2181
|
|
2182
|
[Test]
|
2183
|
public void Normal()
|
2184
|
{
|
2185
|
list.Enqueue(7);
|
2186
|
list.Enqueue(5);
|
2187
|
list.Enqueue(7);
|
2188
|
list.Enqueue(8);
|
2189
|
list.Enqueue(9);
|
2190
|
Assert.AreEqual(7, list.Dequeue());
|
2191
|
Assert.AreEqual(5, list.Dequeue());
|
2192
|
Assert.AreEqual(7, list.Dequeue());
|
2193
|
Assert.AreEqual(8, list.Dequeue());
|
2194
|
Assert.AreEqual(9, list.Dequeue());
|
2195
|
}
|
2196
|
|
2197
|
|
2198
|
[Test]
|
2199
|
[ExpectedException(typeof(NoSuchItemException))]
|
2200
|
public void DeQueueEmpty()
|
2201
|
{
|
2202
|
list.Enqueue(5);
|
2203
|
Assert.AreEqual(5, list.Dequeue());
|
2204
|
list.Dequeue();
|
2205
|
}
|
2206
|
|
2207
|
|
2208
|
[TearDown]
|
2209
|
public void Dispose() { list = null; }
|
2210
|
}
|
2211
|
}
|
2212
|
|
2213
|
|
2214
|
namespace Range
|
2215
|
{
|
2216
|
[TestFixture]
|
2217
|
public class Range
|
2218
|
{
|
2219
|
private IList<int> lst;
|
2220
|
|
2221
|
|
2222
|
[SetUp]
|
2223
|
public void Init() { lst = new ArrayList<int>(); }
|
2224
|
|
2225
|
|
2226
|
[TearDown]
|
2227
|
public void Dispose() { lst = null; }
|
2228
|
|
2229
|
|
2230
|
[Test]
|
2231
|
public void GetRange()
|
2232
|
{
|
2233
|
//Assert.IsTrue(IC.eq(lst[0, 0)));
|
2234
|
for (int i = 0; i < 10; i++) lst.Add(i);
|
2235
|
|
2236
|
Assert.IsTrue(IC.eq(lst[0, 3], 0, 1, 2));
|
2237
|
Assert.IsTrue(IC.eq(lst[3, 4], 3, 4, 5, 6));
|
2238
|
Assert.IsTrue(IC.eq(lst[6, 4], 6, 7, 8, 9));
|
2239
|
}
|
2240
|
|
2241
|
|
2242
|
[Test]
|
2243
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
2244
|
public void BadGetRange()
|
2245
|
{
|
2246
|
object foo = lst[0, 11];
|
2247
|
}
|
2248
|
|
2249
|
|
2250
|
[Test]
|
2251
|
public void Backwards()
|
2252
|
{
|
2253
|
for (int i = 0; i < 10; i++) lst.Add(i);
|
2254
|
|
2255
|
Assert.IsTrue(IC.eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
|
2256
|
Assert.IsTrue(IC.eq(lst[0, 4].Backwards(), 3, 2, 1, 0));
|
2257
|
Assert.IsTrue(IC.eq(lst[3, 4].Backwards(), 6, 5, 4, 3));
|
2258
|
Assert.IsTrue(IC.eq(lst[6, 4].Backwards(), 9, 8, 7, 6));
|
2259
|
}
|
2260
|
|
2261
|
|
2262
|
[Test]
|
2263
|
public void DirectionAndCount()
|
2264
|
{
|
2265
|
for (int i = 0; i < 10; i++) lst.Add(i);
|
2266
|
|
2267
|
Assert.AreEqual(EnumerationDirection.Forwards, lst.Direction);
|
2268
|
Assert.AreEqual(EnumerationDirection.Forwards, lst[3, 4].Direction);
|
2269
|
Assert.AreEqual(EnumerationDirection.Backwards, lst[3, 4].Backwards().Direction);
|
2270
|
Assert.AreEqual(EnumerationDirection.Backwards, lst.Backwards().Direction);
|
2271
|
Assert.AreEqual(4, lst[3, 4].Count);
|
2272
|
Assert.AreEqual(4, lst[3, 4].Backwards().Count);
|
2273
|
Assert.AreEqual(10, lst.Backwards().Count);
|
2274
|
}
|
2275
|
|
2276
|
|
2277
|
[Test]
|
2278
|
[ExpectedException(typeof(CollectionModifiedException))]
|
2279
|
public void MoveNextAfterUpdate()
|
2280
|
{
|
2281
|
for (int i = 0; i < 10; i++) lst.Add(i);
|
2282
|
|
2283
|
foreach (int i in lst)
|
2284
|
{
|
2285
|
lst.Add(45 + i);
|
2286
|
}
|
2287
|
}
|
2288
|
}
|
2289
|
}
|
2290
|
|
2291
|
|
2292
|
|
2293
|
|
2294
|
namespace View
|
2295
|
{
|
2296
|
[TestFixture]
|
2297
|
public class Simple
|
2298
|
{
|
2299
|
ArrayList<int> list, view;
|
2300
|
|
2301
|
|
2302
|
[SetUp]
|
2303
|
public void Init()
|
2304
|
{
|
2305
|
list = new ArrayList<int>();
|
2306
|
list.Add(0); list.Add(1); list.Add(2); list.Add(3);
|
2307
|
view = (ArrayList<int>)list.View(1, 2);
|
2308
|
}
|
2309
|
|
2310
|
|
2311
|
[TearDown]
|
2312
|
public void Dispose()
|
2313
|
{
|
2314
|
list = view = null;
|
2315
|
}
|
2316
|
|
2317
|
|
2318
|
void check()
|
2319
|
{
|
2320
|
Assert.IsTrue(list.Check());
|
2321
|
Assert.IsTrue(view.Check());
|
2322
|
}
|
2323
|
|
2324
|
|
2325
|
//static void pint(IEnumerable<int> l) { foreach (int cell in l) Console.WriteLine(cell); }
|
2326
|
|
2327
|
[Test]
|
2328
|
public void InsertPointer()
|
2329
|
{
|
2330
|
IList<int> view2 = list.View(2, 0);
|
2331
|
list.Insert(view2, 7);
|
2332
|
check();
|
2333
|
list.Insert(list, 8);
|
2334
|
check();
|
2335
|
view.Insert(view2, 9);
|
2336
|
check();
|
2337
|
view.Insert(list.View(3, 2), 10);
|
2338
|
check();
|
2339
|
view.Insert(list.ViewOf(0), 11);
|
2340
|
check();
|
2341
|
Assert.IsTrue(IC.eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8));
|
2342
|
Assert.IsTrue(IC.eq(view, 11, 1, 9, 7, 2, 10));
|
2343
|
}
|
2344
|
|
2345
|
[Test]
|
2346
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
2347
|
public void InsertPointerBad1()
|
2348
|
{
|
2349
|
view.Insert(list.View(0, 0), 7);
|
2350
|
}
|
2351
|
|
2352
|
[Test]
|
2353
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
2354
|
public void InsertPointerBad2()
|
2355
|
{
|
2356
|
view.Insert(list, 7);
|
2357
|
}
|
2358
|
|
2359
|
[Test]
|
2360
|
[ExpectedException(typeof(IncompatibleViewException))]
|
2361
|
public void InsertPointerBad3()
|
2362
|
{
|
2363
|
list.Insert(new ArrayList<int>(), 7);
|
2364
|
}
|
2365
|
|
2366
|
[Test]
|
2367
|
[ExpectedException(typeof(IncompatibleViewException))]
|
2368
|
public void InsertPointerBad4()
|
2369
|
{
|
2370
|
list.Insert(new ArrayList<int>().View(0, 0), 7);
|
2371
|
}
|
2372
|
|
2373
|
|
2374
|
[Test]
|
2375
|
public void Span()
|
2376
|
{
|
2377
|
IList<int> span = list.View(1, 0).Span(list.View(2, 0));
|
2378
|
Assert.IsTrue(span.Check());
|
2379
|
Assert.AreEqual(1, span.Offset);
|
2380
|
Assert.AreEqual(1, span.Count);
|
2381
|
span = list.View(0, 2).Span(list.View(2, 2));
|
2382
|
Assert.IsTrue(span.Check());
|
2383
|
Assert.AreEqual(0, span.Offset);
|
2384
|
Assert.AreEqual(4, span.Count);
|
2385
|
span = list.View(3, 1).Span(list.View(1, 1));
|
2386
|
Assert.IsNull(span);
|
2387
|
}
|
2388
|
|
2389
|
[Test]
|
2390
|
public void ViewOf()
|
2391
|
{
|
2392
|
for (int i = 0; i < 4; i++)
|
2393
|
list.Add(i);
|
2394
|
IList<int> v = view.ViewOf(2);
|
2395
|
Assert.IsTrue(v.Check());
|
2396
|
Assert.IsTrue(IC.eq(v, 2));
|
2397
|
Assert.AreEqual(2, v.Offset);
|
2398
|
v = list.ViewOf(2);
|
2399
|
Assert.IsTrue(v.Check());
|
2400
|
Assert.IsTrue(IC.eq(v, 2));
|
2401
|
Assert.AreEqual(2, v.Offset);
|
2402
|
v = list.LastViewOf(2);
|
2403
|
Assert.IsTrue(v.Check());
|
2404
|
Assert.IsTrue(IC.eq(v, 2));
|
2405
|
Assert.AreEqual(6, v.Offset);
|
2406
|
}
|
2407
|
|
2408
|
[Test]
|
2409
|
public void ArrayStuff()
|
2410
|
{
|
2411
|
Assert.IsTrue(IC.eq(view.ToArray(), 1, 2));
|
2412
|
int[] extarray = new int[5];
|
2413
|
view.CopyTo(extarray, 2);
|
2414
|
Assert.IsTrue(IC.eq(extarray, 0, 0, 1, 2, 0));
|
2415
|
}
|
2416
|
|
2417
|
[Test]
|
2418
|
public void BadViewOf()
|
2419
|
{
|
2420
|
Assert.IsNull(view.ViewOf(5));
|
2421
|
Assert.IsNull(view.LastViewOf(5));
|
2422
|
Assert.IsNull(view.ViewOf(3));
|
2423
|
Assert.IsNull(view.LastViewOf(3));
|
2424
|
Assert.IsNull(view.ViewOf(0));
|
2425
|
Assert.IsNull(view.LastViewOf(0));
|
2426
|
}
|
2427
|
|
2428
|
[Test]
|
2429
|
public void Add()
|
2430
|
{
|
2431
|
check();
|
2432
|
Assert.IsTrue(IC.eq(list, 0, 1, 2, 3));
|
2433
|
Assert.IsTrue(IC.eq(view, 1, 2));
|
2434
|
view.InsertFirst(10);
|
2435
|
check();
|
2436
|
Assert.IsTrue(IC.eq(list, 0, 10, 1, 2, 3));
|
2437
|
Assert.IsTrue(IC.eq(view, 10, 1, 2));
|
2438
|
view.Clear();
|
2439
|
Assert.IsFalse(view.IsReadOnly);
|
2440
|
Assert.IsTrue(view.AllowsDuplicates);
|
2441
|
Assert.IsTrue(view.IsEmpty);
|
2442
|
check();
|
2443
|
Assert.IsTrue(IC.eq(list, 0, 3));
|
2444
|
Assert.IsTrue(IC.eq(view));
|
2445
|
view.Add(8);
|
2446
|
Assert.IsFalse(view.IsEmpty);
|
2447
|
Assert.IsTrue(view.AllowsDuplicates);
|
2448
|
Assert.IsFalse(view.IsReadOnly);
|
2449
|
check();
|
2450
|
Assert.IsTrue(IC.eq(list, 0, 8, 3));
|
2451
|
Assert.IsTrue(IC.eq(view, 8));
|
2452
|
view.Add(12);
|
2453
|
check();
|
2454
|
Assert.IsTrue(IC.eq(list, 0, 8, 12, 3));
|
2455
|
Assert.IsTrue(IC.eq(view, 8, 12));
|
2456
|
view./*ViewOf(12)*/InsertLast(15);
|
2457
|
check();
|
2458
|
Assert.IsTrue(IC.eq(list, 0, 8, 12, 15, 3));
|
2459
|
Assert.IsTrue(IC.eq(view, 8, 12, 15));
|
2460
|
view.ViewOf(12).InsertFirst(18);
|
2461
|
check();
|
2462
|
Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 3));
|
2463
|
Assert.IsTrue(IC.eq(view, 8, 18, 12, 15));
|
2464
|
|
2465
|
ArrayList<int> lst2 = new ArrayList<int>();
|
2466
|
|
2467
|
lst2.Add(90); lst2.Add(92);
|
2468
|
view.AddAll(lst2);
|
2469
|
check();
|
2470
|
Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 3));
|
2471
|
Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92));
|
2472
|
view.InsertLast(66);
|
2473
|
check();
|
2474
|
|
2475
|
Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3));
|
2476
|
Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92, 66));
|
2477
|
}
|
2478
|
|
2479
|
|
2480
|
[Test]
|
2481
|
public void Bxxx()
|
2482
|
{
|
2483
|
Assert.IsTrue(IC.eq(view.Backwards(), 2, 1));
|
2484
|
Assert.AreSame(list, view.Underlying);
|
2485
|
Assert.IsNull(list.Underlying);
|
2486
|
Assert.AreEqual(EnumerationDirection.Forwards, view.Direction);
|
2487
|
Assert.AreEqual(EnumerationDirection.Backwards, view.Backwards().Direction);
|
2488
|
Assert.AreEqual(0, list.Offset);
|
2489
|
Assert.AreEqual(1, view.Offset);
|
2490
|
}
|
2491
|
|
2492
|
|
2493
|
[Test]
|
2494
|
public void Contains()
|
2495
|
{
|
2496
|
Assert.IsTrue(view.Contains(1));
|
2497
|
Assert.IsFalse(view.Contains(0));
|
2498
|
|
2499
|
ArrayList<int> lst2 = new ArrayList<int>();
|
2500
|
|
2501
|
lst2.Add(2);
|
2502
|
Assert.IsTrue(view.ContainsAll(lst2));
|
2503
|
lst2.Add(3);
|
2504
|
Assert.IsFalse(view.ContainsAll(lst2));
|
2505
|
Assert.AreEqual(Speed.Linear, view.ContainsSpeed);
|
2506
|
Assert.AreEqual(2, view.Count);
|
2507
|
view.Add(1);
|
2508
|
Assert.AreEqual(1, view.ContainsCount(2));
|
2509
|
Assert.AreEqual(2, view.ContainsCount(1));
|
2510
|
Assert.AreEqual(3, view.Count);
|
2511
|
}
|
2512
|
|
2513
|
|
2514
|
[Test]
|
2515
|
public void CreateView()
|
2516
|
{
|
2517
|
ArrayList<int> view2 = (ArrayList<int>)view.View(1, 0);
|
2518
|
|
2519
|
Assert.AreSame(list, view2.Underlying);
|
2520
|
}
|
2521
|
|
2522
|
|
2523
|
[Test]
|
2524
|
public void FIFO()
|
2525
|
{
|
2526
|
Assert.IsFalse(view.FIFO);
|
2527
|
view.FIFO = true;
|
2528
|
view.Add(23); view.Add(24); view.Add(25);
|
2529
|
check();
|
2530
|
Assert.IsTrue(IC.eq(view, 1, 2, 23, 24, 25));
|
2531
|
Assert.AreEqual(1, view.Remove());
|
2532
|
check();
|
2533
|
Assert.IsTrue(IC.eq(view, 2, 23, 24, 25));
|
2534
|
view.FIFO = false;
|
2535
|
Assert.IsFalse(view.FIFO);
|
2536
|
Assert.AreEqual(25, view.Remove());
|
2537
|
check();
|
2538
|
Assert.IsTrue(IC.eq(view, 2, 23, 24));
|
2539
|
}
|
2540
|
|
2541
|
|
2542
|
[Test]
|
2543
|
public void MapEtc()
|
2544
|
{
|
2545
|
ArrayList<double> dbl = (ArrayList<double>)view.Map(new Fun<int, double>(delegate(int i) { return i / 10.0; }));
|
2546
|
|
2547
|
Assert.IsTrue(dbl.Check());
|
2548
|
Assert.AreEqual(0.1, dbl[0]);
|
2549
|
Assert.AreEqual(0.2, dbl[1]);
|
2550
|
for (int i = 0; i < 10; i++) view.Add(i);
|
2551
|
|
2552
|
list = (ArrayList<int>)view.FindAll(new Fun<int, bool>(delegate(int i) { return i % 4 == 1; }));
|
2553
|
Assert.IsTrue(list.Check());
|
2554
|
Assert.IsTrue(IC.eq(list, 1, 1, 5, 9));
|
2555
|
}
|
2556
|
|
2557
|
|
2558
|
[Test]
|
2559
|
public void FL()
|
2560
|
{
|
2561
|
Assert.AreEqual(1, view.First);
|
2562
|
Assert.AreEqual(2, view.Last);
|
2563
|
}
|
2564
|
|
2565
|
|
2566
|
[Test]
|
2567
|
public void Indexing()
|
2568
|
{
|
2569
|
list.Clear();
|
2570
|
for (int i = 0; i < 20; i++) list.Add(i);
|
2571
|
|
2572
|
view = (ArrayList<int>)list.View(5, 7);
|
2573
|
for (int i = 0; i < 7; i++) Assert.AreEqual(i + 5, view[i]);
|
2574
|
|
2575
|
for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.IndexOf(i + 5));
|
2576
|
|
2577
|
for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.LastIndexOf(i + 5));
|
2578
|
}
|
2579
|
|
2580
|
|
2581
|
[Test]
|
2582
|
public void Insert()
|
2583
|
{
|
2584
|
view.Insert(0, 34);
|
2585
|
view.Insert(1, 35);
|
2586
|
view.Insert(4, 36);
|
2587
|
Assert.IsTrue(view.Check());
|
2588
|
Assert.IsTrue(IC.eq(view, 34, 35, 1, 2, 36));
|
2589
|
|
2590
|
IList<int> list2 = new ArrayList<int>();
|
2591
|
|
2592
|
list2.AddAll(view);
|
2593
|
view.InsertAll(3, list2);
|
2594
|
Assert.IsTrue(view.Check());
|
2595
|
Assert.IsTrue(IC.eq(view, 34, 35, 1, 34, 35, 1, 2, 36, 2, 36));
|
2596
|
}
|
2597
|
|
2598
|
[Test]
|
2599
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
2600
|
public void RangeCheck1()
|
2601
|
{
|
2602
|
IList<int> lst = new ArrayList<int>();
|
2603
|
lst.Add(2);
|
2604
|
lst = lst.View(1, 1);
|
2605
|
}
|
2606
|
|
2607
|
[Test]
|
2608
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
2609
|
public void RangeCheck2()
|
2610
|
{
|
2611
|
IList<int> lst = new ArrayList<int>();
|
2612
|
lst.Add(2);
|
2613
|
lst = lst.View(1, -1);
|
2614
|
}
|
2615
|
|
2616
|
|
2617
|
[Test]
|
2618
|
public void Sort()
|
2619
|
{
|
2620
|
view.Add(45); view.Add(47); view.Add(46); view.Add(48);
|
2621
|
Assert.IsFalse(view.IsSorted(new IC()));
|
2622
|
view.Sort(new IC());
|
2623
|
check();
|
2624
|
Assert.IsTrue(IC.eq(list, 0, 1, 2, 45, 46, 47, 48, 3));
|
2625
|
Assert.IsTrue(IC.eq(view, 1, 2, 45, 46, 47, 48));
|
2626
|
}
|
2627
|
|
2628
|
|
2629
|
[Test]
|
2630
|
public void Remove()
|
2631
|
{
|
2632
|
view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
|
2633
|
Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
|
2634
|
Assert.IsTrue(view.Remove(1));
|
2635
|
check();
|
2636
|
Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 3, 0));
|
2637
|
Assert.IsTrue(view.Remove(1));
|
2638
|
check();
|
2639
|
Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3, 0));
|
2640
|
Assert.IsTrue(view.Remove(0));
|
2641
|
check();
|
2642
|
Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3));
|
2643
|
view.RemoveAllCopies(3);
|
2644
|
check();
|
2645
|
Assert.IsTrue(IC.eq(view, 1, 2, 5));
|
2646
|
Assert.IsTrue(IC.eq(list, 0, 1, 2, 5, 3));
|
2647
|
view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
|
2648
|
Assert.IsTrue(IC.eq(view, 1, 2, 5, 1, 5, 3, 1, 3, 0));
|
2649
|
|
2650
|
view.FIFO = true;
|
2651
|
view.Clear(); view.Add(1); view.Add(2);
|
2652
|
|
2653
|
view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
|
2654
|
Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
|
2655
|
Assert.IsTrue(view.Remove(1));
|
2656
|
check();
|
2657
|
Assert.IsTrue(IC.eq(view, 2, 1, 5, 3, 1, 3, 0));
|
2658
|
Assert.IsTrue(view.Remove(1));
|
2659
|
check();
|
2660
|
Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3, 0));
|
2661
|
Assert.IsTrue(view.Remove(0));
|
2662
|
check();
|
2663
|
Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3));
|
2664
|
view.RemoveAllCopies(3);
|
2665
|
check();
|
2666
|
Assert.IsTrue(IC.eq(view, 2, 5, 1));
|
2667
|
Assert.IsTrue(IC.eq(list, 0, 2, 5, 1, 3));
|
2668
|
view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
|
2669
|
Assert.IsTrue(IC.eq(view, 2, 5, 1, 1, 5, 3, 1, 3, 0));
|
2670
|
|
2671
|
view.FIFO = false;
|
2672
|
|
2673
|
ArrayList<int> l2 = new ArrayList<int>();
|
2674
|
|
2675
|
l2.Add(1); l2.Add(2); l2.Add(2); l2.Add(3); l2.Add(1);
|
2676
|
view.RemoveAll(l2);
|
2677
|
check();
|
2678
|
Assert.IsTrue(IC.eq(view, 5, 5, 1, 3, 0));
|
2679
|
view.RetainAll(l2);
|
2680
|
check();
|
2681
|
Assert.IsTrue(IC.eq(view, 1, 3));
|
2682
|
view.Add(2); view.Add(4); view.Add(5);
|
2683
|
Assert.AreEqual(1, view.RemoveAt(0));
|
2684
|
Assert.AreEqual(5, view.RemoveAt(3));
|
2685
|
Assert.AreEqual(2, view.RemoveAt(1));
|
2686
|
check();
|
2687
|
Assert.IsTrue(IC.eq(view, 3, 4));
|
2688
|
view.Add(8);
|
2689
|
Assert.AreEqual(3, view.RemoveFirst());
|
2690
|
Assert.AreEqual(8, view.RemoveLast());
|
2691
|
view.Add(2); view.Add(5); view.Add(3); view.Add(1);
|
2692
|
view.RemoveInterval(1, 2);
|
2693
|
check();
|
2694
|
Assert.IsTrue(IC.eq(view, 4, 3, 1));
|
2695
|
}
|
2696
|
|
2697
|
|
2698
|
[Test]
|
2699
|
public void Reverse()
|
2700
|
{
|
2701
|
view.Clear();
|
2702
|
for (int i = 0; i < 10; i++) view.Add(10 + i);
|
2703
|
|
2704
|
view.View(3, 4).Reverse();
|
2705
|
check();
|
2706
|
Assert.IsTrue(IC.eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19));
|
2707
|
view.Reverse();
|
2708
|
Assert.IsTrue(IC.eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10));
|
2709
|
Assert.IsTrue(IC.eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3));
|
2710
|
}
|
2711
|
|
2712
|
|
2713
|
[Test]
|
2714
|
public void Slide()
|
2715
|
{
|
2716
|
view.Slide(1);
|
2717
|
check();
|
2718
|
Assert.IsTrue(IC.eq(view, 2, 3));
|
2719
|
view.Slide(-2);
|
2720
|
check();
|
2721
|
Assert.IsTrue(IC.eq(view, 0, 1));
|
2722
|
view.Slide(0, 3);
|
2723
|
check();
|
2724
|
Assert.IsTrue(IC.eq(view, 0, 1, 2));
|
2725
|
view.Slide(2, 1);
|
2726
|
check();
|
2727
|
Assert.IsTrue(IC.eq(view, 2));
|
2728
|
Assert.AreEqual(view, view.Slide(-1, 0));
|
2729
|
check();
|
2730
|
Assert.IsTrue(IC.eq(view));
|
2731
|
view.Add(28);
|
2732
|
Assert.IsTrue(IC.eq(list, 0, 28, 1, 2, 3));
|
2733
|
}
|
2734
|
[Test]
|
2735
|
public void Iterate()
|
2736
|
{
|
2737
|
list.Clear();
|
2738
|
view = null;
|
2739
|
foreach (int i in new int[] { 2, 4, 8, 13, 6, 1, 2, 7 }) list.Add(i);
|
2740
|
|
2741
|
view = (ArrayList<int>)list.View(list.Count - 2, 2);
|
2742
|
while (true)
|
2743
|
{
|
2744
|
if ((view.Last - view.First) % 2 == 1)
|
2745
|
view.Insert(1, 666);
|
2746
|
check();
|
2747
|
if (view.Offset == 0)
|
2748
|
break;
|
2749
|
else
|
2750
|
view.Slide(-1, 2);
|
2751
|
}
|
2752
|
Assert.IsTrue(list.Check());
|
2753
|
Assert.IsTrue(IC.eq(list, 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7));
|
2754
|
}
|
2755
|
|
2756
|
|
2757
|
[Test]
|
2758
|
public void SyncRoot()
|
2759
|
{
|
2760
|
Assert.AreSame(((System.Collections.IList)view).SyncRoot, ((System.Collections.IList)list).SyncRoot);
|
2761
|
}
|
2762
|
}
|
2763
|
[TestFixture]
|
2764
|
public class MulipleViews
|
2765
|
{
|
2766
|
IList<int> list;
|
2767
|
IList<int>[][] views;
|
2768
|
[SetUp]
|
2769
|
public void Init()
|
2770
|
{
|
2771
|
list = new ArrayList<int>();
|
2772
|
for (int i = 0; i < 6; i++)
|
2773
|
list.Add(i);
|
2774
|
views = new IList<int>[7][];
|
2775
|
for (int i = 0; i < 7; i++)
|
2776
|
{
|
2777
|
views[i] = new IList<int>[7 - i];
|
2778
|
for (int j = 0; j < 7 - i; j++)
|
2779
|
views[i][j] = list.View(i, j);
|
2780
|
}
|
2781
|
}
|
2782
|
[TearDown]
|
2783
|
public void Dispose()
|
2784
|
{
|
2785
|
list = null;
|
2786
|
views = null;
|
2787
|
}
|
2788
|
[Test]
|
2789
|
public void Insert()
|
2790
|
{
|
2791
|
Assert.IsTrue(list.Check(), "list check before insert");
|
2792
|
list.Insert(3, 777);
|
2793
|
Assert.IsTrue(list.Check(), "list check after insert");
|
2794
|
for (int i = 0; i < 7; i++)
|
2795
|
for (int j = 0; j < 7 - i; j++)
|
2796
|
{
|
2797
|
Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2798
|
Assert.AreEqual(i < 3 && i + j > 3 ? j + 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2799
|
}
|
2800
|
}
|
2801
|
[Test]
|
2802
|
public void RemoveAt()
|
2803
|
{
|
2804
|
Assert.IsTrue(list.Check(), "list check before remove");
|
2805
|
list.RemoveAt(3);
|
2806
|
Assert.IsTrue(list.Check(), "list check after remove");
|
2807
|
for (int i = 0; i < 7; i++)
|
2808
|
for (int j = 0; j < 7 - i; j++)
|
2809
|
{
|
2810
|
Assert.AreEqual(i <= 3 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2811
|
Assert.AreEqual(i <= 3 && i + j > 3 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2812
|
}
|
2813
|
}
|
2814
|
|
2815
|
[Test]
|
2816
|
public void RemoveInterval()
|
2817
|
{
|
2818
|
Assert.IsTrue(list.Check(), "list check before remove");
|
2819
|
list.RemoveInterval(3, 2);
|
2820
|
Assert.IsTrue(list.Check(), "list check after remove");
|
2821
|
for (int i = 0; i < 7; i++)
|
2822
|
for (int j = 0; j < 7 - i; j++)
|
2823
|
{
|
2824
|
Assert.AreEqual(i <= 3 ? i : i <= 5 ? 3 : i - 2, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2825
|
Assert.AreEqual(j == 0 ? 0 : i <= 3 && i + j > 4 ? j - 2 : i > 4 || i + j <= 3 ? j : j - 1, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2826
|
}
|
2827
|
}
|
2828
|
|
2829
|
|
2830
|
[Test]
|
2831
|
public void InsertAtEnd()
|
2832
|
{
|
2833
|
Assert.IsTrue(list.Check(), "list check before insert");
|
2834
|
list.InsertLast(777);
|
2835
|
Assert.IsTrue(list.Check(), "list check after insert");
|
2836
|
for (int i = 0; i < 7; i++)
|
2837
|
for (int j = 0; j < 7 - i; j++)
|
2838
|
{
|
2839
|
Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2840
|
Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2841
|
}
|
2842
|
}
|
2843
|
[Test]
|
2844
|
public void RemoveAtEnd()
|
2845
|
{
|
2846
|
Assert.IsTrue(list.Check(), "list check before remove");
|
2847
|
list.RemoveAt(5);
|
2848
|
Assert.IsTrue(list.Check(), "list check after remove");
|
2849
|
for (int i = 0; i < 7; i++)
|
2850
|
for (int j = 0; j < 7 - i; j++)
|
2851
|
{
|
2852
|
Assert.AreEqual(i <= 5 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2853
|
Assert.AreEqual(i <= 5 && i + j > 5 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2854
|
}
|
2855
|
}
|
2856
|
[Test]
|
2857
|
public void InsertAtStart()
|
2858
|
{
|
2859
|
Assert.IsTrue(list.Check(), "list check before insert");
|
2860
|
list.Insert(0, 777);
|
2861
|
Assert.IsTrue(list.Check(), "list check after insert");
|
2862
|
for (int i = 0; i < 7; i++)
|
2863
|
for (int j = 0; j < 7 - i; j++)
|
2864
|
{
|
2865
|
Assert.AreEqual(i == 0 && j == 0 ? 0 : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2866
|
Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2867
|
}
|
2868
|
}
|
2869
|
[Test]
|
2870
|
public void RemoveAtStart()
|
2871
|
{
|
2872
|
Assert.IsTrue(list.Check(), "list check before remove");
|
2873
|
list.RemoveAt(0);
|
2874
|
Assert.IsTrue(list.Check(), "list check after remove");
|
2875
|
for (int i = 0; i < 7; i++)
|
2876
|
for (int j = 0; j < 7 - i; j++)
|
2877
|
{
|
2878
|
Assert.AreEqual(i == 0 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2879
|
Assert.AreEqual(i == 0 && j > 0 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2880
|
}
|
2881
|
}
|
2882
|
[Test]
|
2883
|
public void Clear()
|
2884
|
{
|
2885
|
Assert.IsTrue(list.Check(), "list check before clear");
|
2886
|
views[2][3].Clear();
|
2887
|
Assert.IsTrue(list.Check(), "list check after clear");
|
2888
|
for (int i = 0; i < 7; i++)
|
2889
|
for (int j = 0; j < 7 - i; j++)
|
2890
|
{
|
2891
|
Assert.AreEqual(i < 2 ? i : i < 6 ? 2 : i - 3, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2892
|
Assert.AreEqual(s(i, j), views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2893
|
}
|
2894
|
}
|
2895
|
|
2896
|
private int s(int i, int j)
|
2897
|
{
|
2898
|
if (j == 0) return 0;
|
2899
|
int k = i + j - 1; //end
|
2900
|
if (i > 4 || k <= 1) return j;
|
2901
|
if (i >= 2) return k > 4 ? k - 4 : 0;
|
2902
|
if (i <= 2) return k >= 4 ? j - 3 : 2 - i;
|
2903
|
return -1;
|
2904
|
}
|
2905
|
[Test]
|
2906
|
public void InsertAll()
|
2907
|
{
|
2908
|
ArrayList<int> list2 = new ArrayList<int>();
|
2909
|
for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
|
2910
|
Assert.IsTrue(list.Check(), "list check before insertAll");
|
2911
|
list.InsertAll(3, list2);
|
2912
|
Assert.IsTrue(list.Check(), "list check after insertAll");
|
2913
|
for (int i = 0; i < 7; i++)
|
2914
|
for (int j = 0; j < 7 - i; j++)
|
2915
|
{
|
2916
|
Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2917
|
Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2918
|
}
|
2919
|
}
|
2920
|
|
2921
|
[Test]
|
2922
|
public void AddAll()
|
2923
|
{
|
2924
|
ArrayList<int> list2 = new ArrayList<int>();
|
2925
|
for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
|
2926
|
Assert.IsTrue(list.Check(), "list check before AddAll");
|
2927
|
list.View(1, 2).AddAll(list2);
|
2928
|
Assert.IsTrue(list.Check(), "list check after AddAll");
|
2929
|
for (int i = 0; i < 7; i++)
|
2930
|
for (int j = 0; j < 7 - i; j++)
|
2931
|
{
|
2932
|
Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
2933
|
Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
|
2934
|
}
|
2935
|
}
|
2936
|
|
2937
|
[Test]
|
2938
|
public void RemoveAll1()
|
2939
|
{
|
2940
|
ArrayList<int> list2 = new ArrayList<int>();
|
2941
|
list2.Add(1); list2.Add(3); list2.Add(4);
|
2942
|
|
2943
|
for (int i = 0; i < 7; i++)
|
2944
|
{
|
2945
|
for (int j = 0; j < 7 - i; j++)
|
2946
|
{
|
2947
|
list = new ArrayList<int>();
|
2948
|
for (int k = 0; k < 6; k++) list.Add(k);
|
2949
|
ArrayList<int> v = (ArrayList<int>)list.View(i, j);
|
2950
|
list.RemoveAll(list2);
|
2951
|
Assert.IsTrue(list.Check(), "list check after RemoveAll, i=" + i + ", j=" + j);
|
2952
|
}
|
2953
|
}
|
2954
|
}
|
2955
|
[Test]
|
2956
|
public void RemoveAll2()
|
2957
|
{
|
2958
|
ArrayList<int> list2 = new ArrayList<int>();
|
2959
|
list2.Add(1); list2.Add(3); list2.Add(4);
|
2960
|
Assert.IsTrue(list.Check(), "list check before RemoveAll");
|
2961
|
list.RemoveAll(list2);
|
2962
|
|
2963
|
Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
|
2964
|
Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
|
2965
|
Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
|
2966
|
Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
|
2967
|
Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
|
2968
|
Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
|
2969
|
Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
|
2970
|
Assert.AreEqual(1, views[1][0].Offset, "view [1][0] offset");
|
2971
|
Assert.AreEqual(1, views[1][1].Offset, "view [1][1] offset");
|
2972
|
Assert.AreEqual(1, views[1][2].Offset, "view [1][2] offset");
|
2973
|
Assert.AreEqual(1, views[1][3].Offset, "view [1][3] offset");
|
2974
|
Assert.AreEqual(1, views[1][4].Offset, "view [1][4] offset");
|
2975
|
Assert.AreEqual(1, views[1][5].Offset, "view [1][5] offset");
|
2976
|
Assert.AreEqual(1, views[2][0].Offset, "view [2][0] offset");
|
2977
|
Assert.AreEqual(1, views[2][1].Offset, "view [2][1] offset");
|
2978
|
Assert.AreEqual(1, views[2][2].Offset, "view [2][2] offset");
|
2979
|
Assert.AreEqual(1, views[2][3].Offset, "view [2][3] offset");
|
2980
|
Assert.AreEqual(1, views[2][4].Offset, "view [2][4] offset");
|
2981
|
Assert.AreEqual(2, views[3][0].Offset, "view [3][0] offset");
|
2982
|
Assert.AreEqual(2, views[3][1].Offset, "view [3][1] offset");
|
2983
|
Assert.AreEqual(2, views[3][2].Offset, "view [3][2] offset");
|
2984
|
Assert.AreEqual(2, views[3][3].Offset, "view [3][3] offset");
|
2985
|
Assert.AreEqual(2, views[4][0].Offset, "view [4][0] offset");
|
2986
|
Assert.AreEqual(2, views[4][1].Offset, "view [4][1] offset");
|
2987
|
Assert.AreEqual(2, views[4][2].Offset, "view [4][2] offset");
|
2988
|
Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
|
2989
|
Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
|
2990
|
Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
|
2991
|
|
2992
|
Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
|
2993
|
Assert.AreEqual(1, views[0][1].Count, "view [0][1] count");
|
2994
|
Assert.AreEqual(1, views[0][2].Count, "view [0][2] count");
|
2995
|
Assert.AreEqual(2, views[0][3].Count, "view [0][3] count");
|
2996
|
Assert.AreEqual(2, views[0][4].Count, "view [0][4] count");
|
2997
|
Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
|
2998
|
Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
|
2999
|
Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
|
3000
|
Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
|
3001
|
Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
|
3002
|
Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
|
3003
|
Assert.AreEqual(1, views[1][4].Count, "view [1][4] count");
|
3004
|
Assert.AreEqual(2, views[1][5].Count, "view [1][5] count");
|
3005
|
Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
|
3006
|
Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
|
3007
|
Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
|
3008
|
Assert.AreEqual(1, views[2][3].Count, "view [2][3] count");
|
3009
|
Assert.AreEqual(2, views[2][4].Count, "view [2][4] count");
|
3010
|
Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
|
3011
|
Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
|
3012
|
Assert.AreEqual(0, views[3][2].Count, "view [3][2] count");
|
3013
|
Assert.AreEqual(1, views[3][3].Count, "view [3][3] count");
|
3014
|
Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
|
3015
|
Assert.AreEqual(0, views[4][1].Count, "view [4][1] count");
|
3016
|
Assert.AreEqual(1, views[4][2].Count, "view [4][2] count");
|
3017
|
Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
|
3018
|
Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
|
3019
|
Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
|
3020
|
|
3021
|
Assert.IsTrue(list.Check(), "list check after RemoveAll");
|
3022
|
}
|
3023
|
|
3024
|
[Test]
|
3025
|
public void RetainAll()
|
3026
|
{
|
3027
|
ArrayList<int> list2 = new ArrayList<int>();
|
3028
|
list2.Add(2); list2.Add(4); list2.Add(5);
|
3029
|
Assert.IsTrue(list.Check(), "list check before RetainAll");
|
3030
|
list.RetainAll(list2);
|
3031
|
|
3032
|
Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
|
3033
|
Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
|
3034
|
Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
|
3035
|
Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
|
3036
|
Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
|
3037
|
Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
|
3038
|
Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
|
3039
|
Assert.AreEqual(0, views[1][0].Offset, "view [1][0] offset");
|
3040
|
Assert.AreEqual(0, views[1][1].Offset, "view [1][1] offset");
|
3041
|
Assert.AreEqual(0, views[1][2].Offset, "view [1][2] offset");
|
3042
|
Assert.AreEqual(0, views[1][3].Offset, "view [1][3] offset");
|
3043
|
Assert.AreEqual(0, views[1][4].Offset, "view [1][4] offset");
|
3044
|
Assert.AreEqual(0, views[1][5].Offset, "view [1][5] offset");
|
3045
|
Assert.AreEqual(0, views[2][0].Offset, "view [2][0] offset");
|
3046
|
Assert.AreEqual(0, views[2][1].Offset, "view [2][1] offset");
|
3047
|
Assert.AreEqual(0, views[2][2].Offset, "view [2][2] offset");
|
3048
|
Assert.AreEqual(0, views[2][3].Offset, "view [2][3] offset");
|
3049
|
Assert.AreEqual(0, views[2][4].Offset, "view [2][4] offset");
|
3050
|
Assert.AreEqual(1, views[3][0].Offset, "view [3][0] offset");
|
3051
|
Assert.AreEqual(1, views[3][1].Offset, "view [3][1] offset");
|
3052
|
Assert.AreEqual(1, views[3][2].Offset, "view [3][2] offset");
|
3053
|
Assert.AreEqual(1, views[3][3].Offset, "view [3][3] offset");
|
3054
|
Assert.AreEqual(1, views[4][0].Offset, "view [4][0] offset");
|
3055
|
Assert.AreEqual(1, views[4][1].Offset, "view [4][1] offset");
|
3056
|
Assert.AreEqual(1, views[4][2].Offset, "view [4][2] offset");
|
3057
|
Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
|
3058
|
Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
|
3059
|
Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
|
3060
|
|
3061
|
Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
|
3062
|
Assert.AreEqual(0, views[0][1].Count, "view [0][1] count");
|
3063
|
Assert.AreEqual(0, views[0][2].Count, "view [0][2] count");
|
3064
|
Assert.AreEqual(1, views[0][3].Count, "view [0][3] count");
|
3065
|
Assert.AreEqual(1, views[0][4].Count, "view [0][4] count");
|
3066
|
Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
|
3067
|
Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
|
3068
|
Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
|
3069
|
Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
|
3070
|
Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
|
3071
|
Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
|
3072
|
Assert.AreEqual(2, views[1][4].Count, "view [1][4] count");
|
3073
|
Assert.AreEqual(3, views[1][5].Count, "view [1][5] count");
|
3074
|
Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
|
3075
|
Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
|
3076
|
Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
|
3077
|
Assert.AreEqual(2, views[2][3].Count, "view [2][3] count");
|
3078
|
Assert.AreEqual(3, views[2][4].Count, "view [2][4] count");
|
3079
|
Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
|
3080
|
Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
|
3081
|
Assert.AreEqual(1, views[3][2].Count, "view [3][2] count");
|
3082
|
Assert.AreEqual(2, views[3][3].Count, "view [3][3] count");
|
3083
|
Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
|
3084
|
Assert.AreEqual(1, views[4][1].Count, "view [4][1] count");
|
3085
|
Assert.AreEqual(2, views[4][2].Count, "view [4][2] count");
|
3086
|
Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
|
3087
|
Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
|
3088
|
Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
|
3089
|
|
3090
|
Assert.IsTrue(list.Check(), "list check after RetainAll");
|
3091
|
}
|
3092
|
|
3093
|
[Test]
|
3094
|
public void RemoveAllCopies()
|
3095
|
{
|
3096
|
ArrayList<int> list2 = new ArrayList<int>();
|
3097
|
list2.Add(0); list2.Add(2); list2.Add(2); list2.Add(2); list2.Add(5); list2.Add(2); list2.Add(1);
|
3098
|
for (int i = 0; i < 7; i++)
|
3099
|
{
|
3100
|
for (int j = 0; j < 7 - i; j++)
|
3101
|
{
|
3102
|
list = new ArrayList<int>();
|
3103
|
list.AddAll(list2);
|
3104
|
ArrayList<int> v = (ArrayList<int>)list.View(i, j);
|
3105
|
list.RemoveAllCopies(2);
|
3106
|
Assert.AreEqual((i == 0 && j > 0 ? 1 : 0) + (i <= 4 && i + j > 4 ? 1 : 0) + (i <= 6 && i + j > 6 ? 1 : 0), v.Count, "v.Count, i=" + i + ", j=" + j);
|
3107
|
Assert.AreEqual(i == 0 ? 0 : i <= 4 ? 1 : i <= 6 ? 2 : 3, v.Offset, "v.Offset, i=" + i + ", j=" + j);
|
3108
|
Assert.IsTrue(list.Check(), "list check after RemoveAllCopies, i=" + i + ", j=" + j);
|
3109
|
}
|
3110
|
}
|
3111
|
}
|
3112
|
|
3113
|
private void checkDisposed(bool reverse, int start, int count)
|
3114
|
{
|
3115
|
int k = 0;
|
3116
|
for (int i = 0; i < 7; i++)
|
3117
|
for (int j = 0; j < 7 - i; j++)
|
3118
|
{
|
3119
|
if (i + j <= start || i >= start + count || (i <= start && i + j >= start + count) || (reverse && start <= i && start + count >= i + j))
|
3120
|
{
|
3121
|
try
|
3122
|
{
|
3123
|
k = views[i][j].Count;
|
3124
|
}
|
3125
|
catch (ViewDisposedException)
|
3126
|
{
|
3127
|
Assert.Fail("view[" + i + "][" + j + "] threw");
|
3128
|
}
|
3129
|
Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] size");
|
3130
|
if (reverse && ((j > 0 && start <= i && start + count >= i + j) || (j == 0 && start < i && start + count > i)))
|
3131
|
Assert.AreEqual(start + (start + count - i - j), views[i][j].Offset, "view[" + i + "][" + j + "] offset (mirrored)");
|
3132
|
else
|
3133
|
Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
|
3134
|
}
|
3135
|
else
|
3136
|
{
|
3137
|
try
|
3138
|
{
|
3139
|
k = views[i][j].Count;
|
3140
|
Assert.Fail("view[" + i + "][" + j + "] no throw");
|
3141
|
}
|
3142
|
catch (ViewDisposedException) { }
|
3143
|
}
|
3144
|
}
|
3145
|
}
|
3146
|
|
3147
|
[Test]
|
3148
|
public void Reverse()
|
3149
|
{
|
3150
|
int start = 2, count = 3;
|
3151
|
IList<int> list2 = list.View(start, count);
|
3152
|
Assert.IsTrue(list.Check(), "list check before Reverse");
|
3153
|
list2.Reverse();
|
3154
|
Assert.IsTrue(list.Check(), "list check after Reverse");
|
3155
|
checkDisposed(true, start, count);
|
3156
|
}
|
3157
|
[Test]
|
3158
|
public void Sort()
|
3159
|
{
|
3160
|
int start = 2, count = 3;
|
3161
|
IList<int> list2 = list.View(start, count);
|
3162
|
Assert.IsTrue(list.Check(), "list check before Sort");
|
3163
|
list2.Sort();
|
3164
|
Assert.IsTrue(list.Check(), "list check after Sort");
|
3165
|
checkDisposed(false, start, count);
|
3166
|
}
|
3167
|
[Test]
|
3168
|
public void Shuffle()
|
3169
|
{
|
3170
|
int start = 2, count = 3;
|
3171
|
IList<int> list2 = list.View(start, count);
|
3172
|
Assert.IsTrue(list.Check(), "list check before Shuffle");
|
3173
|
list2.Shuffle();
|
3174
|
Assert.IsTrue(list.Check(), "list check after Shuffle");
|
3175
|
checkDisposed(false, start, count);
|
3176
|
}
|
3177
|
|
3178
|
|
3179
|
}
|
3180
|
}
|
3181
|
|
3182
|
|
3183
|
|
3184
|
|
3185
|
namespace ArrayListOfTreesORLists
|
3186
|
{
|
3187
|
[TestFixture]
|
3188
|
public class MultiLevelUnorderedOfUnOrdered
|
3189
|
{
|
3190
|
private ICollection<int> dit, dat, dut;
|
3191
|
|
3192
|
private ICollection<ICollection<int>> Dit, Dat, Dut;
|
3193
|
|
3194
|
|
3195
|
[SetUp]
|
3196
|
public void Init()
|
3197
|
{
|
3198
|
dit = new ArrayList<int>();
|
3199
|
dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
|
3200
|
dut = new ArrayList<int>();
|
3201
|
dit.Add(2); dit.Add(1);
|
3202
|
dat.Add(1); dat.Add(2);
|
3203
|
dut.Add(3);
|
3204
|
Dit = new ArrayList<ICollection<int>>();
|
3205
|
Dat = new ArrayList<ICollection<int>>();
|
3206
|
Dut = new ArrayList<ICollection<int>>();
|
3207
|
}
|
3208
|
|
3209
|
|
3210
|
[Test]
|
3211
|
public void Check()
|
3212
|
{
|
3213
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3214
|
Assert.IsFalse(dit.UnsequencedEquals(dut));
|
3215
|
}
|
3216
|
|
3217
|
|
3218
|
[Test]
|
3219
|
public void Multi()
|
3220
|
{
|
3221
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3222
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3223
|
Assert.IsTrue(Dit.UnsequencedEquals(Dat));
|
3224
|
Assert.IsFalse(Dit.UnsequencedEquals(Dut));
|
3225
|
}
|
3226
|
|
3227
|
|
3228
|
[TearDown]
|
3229
|
public void Dispose()
|
3230
|
{
|
3231
|
dit = dat = dut = null;
|
3232
|
Dit = Dat = Dut = null;
|
3233
|
}
|
3234
|
}
|
3235
|
|
3236
|
|
3237
|
|
3238
|
[TestFixture]
|
3239
|
public class MultiLevelOrderedOfUnOrdered
|
3240
|
{
|
3241
|
private ICollection<int> dit, dat, dut;
|
3242
|
|
3243
|
private ISequenced<ICollection<int>> Dit, Dat, Dut;
|
3244
|
|
3245
|
|
3246
|
[SetUp]
|
3247
|
public void Init()
|
3248
|
{
|
3249
|
dit = new ArrayList<int>();
|
3250
|
dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
|
3251
|
dut = new ArrayList<int>();
|
3252
|
dit.Add(2); dit.Add(1);
|
3253
|
dat.Add(1); dat.Add(2);
|
3254
|
dut.Add(3);
|
3255
|
Dit = new ArrayList<ICollection<int>>();
|
3256
|
Dat = new ArrayList<ICollection<int>>();
|
3257
|
Dut = new ArrayList<ICollection<int>>();
|
3258
|
}
|
3259
|
|
3260
|
|
3261
|
[Test]
|
3262
|
public void Check()
|
3263
|
{
|
3264
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3265
|
Assert.IsFalse(dit.UnsequencedEquals(dut));
|
3266
|
}
|
3267
|
|
3268
|
|
3269
|
[Test]
|
3270
|
public void Multi()
|
3271
|
{
|
3272
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3273
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3274
|
Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
|
3275
|
Assert.IsFalse(Dit.SequencedEquals(Dat));
|
3276
|
Assert.IsTrue(Dit.SequencedEquals(Dut));
|
3277
|
}
|
3278
|
|
3279
|
|
3280
|
[TearDown]
|
3281
|
public void Dispose()
|
3282
|
{
|
3283
|
dit = dat = dut = null;
|
3284
|
Dit = Dat = Dut = null;
|
3285
|
}
|
3286
|
}
|
3287
|
|
3288
|
|
3289
|
|
3290
|
[TestFixture]
|
3291
|
public class MultiLevelUnOrderedOfOrdered
|
3292
|
{
|
3293
|
private ISequenced<int> dit, dat, dut, dot;
|
3294
|
|
3295
|
private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
|
3296
|
|
3297
|
|
3298
|
[SetUp]
|
3299
|
public void Init()
|
3300
|
{
|
3301
|
dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
|
3302
|
dat = new ArrayList<int>();
|
3303
|
dut = new ArrayList<int>();
|
3304
|
dot = new ArrayList<int>();
|
3305
|
dit.Add(2); dit.Add(1);
|
3306
|
dat.Add(2); dat.Add(1);
|
3307
|
dut.Add(3);
|
3308
|
dot.Add(1); dot.Add(2);
|
3309
|
Dit = new ArrayList<ISequenced<int>>();
|
3310
|
Dat = new ArrayList<ISequenced<int>>();
|
3311
|
Dut = new ArrayList<ISequenced<int>>();
|
3312
|
Dot = new ArrayList<ISequenced<int>>();
|
3313
|
}
|
3314
|
|
3315
|
|
3316
|
[Test]
|
3317
|
public void Check()
|
3318
|
{
|
3319
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3320
|
Assert.IsTrue(dit.SequencedEquals(dot));
|
3321
|
Assert.IsFalse(dit.SequencedEquals(dut));
|
3322
|
}
|
3323
|
|
3324
|
|
3325
|
[Test]
|
3326
|
public void Multi()
|
3327
|
{
|
3328
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3329
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3330
|
Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
|
3331
|
Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
|
3332
|
Assert.IsTrue(Dit.UnsequencedEquals(Dut));
|
3333
|
Assert.IsFalse(Dit.UnsequencedEquals(Dat));
|
3334
|
Assert.IsTrue(Dit.UnsequencedEquals(Dot));
|
3335
|
}
|
3336
|
|
3337
|
|
3338
|
[TearDown]
|
3339
|
public void Dispose()
|
3340
|
{
|
3341
|
dit = dat = dut = dot = null;
|
3342
|
Dit = Dat = Dut = Dot = null;
|
3343
|
}
|
3344
|
}
|
3345
|
|
3346
|
|
3347
|
|
3348
|
[TestFixture]
|
3349
|
public class MultiLevelOrderedOfOrdered
|
3350
|
{
|
3351
|
private ISequenced<int> dit, dat, dut, dot;
|
3352
|
|
3353
|
private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
|
3354
|
|
3355
|
|
3356
|
[SetUp]
|
3357
|
public void Init()
|
3358
|
{
|
3359
|
dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
|
3360
|
dat = new ArrayList<int>();
|
3361
|
dut = new ArrayList<int>();
|
3362
|
dot = new ArrayList<int>();
|
3363
|
dit.Add(2); dit.Add(1);
|
3364
|
dat.Add(2); dat.Add(1);
|
3365
|
dut.Add(3);
|
3366
|
dot.Add(1); dot.Add(2);
|
3367
|
Dit = new ArrayList<ISequenced<int>>();
|
3368
|
Dat = new ArrayList<ISequenced<int>>();
|
3369
|
Dut = new ArrayList<ISequenced<int>>();
|
3370
|
Dot = new ArrayList<ISequenced<int>>();
|
3371
|
}
|
3372
|
|
3373
|
|
3374
|
[Test]
|
3375
|
public void Check()
|
3376
|
{
|
3377
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3378
|
Assert.IsTrue(dit.SequencedEquals(dot));
|
3379
|
Assert.IsFalse(dit.SequencedEquals(dut));
|
3380
|
}
|
3381
|
|
3382
|
|
3383
|
[Test]
|
3384
|
public void Multi()
|
3385
|
{
|
3386
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3387
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3388
|
Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
|
3389
|
Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
|
3390
|
Assert.IsTrue(Dit.SequencedEquals(Dut));
|
3391
|
Assert.IsFalse(Dit.SequencedEquals(Dat));
|
3392
|
Assert.IsFalse(Dit.SequencedEquals(Dot));
|
3393
|
}
|
3394
|
|
3395
|
|
3396
|
[TearDown]
|
3397
|
public void Dispose()
|
3398
|
{
|
3399
|
dit = dat = dut = dot = null;
|
3400
|
Dit = Dat = Dut = Dot = null;
|
3401
|
}
|
3402
|
}
|
3403
|
}
|
3404
|
|
3405
|
|
3406
|
|
3407
|
|
3408
|
namespace HashingAndEquals
|
3409
|
{
|
3410
|
[TestFixture]
|
3411
|
public class ISequenced
|
3412
|
{
|
3413
|
private ISequenced<int> dit, dat, dut;
|
3414
|
|
3415
|
|
3416
|
[SetUp]
|
3417
|
public void Init()
|
3418
|
{
|
3419
|
dit = new ArrayList<int>();
|
3420
|
dat = new ArrayList<int>();
|
3421
|
dut = new ArrayList<int>();
|
3422
|
}
|
3423
|
|
3424
|
|
3425
|
[Test]
|
3426
|
public void EmptyEmpty()
|
3427
|
{
|
3428
|
Assert.IsTrue(dit.SequencedEquals(dat));
|
3429
|
}
|
3430
|
|
3431
|
|
3432
|
[Test]
|
3433
|
public void EmptyNonEmpty()
|
3434
|
{
|
3435
|
dit.Add(3);
|
3436
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3437
|
Assert.IsFalse(dat.SequencedEquals(dit));
|
3438
|
}
|
3439
|
|
3440
|
[Test]
|
3441
|
public void HashVal()
|
3442
|
{
|
3443
|
Assert.AreEqual(CHC.sequencedhashcode(), dit.GetSequencedHashCode());
|
3444
|
dit.Add(3);
|
3445
|
Assert.AreEqual(CHC.sequencedhashcode(3), dit.GetSequencedHashCode());
|
3446
|
dit.Add(7);
|
3447
|
Assert.AreEqual(CHC.sequencedhashcode(3, 7), dit.GetSequencedHashCode());
|
3448
|
Assert.AreEqual(CHC.sequencedhashcode(), dut.GetSequencedHashCode());
|
3449
|
dut.Add(7);
|
3450
|
Assert.AreEqual(CHC.sequencedhashcode(7), dut.GetSequencedHashCode());
|
3451
|
dut.Add(3);
|
3452
|
Assert.AreEqual(CHC.sequencedhashcode(7, 3), dut.GetSequencedHashCode());
|
3453
|
}
|
3454
|
|
3455
|
|
3456
|
[Test]
|
3457
|
public void EqualHashButDifferent()
|
3458
|
{
|
3459
|
dit.Add(0); dit.Add(31);
|
3460
|
dat.Add(1); dat.Add(0);
|
3461
|
Assert.AreEqual(dit.GetSequencedHashCode(), dat.GetSequencedHashCode());
|
3462
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3463
|
}
|
3464
|
|
3465
|
|
3466
|
[Test]
|
3467
|
public void Normal()
|
3468
|
{
|
3469
|
dit.Add(3);
|
3470
|
dit.Add(7);
|
3471
|
dat.Add(3);
|
3472
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3473
|
Assert.IsFalse(dat.SequencedEquals(dit));
|
3474
|
dat.Add(7);
|
3475
|
Assert.IsTrue(dit.SequencedEquals(dat));
|
3476
|
Assert.IsTrue(dat.SequencedEquals(dit));
|
3477
|
}
|
3478
|
|
3479
|
|
3480
|
[Test]
|
3481
|
public void WrongOrder()
|
3482
|
{
|
3483
|
dit.Add(3);
|
3484
|
dut.Add(3);
|
3485
|
Assert.IsTrue(dit.SequencedEquals(dut));
|
3486
|
Assert.IsTrue(dut.SequencedEquals(dit));
|
3487
|
dit.Add(7);
|
3488
|
((ArrayList<int>)dut).InsertFirst(7);
|
3489
|
Assert.IsFalse(dit.SequencedEquals(dut));
|
3490
|
Assert.IsFalse(dut.SequencedEquals(dit));
|
3491
|
}
|
3492
|
|
3493
|
|
3494
|
[Test]
|
3495
|
public void Reflexive()
|
3496
|
{
|
3497
|
Assert.IsTrue(dit.SequencedEquals(dit));
|
3498
|
dit.Add(3);
|
3499
|
Assert.IsTrue(dit.SequencedEquals(dit));
|
3500
|
dit.Add(7);
|
3501
|
Assert.IsTrue(dit.SequencedEquals(dit));
|
3502
|
}
|
3503
|
|
3504
|
|
3505
|
[TearDown]
|
3506
|
public void Dispose()
|
3507
|
{
|
3508
|
dit = null;
|
3509
|
dat = null;
|
3510
|
dut = null;
|
3511
|
}
|
3512
|
}
|
3513
|
|
3514
|
|
3515
|
|
3516
|
[TestFixture]
|
3517
|
public class IEditableCollection
|
3518
|
{
|
3519
|
private ICollection<int> dit, dat, dut;
|
3520
|
|
3521
|
|
3522
|
[SetUp]
|
3523
|
public void Init()
|
3524
|
{
|
3525
|
dit = new ArrayList<int>();
|
3526
|
dat = new ArrayList<int>();
|
3527
|
dut = new ArrayList<int>();
|
3528
|
}
|
3529
|
|
3530
|
|
3531
|
[Test]
|
3532
|
public void EmptyEmpty()
|
3533
|
{
|
3534
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3535
|
}
|
3536
|
|
3537
|
|
3538
|
[Test]
|
3539
|
public void EmptyNonEmpty()
|
3540
|
{
|
3541
|
dit.Add(3);
|
3542
|
Assert.IsFalse(dit.UnsequencedEquals(dat));
|
3543
|
Assert.IsFalse(dat.UnsequencedEquals(dit));
|
3544
|
}
|
3545
|
|
3546
|
|
3547
|
[Test]
|
3548
|
public void HashVal()
|
3549
|
{
|
3550
|
Assert.AreEqual(CHC.unsequencedhashcode(), dit.GetUnsequencedHashCode());
|
3551
|
dit.Add(3);
|
3552
|
Assert.AreEqual(CHC.unsequencedhashcode(3), dit.GetUnsequencedHashCode());
|
3553
|
dit.Add(7);
|
3554
|
Assert.AreEqual(CHC.unsequencedhashcode(3, 7), dit.GetUnsequencedHashCode());
|
3555
|
Assert.AreEqual(CHC.unsequencedhashcode(), dut.GetUnsequencedHashCode());
|
3556
|
dut.Add(3);
|
3557
|
Assert.AreEqual(CHC.unsequencedhashcode(3), dut.GetUnsequencedHashCode());
|
3558
|
dut.Add(7);
|
3559
|
Assert.AreEqual(CHC.unsequencedhashcode(7, 3), dut.GetUnsequencedHashCode());
|
3560
|
}
|
3561
|
|
3562
|
|
3563
|
[Test]
|
3564
|
public void EqualHashButDifferent()
|
3565
|
{
|
3566
|
dit.Add(-1657792980); dit.Add(-1570288808);
|
3567
|
dat.Add(1862883298); dat.Add(-272461342);
|
3568
|
Assert.AreEqual(dit.GetUnsequencedHashCode(), dat.GetUnsequencedHashCode());
|
3569
|
Assert.IsFalse(dit.UnsequencedEquals(dat));
|
3570
|
}
|
3571
|
|
3572
|
|
3573
|
[Test]
|
3574
|
public void Normal()
|
3575
|
{
|
3576
|
dit.Add(3);
|
3577
|
dit.Add(7);
|
3578
|
dat.Add(3);
|
3579
|
Assert.IsFalse(dit.UnsequencedEquals(dat));
|
3580
|
Assert.IsFalse(dat.UnsequencedEquals(dit));
|
3581
|
dat.Add(7);
|
3582
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3583
|
Assert.IsTrue(dat.UnsequencedEquals(dit));
|
3584
|
}
|
3585
|
|
3586
|
|
3587
|
[Test]
|
3588
|
public void WrongOrder()
|
3589
|
{
|
3590
|
dit.Add(3);
|
3591
|
dut.Add(3);
|
3592
|
Assert.IsTrue(dit.UnsequencedEquals(dut));
|
3593
|
Assert.IsTrue(dut.UnsequencedEquals(dit));
|
3594
|
dit.Add(7);
|
3595
|
dut.Add(7);
|
3596
|
Assert.IsTrue(dit.UnsequencedEquals(dut));
|
3597
|
Assert.IsTrue(dut.UnsequencedEquals(dit));
|
3598
|
}
|
3599
|
|
3600
|
|
3601
|
[Test]
|
3602
|
public void Reflexive()
|
3603
|
{
|
3604
|
Assert.IsTrue(dit.UnsequencedEquals(dit));
|
3605
|
dit.Add(3);
|
3606
|
Assert.IsTrue(dit.UnsequencedEquals(dit));
|
3607
|
dit.Add(7);
|
3608
|
Assert.IsTrue(dit.UnsequencedEquals(dit));
|
3609
|
}
|
3610
|
|
3611
|
|
3612
|
[TearDown]
|
3613
|
public void Dispose()
|
3614
|
{
|
3615
|
dit = null;
|
3616
|
dat = null;
|
3617
|
dut = null;
|
3618
|
}
|
3619
|
}
|
3620
|
|
3621
|
|
3622
|
|
3623
|
[TestFixture]
|
3624
|
public class MultiLevelUnorderedOfUnOrdered
|
3625
|
{
|
3626
|
private ICollection<int> dit, dat, dut;
|
3627
|
|
3628
|
private ICollection<ICollection<int>> Dit, Dat, Dut;
|
3629
|
|
3630
|
|
3631
|
[SetUp]
|
3632
|
public void Init()
|
3633
|
{
|
3634
|
dit = new ArrayList<int>();
|
3635
|
dat = new ArrayList<int>();
|
3636
|
dut = new ArrayList<int>();
|
3637
|
dit.Add(2); dit.Add(1);
|
3638
|
dat.Add(1); dat.Add(2);
|
3639
|
dut.Add(3);
|
3640
|
Dit = new ArrayList<ICollection<int>>();
|
3641
|
Dat = new ArrayList<ICollection<int>>();
|
3642
|
Dut = new ArrayList<ICollection<int>>();
|
3643
|
}
|
3644
|
|
3645
|
|
3646
|
[Test]
|
3647
|
public void Check()
|
3648
|
{
|
3649
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3650
|
Assert.IsFalse(dit.UnsequencedEquals(dut));
|
3651
|
}
|
3652
|
|
3653
|
|
3654
|
[Test]
|
3655
|
public void Multi()
|
3656
|
{
|
3657
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3658
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3659
|
Assert.IsTrue(Dit.UnsequencedEquals(Dat));
|
3660
|
Assert.IsFalse(Dit.UnsequencedEquals(Dut));
|
3661
|
}
|
3662
|
|
3663
|
|
3664
|
[TearDown]
|
3665
|
public void Dispose()
|
3666
|
{
|
3667
|
dit = dat = dut = null;
|
3668
|
Dit = Dat = Dut = null;
|
3669
|
}
|
3670
|
}
|
3671
|
|
3672
|
|
3673
|
|
3674
|
[TestFixture]
|
3675
|
public class MultiLevelOrderedOfUnOrdered
|
3676
|
{
|
3677
|
private ICollection<int> dit, dat, dut;
|
3678
|
|
3679
|
private ISequenced<ICollection<int>> Dit, Dat, Dut;
|
3680
|
|
3681
|
|
3682
|
[SetUp]
|
3683
|
public void Init()
|
3684
|
{
|
3685
|
dit = new ArrayList<int>();
|
3686
|
dat = new ArrayList<int>();
|
3687
|
dut = new ArrayList<int>();
|
3688
|
dit.Add(2); dit.Add(1);
|
3689
|
dat.Add(1); dat.Add(2);
|
3690
|
dut.Add(3);
|
3691
|
Dit = new ArrayList<ICollection<int>>();
|
3692
|
Dat = new ArrayList<ICollection<int>>();
|
3693
|
Dut = new ArrayList<ICollection<int>>();
|
3694
|
}
|
3695
|
|
3696
|
|
3697
|
[Test]
|
3698
|
public void Check()
|
3699
|
{
|
3700
|
Assert.IsTrue(dit.UnsequencedEquals(dat));
|
3701
|
Assert.IsFalse(dit.UnsequencedEquals(dut));
|
3702
|
}
|
3703
|
|
3704
|
|
3705
|
[Test]
|
3706
|
public void Multi()
|
3707
|
{
|
3708
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3709
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3710
|
Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
|
3711
|
Assert.IsFalse(Dit.SequencedEquals(Dat));
|
3712
|
Assert.IsTrue(Dit.SequencedEquals(Dut));
|
3713
|
}
|
3714
|
|
3715
|
|
3716
|
[TearDown]
|
3717
|
public void Dispose()
|
3718
|
{
|
3719
|
dit = dat = dut = null;
|
3720
|
Dit = Dat = Dut = null;
|
3721
|
}
|
3722
|
}
|
3723
|
|
3724
|
|
3725
|
|
3726
|
[TestFixture]
|
3727
|
public class MultiLevelUnOrderedOfOrdered
|
3728
|
{
|
3729
|
private ISequenced<int> dit, dat, dut, dot;
|
3730
|
|
3731
|
private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
|
3732
|
|
3733
|
|
3734
|
[SetUp]
|
3735
|
public void Init()
|
3736
|
{
|
3737
|
dit = new ArrayList<int>();
|
3738
|
dat = new ArrayList<int>();
|
3739
|
dut = new ArrayList<int>();
|
3740
|
dot = new ArrayList<int>();
|
3741
|
dit.Add(2); dit.Add(1);
|
3742
|
dat.Add(1); dat.Add(2);
|
3743
|
dut.Add(3);
|
3744
|
dot.Add(2); dot.Add(1);
|
3745
|
Dit = new ArrayList<ISequenced<int>>();
|
3746
|
Dat = new ArrayList<ISequenced<int>>();
|
3747
|
Dut = new ArrayList<ISequenced<int>>();
|
3748
|
Dot = new ArrayList<ISequenced<int>>();
|
3749
|
}
|
3750
|
|
3751
|
|
3752
|
[Test]
|
3753
|
public void Check()
|
3754
|
{
|
3755
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3756
|
Assert.IsTrue(dit.SequencedEquals(dot));
|
3757
|
Assert.IsFalse(dit.SequencedEquals(dut));
|
3758
|
}
|
3759
|
|
3760
|
|
3761
|
[Test]
|
3762
|
public void Multi()
|
3763
|
{
|
3764
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3765
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3766
|
Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
|
3767
|
Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
|
3768
|
Assert.IsTrue(Dit.UnsequencedEquals(Dut));
|
3769
|
Assert.IsFalse(Dit.UnsequencedEquals(Dat));
|
3770
|
Assert.IsTrue(Dit.UnsequencedEquals(Dot));
|
3771
|
}
|
3772
|
|
3773
|
|
3774
|
[TearDown]
|
3775
|
public void Dispose()
|
3776
|
{
|
3777
|
dit = dat = dut = dot = null;
|
3778
|
Dit = Dat = Dut = Dot = null;
|
3779
|
}
|
3780
|
}
|
3781
|
|
3782
|
|
3783
|
|
3784
|
[TestFixture]
|
3785
|
public class MultiLevelOrderedOfOrdered
|
3786
|
{
|
3787
|
private ISequenced<int> dit, dat, dut, dot;
|
3788
|
|
3789
|
private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
|
3790
|
|
3791
|
|
3792
|
[SetUp]
|
3793
|
public void Init()
|
3794
|
{
|
3795
|
dit = new ArrayList<int>();
|
3796
|
dat = new ArrayList<int>();
|
3797
|
dut = new ArrayList<int>();
|
3798
|
dot = new ArrayList<int>();
|
3799
|
dit.Add(2); dit.Add(1);
|
3800
|
dat.Add(1); dat.Add(2);
|
3801
|
dut.Add(3);
|
3802
|
dot.Add(2); dot.Add(1);
|
3803
|
Dit = new ArrayList<ISequenced<int>>();
|
3804
|
Dat = new ArrayList<ISequenced<int>>();
|
3805
|
Dut = new ArrayList<ISequenced<int>>();
|
3806
|
Dot = new ArrayList<ISequenced<int>>();
|
3807
|
}
|
3808
|
|
3809
|
|
3810
|
[Test]
|
3811
|
public void Check()
|
3812
|
{
|
3813
|
Assert.IsFalse(dit.SequencedEquals(dat));
|
3814
|
Assert.IsTrue(dit.SequencedEquals(dot));
|
3815
|
Assert.IsFalse(dit.SequencedEquals(dut));
|
3816
|
}
|
3817
|
|
3818
|
|
3819
|
[Test]
|
3820
|
public void Multi()
|
3821
|
{
|
3822
|
Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
|
3823
|
Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
|
3824
|
Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
|
3825
|
Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
|
3826
|
Assert.IsTrue(Dit.SequencedEquals(Dut));
|
3827
|
Assert.IsFalse(Dit.SequencedEquals(Dat));
|
3828
|
Assert.IsFalse(Dit.SequencedEquals(Dot));
|
3829
|
}
|
3830
|
|
3831
|
|
3832
|
[TearDown]
|
3833
|
public void Dispose()
|
3834
|
{
|
3835
|
dit = dat = dut = dot = null;
|
3836
|
Dit = Dat = Dut = Dot = null;
|
3837
|
}
|
3838
|
}
|
3839
|
}
|
3840
|
}
|