Project

General

Profile

root / branches / compiler / cSharp / ooasCompiler / src / libs / c5 / nunit / linkedlists / LinkedListTest.cs @ 3

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

    
28
namespace C5UnitTests.linkedlists.plain
29
{
30
  using CollectionOfInt = LinkedList<int>;
31

    
32
  [TestFixture]
33
  public class GenericTesters
34
  {
35

    
36
    [Test]
37
    public void TestEvents()
38
    {
39
      Fun<CollectionOfInt> factory = delegate() { return new CollectionOfInt(TenEqualityComparer.Default); };
40
      new C5UnitTests.Templates.Events.ListTester<CollectionOfInt>().Test(factory);
41
      new C5UnitTests.Templates.Events.QueueTester<CollectionOfInt>().Test(factory);
42
      new C5UnitTests.Templates.Events.StackTester<CollectionOfInt>().Test(factory);
43
    }
44

    
45
    [Test]
46
    public void Extensible()
47
    {
48
      C5UnitTests.Templates.Extensible.Clone.Tester<CollectionOfInt>();
49
      C5UnitTests.Templates.Extensible.Clone.ViewTester<CollectionOfInt>();
50
      C5UnitTests.Templates.Extensible.Serialization.Tester<CollectionOfInt>();
51
      C5UnitTests.Templates.Extensible.Serialization.ViewTester<CollectionOfInt>();
52
    }
53

    
54
    [Test]
55
    public void List()
56
    {
57
      C5UnitTests.Templates.List.Dispose.Tester<CollectionOfInt>();
58
      C5UnitTests.Templates.List.SCG_IList.Tester<CollectionOfInt>();
59
    }
60
  }
61

    
62
  static class Factory
63
  {
64
    public static ICollection<T> New<T>() { return new LinkedList<T>(); }
65
  }
66

    
67
  namespace Enumerable
68
  {
69
    [TestFixture]
70
    public class Multiops
71
    {
72
      private LinkedList<int> list;
73

    
74
      private Fun<int, bool> always, never, even;
75

    
76

    
77
      [SetUp]
78
      public void Init()
79
      {
80
        list = new LinkedList<int>();
81
        always = delegate { return true; };
82
        never = delegate { return false; };
83
        even = delegate(int i) { return i % 2 == 0; };
84
      }
85

    
86

    
87
      [Test]
88
      public void All()
89
      {
90
        Assert.IsTrue(list.All(always));
91
        Assert.IsTrue(list.All(never));
92
        Assert.IsTrue(list.All(even));
93
        list.Add(8);
94
        Assert.IsTrue(list.All(always));
95
        Assert.IsFalse(list.All(never));
96
        Assert.IsTrue(list.All(even));
97
        list.Add(5);
98
        Assert.IsTrue(list.All(always));
99
        Assert.IsFalse(list.All(never));
100
        Assert.IsFalse(list.All(even));
101
      }
102

    
103

    
104
      [Test]
105
      public void Exists()
106
      {
107
        Assert.IsFalse(list.Exists(always));
108
        Assert.IsFalse(list.Exists(never));
109
        Assert.IsFalse(list.Exists(even));
110
        list.Add(5);
111
        Assert.IsTrue(list.Exists(always));
112
        Assert.IsFalse(list.Exists(never));
113
        Assert.IsFalse(list.Exists(even));
114
        list.Add(8);
115
        Assert.IsTrue(list.Exists(always));
116
        Assert.IsFalse(list.Exists(never));
117
        Assert.IsTrue(list.Exists(even));
118
      }
119

    
120

    
121
      [Test]
122
      public void Apply()
123
      {
124
        int sum = 0;
125
        Act<int> a = delegate(int i) { sum = i + 10 * sum; };
126

    
127
        list.Apply(a);
128
        Assert.AreEqual(0, sum);
129
        sum = 0;
130
        list.Add(5); list.Add(8); list.Add(7); list.Add(5);
131
        list.Apply(a);
132
        Assert.AreEqual(5875, sum);
133
      }
134

    
135

    
136
      [TearDown]
137
      public void Dispose() { list = null; }
138
    }
139

    
140

    
141

    
142
    [TestFixture]
143
    public class GetEnumerator
144
    {
145
      private LinkedList<int> list;
146

    
147

    
148
      [SetUp]
149
      public void Init() { list = new LinkedList<int>(); }
150

    
151

    
152
      [Test]
153
      public void Empty()
154
      {
155
        SCG.IEnumerator<int> e = list.GetEnumerator();
156

    
157
        Assert.IsFalse(e.MoveNext());
158
      }
159

    
160

    
161
      [Test]
162
      public void Normal()
163
      {
164
        list.Add(5);
165
        list.Add(8);
166
        list.Add(5);
167
        list.Add(5);
168
        list.Add(10);
169
        list.Add(1);
170

    
171
        SCG.IEnumerator<int> e = list.GetEnumerator();
172

    
173
        Assert.IsTrue(e.MoveNext());
174
        Assert.AreEqual(5, e.Current);
175
        Assert.IsTrue(e.MoveNext());
176
        Assert.AreEqual(8, e.Current);
177
        Assert.IsTrue(e.MoveNext());
178
        Assert.AreEqual(5, e.Current);
179
        Assert.IsTrue(e.MoveNext());
180
        Assert.AreEqual(5, e.Current);
181
        Assert.IsTrue(e.MoveNext());
182
        Assert.AreEqual(10, e.Current);
183
        Assert.IsTrue(e.MoveNext());
184
        Assert.AreEqual(1, e.Current);
185
        Assert.IsFalse(e.MoveNext());
186
      }
187

    
188

    
189
      [Test]
190
      public void DoDispose()
191
      {
192
        list.Add(5);
193
        list.Add(8);
194
        list.Add(5);
195

    
196
        SCG.IEnumerator<int> e = list.GetEnumerator();
197

    
198
        e.MoveNext();
199
        e.MoveNext();
200
        e.Dispose();
201
      }
202

    
203

    
204
      [Test]
205
      [ExpectedException(typeof(CollectionModifiedException))]
206
      public void MoveNextAfterUpdate()
207
      {
208
        list.Add(5);
209
        list.Add(8);
210
        list.Add(5);
211

    
212
        SCG.IEnumerator<int> e = list.GetEnumerator();
213

    
214
        e.MoveNext();
215
        list.Add(99);
216
        e.MoveNext();
217
      }
218

    
219

    
220
      [TearDown]
221
      public void Dispose() { list = null; }
222
    }
223
  }
224

    
225
  namespace CollectionOrExtensible
226
  {
227
    [TestFixture]
228
    public class Formatting
229
    {
230
      ICollection<int> coll;
231
      IFormatProvider rad16;
232
      [SetUp]
233
      public void Init() { coll = Factory.New<int>(); rad16 = new RadixFormatProvider(16); }
234
      [TearDown]
235
      public void Dispose() { coll = null; rad16 = null; }
236
      [Test]
237
      public void Format()
238
      {
239
        Assert.AreEqual("[  ]", coll.ToString());
240
        coll.AddAll<int>(new int[] { -4, 28, 129, 65530 });
241
        Assert.AreEqual("[ -4, 28, 129, 65530 ]", coll.ToString());
242
        Assert.AreEqual("[ -4, 1C, 81, FFFA ]", coll.ToString(null, rad16));
243
        Assert.AreEqual("[ -4, 28, 129... ]", coll.ToString("L14", null));
244
        Assert.AreEqual("[ -4, 1C, 81... ]", coll.ToString("L14", rad16));
245
      }
246
    }
247

    
248
    [TestFixture]
249
    public class CollectionOrSink
250
    {
251
      private LinkedList<int> list;
252

    
253

    
254
      [SetUp]
255
      public void Init() { list = new LinkedList<int>(); }
256

    
257
      [Test]
258
      [ExpectedException(typeof(NullReferenceException))]
259
      public void NullEqualityComparerinConstructor1()
260
      {
261
        new LinkedList<int>(null);
262
      }
263

    
264
      [Test]
265
      public void Choose()
266
      {
267
        list.Add(7);
268
        Assert.AreEqual(7, list.Choose());
269
      }
270

    
271
      [Test]
272
      [ExpectedException(typeof(NoSuchItemException))]
273
      public void BadChoose()
274
      {
275
        list.Choose();
276
      }
277

    
278

    
279
      [Test]
280
      public void CountEtAl()
281
      {
282
        Assert.AreEqual(0, list.Count);
283
        Assert.IsTrue(list.IsEmpty);
284
        Assert.IsTrue(list.AllowsDuplicates);
285
        list.Add(5);
286
        Assert.AreEqual(1, list.Count);
287
        Assert.IsFalse(list.IsEmpty);
288
        list.Add(5);
289
        Assert.AreEqual(2, list.Count);
290
        Assert.IsFalse(list.IsEmpty);
291
        list.Add(8);
292
        Assert.AreEqual(3, list.Count);
293
      }
294

    
295

    
296
      [Test]
297
      public void AddAll()
298
      {
299
        list.Add(3); list.Add(4); list.Add(5);
300

    
301
        LinkedList<int> list2 = new LinkedList<int>();
302

    
303
        list2.AddAll(list);
304
        Assert.IsTrue(IC.eq(list2, 3, 4, 5));
305
        list.AddAll(list2);
306
        Assert.IsTrue(IC.eq(list2, 3, 4, 5));
307
        Assert.IsTrue(IC.eq(list, 3, 4, 5, 3, 4, 5));
308
      }
309

    
310

    
311
      [TearDown]
312
      public void Dispose() { list = null; }
313
    }
314

    
315
    [TestFixture]
316
    public class FindPredicate
317
    {
318
      private LinkedList<int> list;
319
      Fun<int, bool> pred;
320

    
321
      [SetUp]
322
      public void Init()
323
      {
324
        list = new LinkedList<int>(TenEqualityComparer.Default);
325
        pred = delegate(int i) { return i % 5 == 0; };
326
      }
327

    
328
      [TearDown]
329
      public void Dispose() { list = null; }
330

    
331
      [Test]
332
      public void Find()
333
      {
334
        int i;
335
        Assert.IsFalse(list.Find(pred, out i));
336
        list.AddAll<int>(new int[] { 4, 22, 67, 37 });
337
        Assert.IsFalse(list.Find(pred, out i));
338
        list.AddAll<int>(new int[] { 45, 122, 675, 137 });
339
        Assert.IsTrue(list.Find(pred, out i));
340
        Assert.AreEqual(45, i);
341
      }
342

    
343
      [Test]
344
      public void FindLast()
345
      {
346
        int i;
347
        Assert.IsFalse(list.FindLast(pred, out i));
348
        list.AddAll<int>(new int[] { 4, 22, 67, 37 });
349
        Assert.IsFalse(list.FindLast(pred, out i));
350
        list.AddAll<int>(new int[] { 45, 122, 675, 137 });
351
        Assert.IsTrue(list.FindLast(pred, out i));
352
        Assert.AreEqual(675, i);
353
      }
354

    
355
      [Test]
356
      public void FindIndex()
357
      {
358
        Assert.IsFalse(0 <= list.FindIndex(pred));
359
        list.AddAll<int>(new int[] { 4, 22, 67, 37 });
360
        Assert.IsFalse(0 <= list.FindIndex(pred));
361
        list.AddAll<int>(new int[] { 45, 122, 675, 137 });
362
        Assert.AreEqual(4, list.FindIndex(pred));
363
      }
364

    
365
      [Test]
366
      public void FindLastIndex()
367
      {
368
        Assert.IsFalse(0 <= list.FindLastIndex(pred));
369
        list.AddAll<int>(new int[] { 4, 22, 67, 37 });
370
        Assert.IsFalse(0 <= list.FindLastIndex(pred));
371
        list.AddAll<int>(new int[] { 45, 122, 675, 137 });
372
        Assert.AreEqual(6, list.FindLastIndex(pred));
373
      }
374
    }
375

    
376
    [TestFixture]
377
    public class UniqueItems
378
    {
379
      private LinkedList<int> list;
380

    
381
      [SetUp]
382
      public void Init() { list = new LinkedList<int>(); }
383

    
384
      [TearDown]
385
      public void Dispose() { list = null; }
386

    
387
      [Test]
388
      public void Test()
389
      {
390
        Assert.IsTrue(IC.seteq(list.UniqueItems()));
391
        Assert.IsTrue(IC.seteq(list.ItemMultiplicities()));
392
        list.AddAll<int>(new int[] { 7, 9, 7 });
393
        Assert.IsTrue(IC.seteq(list.UniqueItems(), 7, 9));
394
        Assert.IsTrue(IC.seteq(list.ItemMultiplicities(), 7, 2, 9, 1));
395
      }
396
    }
397

    
398
    [TestFixture]
399
    public class ArrayTest
400
    {
401
      private LinkedList<int> list;
402

    
403
      int[] a;
404

    
405

    
406
      [SetUp]
407
      public void Init()
408
      {
409
        list = new LinkedList<int>();
410
        a = new int[10];
411
        for (int i = 0; i < 10; i++)
412
          a[i] = 1000 + i;
413
      }
414

    
415

    
416
      [TearDown]
417
      public void Dispose() { list = null; }
418

    
419

    
420
      private string aeq(int[] a, params int[] b)
421
      {
422
        if (a.Length != b.Length)
423
          return "Lengths differ: " + a.Length + " != " + b.Length;
424

    
425
        for (int i = 0; i < a.Length; i++)
426
          if (a[i] != b[i])
427
            return String.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]);
428

    
429
        return "Alles klar";
430
      }
431

    
432

    
433
      [Test]
434
      public void ToArray()
435
      {
436
        Assert.AreEqual("Alles klar", aeq(list.ToArray()));
437
        list.Add(7);
438
        list.Add(7);
439
        Assert.AreEqual("Alles klar", aeq(list.ToArray(), 7, 7));
440
      }
441

    
442

    
443
      [Test]
444
      public void CopyTo()
445
      {
446
        list.CopyTo(a, 1);
447
        Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
448
        list.Add(6);
449
        list.CopyTo(a, 2);
450
        Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
451
        list.Add(4);
452
        list.Add(4);
453
        list.Add(9);
454
        list.CopyTo(a, 4);
455
        Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009));
456
        list.Clear();
457
        list.Add(7);
458
        list.CopyTo(a, 9);
459
        Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7));
460
      }
461

    
462

    
463
      [Test]
464
      [ExpectedException(typeof(ArgumentOutOfRangeException))]
465
      public void CopyToBad()
466
      {
467
        list.CopyTo(a, 11);
468
      }
469

    
470

    
471
      [Test]
472
      [ExpectedException(typeof(ArgumentOutOfRangeException))]
473
      public void CopyToBad2()
474
      {
475
        list.CopyTo(a, -1);
476
      }
477

    
478

    
479
      [Test]
480
      [ExpectedException(typeof(ArgumentOutOfRangeException))]
481
      public void CopyToTooFar()
482
      {
483
        list.Add(3);
484
        list.Add(3);
485
        list.CopyTo(a, 9);
486
      }
487
    }
488

    
489

    
490

    
491
    [TestFixture]
492
    public class Sync
493
    {
494
      private LinkedList<int> list;
495

    
496

    
497
      [SetUp]
498
      public void Init()
499
      {
500
        list = new LinkedList<int>();
501
      }
502

    
503

    
504
      [TearDown]
505
      public void Dispose() { list = null; }
506

    
507

    
508
      [Test]
509
      public void Get()
510
      {
511
        Assert.IsNotNull(((System.Collections.IList)list).SyncRoot);
512
      }
513
    }
514
  }
515

    
516

    
517

    
518

    
519
  namespace EditableCollection
520
  {
521
    [TestFixture]
522
    public class Searching
523
    {
524
      private LinkedList<int> list;
525

    
526

    
527
      [SetUp]
528
      public void Init() { list = new LinkedList<int>(); }
529

    
530

    
531
      [Test]
532
      public void Contains()
533
      {
534
        Assert.IsFalse(list.Contains(5));
535
        list.Add(5);
536
        Assert.IsTrue(list.Contains(5));
537
        Assert.IsFalse(list.Contains(7));
538
        list.Add(8);
539
        list.Add(10);
540
        Assert.IsTrue(list.Contains(5));
541
        Assert.IsFalse(list.Contains(7));
542
        Assert.IsTrue(list.Contains(8));
543
        Assert.IsTrue(list.Contains(10));
544
        list.Remove(8);
545
        Assert.IsTrue(list.Contains(5));
546
        Assert.IsFalse(list.Contains(7));
547
        Assert.IsFalse(list.Contains(8));
548
        Assert.IsTrue(list.Contains(10));
549
      }
550

    
551

    
552
      [Test]
553
      public void ContainsCount()
554
      {
555
        Assert.AreEqual(0, list.ContainsCount(5));
556
        list.Add(5);
557
        Assert.AreEqual(1, list.ContainsCount(5));
558
        Assert.AreEqual(0, list.ContainsCount(7));
559
        list.Add(8);
560
        Assert.AreEqual(1, list.ContainsCount(5));
561
        Assert.AreEqual(0, list.ContainsCount(7));
562
        Assert.AreEqual(1, list.ContainsCount(8));
563
        list.Add(5);
564
        Assert.AreEqual(2, list.ContainsCount(5));
565
        Assert.AreEqual(0, list.ContainsCount(7));
566
        Assert.AreEqual(1, list.ContainsCount(8));
567
      }
568

    
569

    
570
      [Test]
571
      public void RemoveAllCopies()
572
      {
573
        list.Add(5); list.Add(7); list.Add(5);
574
        Assert.AreEqual(2, list.ContainsCount(5));
575
        Assert.AreEqual(1, list.ContainsCount(7));
576
        list.RemoveAllCopies(5);
577
        Assert.AreEqual(0, list.ContainsCount(5));
578
        Assert.AreEqual(1, list.ContainsCount(7));
579
        list.Add(5); list.Add(8); list.Add(5);
580
        list.RemoveAllCopies(8);
581
        Assert.IsTrue(IC.eq(list, 7, 5, 5));
582
      }
583

    
584

    
585
      [Test]
586
      public void FindAll()
587
      {
588
        Fun<int, bool> f = delegate(int i) { return i % 2 == 0; };
589

    
590
        Assert.IsTrue(list.FindAll(f).IsEmpty);
591
        list.Add(5); list.Add(8); list.Add(5); list.Add(10); list.Add(8);
592
        Assert.IsTrue(((LinkedList<int>)list.FindAll(f)).Check());
593
        Assert.IsTrue(IC.eq(list.FindAll(f), 8, 10, 8));
594
      }
595

    
596

    
597
      [Test]
598
      public void ContainsAll()
599
      {
600
        LinkedList<int> list2 = new LinkedList<int>();
601

    
602
        Assert.IsTrue(list.ContainsAll(list2));
603
        list2.Add(4);
604
        Assert.IsFalse(list.ContainsAll(list2));
605
        list.Add(4);
606
        Assert.IsTrue(list.ContainsAll(list2));
607
        list.Add(5);
608
        Assert.IsTrue(list.ContainsAll(list2));
609
        list2.Add(4);
610
        Assert.IsFalse(list.ContainsAll(list2));
611
        list.Add(4);
612
        Assert.IsTrue(list.ContainsAll(list2));
613
      }
614

    
615

    
616
      [Test]
617
      public void RetainAll()
618
      {
619
        LinkedList<int> list2 = new LinkedList<int>();
620

    
621
        list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
622
        list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
623
        list.RetainAll(list2);
624
        Assert.IsTrue(list.Check());
625
        Assert.IsTrue(IC.eq(list, 4, 4, 5));
626
        list.Add(5); list.Add(4); list.Add(6);
627
        list2.Clear();
628
        list2.Add(5); list2.Add(5); list2.Add(6);
629
        list.RetainAll(list2);
630
        Assert.IsTrue(list.Check());
631
        Assert.IsTrue(IC.eq(list, 5, 5, 6));
632
        list2.Clear();
633
        list2.Add(7); list2.Add(8); list2.Add(9);
634
        list.RetainAll(list2);
635
        Assert.IsTrue(list.Check());
636
        Assert.IsTrue(IC.eq(list));
637
      }
638

    
639

    
640
      [Test]
641
      public void RemoveAll()
642
      {
643
        LinkedList<int> list2 = new LinkedList<int>();
644

    
645
        list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
646
        list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
647
        list.RemoveAll(list2);
648
        Assert.IsTrue(list.Check());
649
        Assert.IsTrue(IC.eq(list, 4, 6));
650
        list.Add(5); list.Add(4); list.Add(6);
651
        list2.Clear();
652
        list2.Add(6); list2.Add(5); list2.Add(5); list2.Add(6);
653
        list.RemoveAll(list2);
654
        Assert.IsTrue(list.Check());
655
        Assert.IsTrue(IC.eq(list, 4, 4));
656
        list2.Clear();
657
        list2.Add(7); list2.Add(8); list2.Add(9);
658
        list.RemoveAll(list2);
659
        Assert.IsTrue(list.Check());
660
        Assert.IsTrue(IC.eq(list, 4, 4));
661
      }
662

    
663

    
664
      [Test]
665
      public void Remove()
666
      {
667

    
668
        Assert.IsTrue(list.FIFO);
669
        list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
670
        Assert.IsFalse(list.Remove(2));
671
        Assert.IsTrue(list.Check());
672
        Assert.IsTrue(list.Remove(4));
673
        Assert.IsTrue(list.Check());
674
        Assert.IsTrue(IC.eq(list, 4, 5, 4, 6));
675
        Assert.AreEqual(6, list.RemoveLast());
676
        Assert.IsTrue(list.Check());
677
        Assert.IsTrue(IC.eq(list, 4, 5, 4));
678
        list.Add(7);
679
        Assert.AreEqual(4, list.RemoveFirst());
680
        Assert.IsTrue(list.Check());
681
        Assert.IsTrue(IC.eq(list, 5, 4, 7));
682

    
683
        list.FIFO = false;
684
        list.Clear();
685
        list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
686
        Assert.IsFalse(list.Remove(2));
687
        Assert.IsTrue(list.Check());
688
        Assert.IsTrue(list.Remove(4));
689
        Assert.IsTrue(list.Check());
690
        Assert.IsTrue(IC.eq(list, 4, 4, 5, 6));
691
        Assert.AreEqual(6, list.RemoveLast());
692
        Assert.IsTrue(list.Check());
693
        Assert.IsTrue(IC.eq(list, 4, 4, 5));
694
        list.Add(7);
695
        Assert.AreEqual(4, list.RemoveFirst());
696
        Assert.IsTrue(list.Check());
697
        Assert.IsTrue(IC.eq(list, 4, 5, 7));
698
      }
699

    
700

    
701
      [Test]
702
      public void Clear()
703
      {
704
        list.Add(7); list.Add(7);
705
        list.Clear();
706
        Assert.IsTrue(list.IsEmpty);
707
      }
708

    
709

    
710
      [TearDown]
711
      public void Dispose() { list = null; }
712
    }
713
  }
714

    
715

    
716

    
717

    
718
  namespace IIndexed
719
  {
720
    [TestFixture]
721
    public class Searching
722
    {
723
      private IIndexed<int> dit;
724

    
725

    
726
      [SetUp]
727
      public void Init()
728
      {
729
        dit = new LinkedList<int>();
730
      }
731

    
732

    
733
      [Test]
734
      public void IndexOf()
735
      {
736
        Assert.AreEqual(~0, dit.IndexOf(6));
737
        dit.Add(7);
738
        Assert.AreEqual(~1, dit.IndexOf(6));
739
        Assert.AreEqual(~1, dit.LastIndexOf(6));
740
        Assert.AreEqual(0, dit.IndexOf(7));
741
        dit.Add(5); dit.Add(7); dit.Add(8); dit.Add(7);
742
        Assert.AreEqual(~5, dit.IndexOf(6));
743
        Assert.AreEqual(0, dit.IndexOf(7));
744
        Assert.AreEqual(4, dit.LastIndexOf(7));
745
        Assert.AreEqual(3, dit.IndexOf(8));
746
        Assert.AreEqual(1, dit.LastIndexOf(5));
747
      }
748

    
749

    
750
      [TearDown]
751
      public void Dispose()
752
      {
753
        dit = null;
754
      }
755
    }
756

    
757

    
758

    
759
    [TestFixture]
760
    public class Removing
761
    {
762
      private IIndexed<int> dit;
763

    
764

    
765
      [SetUp]
766
      public void Init()
767
      {
768
        dit = new LinkedList<int>();
769
      }
770

    
771

    
772
      [Test]
773
      public void RemoveAt()
774
      {
775
        dit.Add(5); dit.Add(7); dit.Add(9); dit.Add(1); dit.Add(2);
776
        Assert.AreEqual(7, dit.RemoveAt(1));
777
        Assert.IsTrue(((LinkedList<int>)dit).Check());
778
        Assert.IsTrue(IC.eq(dit, 5, 9, 1, 2));
779
        Assert.AreEqual(5, dit.RemoveAt(0));
780
        Assert.IsTrue(((LinkedList<int>)dit).Check());
781
        Assert.IsTrue(IC.eq(dit, 9, 1, 2));
782
        Assert.AreEqual(2, dit.RemoveAt(2));
783
        Assert.IsTrue(((LinkedList<int>)dit).Check());
784
        Assert.IsTrue(IC.eq(dit, 9, 1));
785
      }
786

    
787

    
788
      [Test]
789
      [ExpectedException(typeof(IndexOutOfRangeException))]
790
      public void RemoveAtBad0()
791
      {
792
        dit.RemoveAt(0);
793
      }
794

    
795

    
796
      [Test]
797
      [ExpectedException(typeof(IndexOutOfRangeException))]
798
      public void RemoveAtBadM1()
799
      {
800
        dit.RemoveAt(-1);
801
      }
802

    
803

    
804
      [Test]
805
      [ExpectedException(typeof(IndexOutOfRangeException))]
806
      public void RemoveAtBad1()
807
      {
808
        dit.Add(8);
809
        dit.RemoveAt(1);
810
      }
811

    
812

    
813
      [Test]
814
      public void RemoveInterval()
815
      {
816
        dit.RemoveInterval(0, 0);
817
        dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
818
        dit.RemoveInterval(3, 0);
819
        Assert.IsTrue(((LinkedList<int>)dit).Check());
820
        Assert.IsTrue(IC.eq(dit, 10, 20, 30, 40, 50, 60));
821
        dit.RemoveInterval(3, 1);
822
        Assert.IsTrue(((LinkedList<int>)dit).Check());
823
        Assert.IsTrue(IC.eq(dit, 10, 20, 30, 50, 60));
824
        dit.RemoveInterval(1, 3);
825
        Assert.IsTrue(((LinkedList<int>)dit).Check());
826
        Assert.IsTrue(IC.eq(dit, 10, 60));
827
        dit.RemoveInterval(0, 2);
828
        Assert.IsTrue(((LinkedList<int>)dit).Check());
829
        Assert.IsTrue(IC.eq(dit));
830
        dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
831
        dit.RemoveInterval(0, 2);
832
        Assert.IsTrue(((LinkedList<int>)dit).Check());
833
        Assert.IsTrue(IC.eq(dit, 30, 40, 50, 60));
834
        dit.RemoveInterval(2, 2);
835
        Assert.IsTrue(((LinkedList<int>)dit).Check());
836
        Assert.IsTrue(IC.eq(dit, 30, 40));
837
      }
838

    
839

    
840
      [TearDown]
841
      public void Dispose()
842
      {
843
        dit = null;
844
      }
845
    }
846
  }
847

    
848

    
849

    
850

    
851
  namespace IList_
852
  {
853
    [TestFixture]
854
    public class Searching
855
    {
856
      private IList<int> lst;
857

    
858

    
859
      [SetUp]
860
      public void Init() { lst = new LinkedList<int>(); }
861

    
862

    
863
      [TearDown]
864
      public void Dispose() { lst = null; }
865

    
866

    
867
      [Test]
868
      [ExpectedException(typeof(NoSuchItemException))]
869
      public void FirstBad()
870
      {
871
        int f = lst.First;
872
      }
873

    
874

    
875
      [Test]
876
      [ExpectedException(typeof(NoSuchItemException))]
877
      public void LastBad()
878
      {
879
        int f = lst.Last;
880
      }
881

    
882

    
883
      [Test]
884
      public void FirstLast()
885
      {
886
        lst.Add(19);
887
        Assert.AreEqual(19, lst.First);
888
        Assert.AreEqual(19, lst.Last);
889
        lst.Add(34); lst.InsertFirst(12);
890
        Assert.AreEqual(12, lst.First);
891
        Assert.AreEqual(34, lst.Last);
892
      }
893

    
894

    
895
      [Test]
896
      public void This()
897
      {
898
        lst.Add(34);
899
        Assert.AreEqual(34, lst[0]);
900
        lst[0] = 56;
901
        Assert.AreEqual(56, lst.First);
902
        lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7);
903
        lst[0] = 45; lst[2] = 78; lst[4] = 101;
904
        Assert.IsTrue(IC.eq(lst, 45, 7, 78, 7, 101));
905
      }
906

    
907

    
908
      [Test]
909
      [ExpectedException(typeof(IndexOutOfRangeException))]
910
      public void ThisBadEmptyGet()
911
      {
912
        int f = lst[0];
913
      }
914

    
915

    
916
      [Test]
917
      [ExpectedException(typeof(IndexOutOfRangeException))]
918
      public void ThisBadLowGet()
919
      {
920
        lst.Add(7);
921

    
922
        int f = lst[-1];
923
      }
924

    
925

    
926
      [Test]
927
      [ExpectedException(typeof(IndexOutOfRangeException))]
928
      public void ThisBadHiGet()
929
      {
930
        lst.Add(6);
931

    
932
        int f = lst[1];
933
      }
934

    
935

    
936
      [Test]
937
      [ExpectedException(typeof(IndexOutOfRangeException))]
938
      public void ThisBadEmptySet()
939
      {
940
        lst[0] = 4;
941
      }
942

    
943

    
944
      [Test]
945
      [ExpectedException(typeof(IndexOutOfRangeException))]
946
      public void ThisBadLowSet()
947
      {
948
        lst.Add(7);
949
        lst[-1] = 9;
950
      }
951

    
952

    
953
      [Test]
954
      [ExpectedException(typeof(IndexOutOfRangeException))]
955
      public void ThisBadHiSet()
956
      {
957
        lst.Add(6);
958
        lst[1] = 11;
959
      }
960
    }
961

    
962

    
963
    [TestFixture]
964
    public class Combined
965
    {
966
      private IList<KeyValuePair<int, int>> lst;
967

    
968

    
969
      [SetUp]
970
      public void Init()
971
      {
972
        lst = new LinkedList<KeyValuePair<int, int>>(new KeyValuePairEqualityComparer<int, int>());
973
        for (int i = 0; i < 10; i++)
974
          lst.Add(new KeyValuePair<int, int>(i, i + 30));
975
      }
976

    
977

    
978
      [TearDown]
979
      public void Dispose() { lst = null; }
980

    
981

    
982
      [Test]
983
      public void Find()
984
      {
985
        KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
986

    
987
        Assert.IsTrue(lst.Find(ref p));
988
        Assert.AreEqual(3, p.Key);
989
        Assert.AreEqual(33, p.Value);
990
        p = new KeyValuePair<int, int>(13, 78);
991
        Assert.IsFalse(lst.Find(ref p));
992
      }
993

    
994

    
995
      [Test]
996
      public void FindOrAdd()
997
      {
998
        KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
999

    
1000
        Assert.IsTrue(lst.FindOrAdd(ref p));
1001
        Assert.AreEqual(3, p.Key);
1002
        Assert.AreEqual(33, p.Value);
1003
        p = new KeyValuePair<int, int>(13, 79);
1004
        Assert.IsFalse(lst.FindOrAdd(ref p));
1005
        Assert.AreEqual(13, lst[10].Key);
1006
        Assert.AreEqual(79, lst[10].Value);
1007
      }
1008

    
1009

    
1010
      [Test]
1011
      public void Update()
1012
      {
1013
        KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
1014

    
1015
        Assert.IsTrue(lst.Update(p));
1016
        Assert.AreEqual(3, lst[3].Key);
1017
        Assert.AreEqual(78, lst[3].Value);
1018
        p = new KeyValuePair<int, int>(13, 78);
1019
        Assert.IsFalse(lst.Update(p));
1020
      }
1021

    
1022

    
1023
      [Test]
1024
      public void UpdateOrAdd1()
1025
      {
1026
        KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
1027

    
1028
        Assert.IsTrue(lst.UpdateOrAdd(p));
1029
        Assert.AreEqual(3, lst[3].Key);
1030
        Assert.AreEqual(78, lst[3].Value);
1031
        p = new KeyValuePair<int, int>(13, 79);
1032
        Assert.IsFalse(lst.UpdateOrAdd(p));
1033
        Assert.AreEqual(13, lst[10].Key);
1034
        Assert.AreEqual(79, lst[10].Value);
1035
      }
1036

    
1037
      [Test]
1038
      public void UpdateOrAdd2()
1039
      {
1040
          ICollection<String> coll = new LinkedList<String>();
1041
          // s1 and s2 are distinct objects but contain the same text:
1042
          String old, s1 = "abc", s2 = ("def" + s1).Substring(3);
1043
          Assert.IsFalse(coll.UpdateOrAdd(s1, out old));
1044
          Assert.AreEqual(null, old);
1045
          Assert.IsTrue(coll.UpdateOrAdd(s2, out old));
1046
          Assert.IsTrue(Object.ReferenceEquals(s1, old));
1047
          Assert.IsFalse(Object.ReferenceEquals(s2, old));
1048
      }
1049

    
1050

    
1051
      [Test]
1052
      public void RemoveWithReturn()
1053
      {
1054
        KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
1055

    
1056
        Assert.IsTrue(lst.Remove(p, out p));
1057
        Assert.AreEqual(3, p.Key);
1058
        Assert.AreEqual(33, p.Value);
1059
        Assert.AreEqual(4, lst[3].Key);
1060
        Assert.AreEqual(34, lst[3].Value);
1061
        p = new KeyValuePair<int, int>(13, 78);
1062
        Assert.IsFalse(lst.Remove(p, out p));
1063
      }
1064
    }
1065

    
1066

    
1067
    [TestFixture]
1068
    public class Inserting
1069
    {
1070
      private IList<int> lst;
1071

    
1072

    
1073
      [SetUp]
1074
      public void Init() { lst = new LinkedList<int>(); }
1075

    
1076

    
1077
      [TearDown]
1078
      public void Dispose() { lst = null; }
1079

    
1080

    
1081
      [Test]
1082
      public void Insert()
1083
      {
1084
        lst.Insert(0, 5);
1085
        Assert.IsTrue(IC.eq(lst, 5));
1086
        lst.Insert(0, 7);
1087
        Assert.IsTrue(IC.eq(lst, 7, 5));
1088
        lst.Insert(1, 4);
1089
        Assert.IsTrue(IC.eq(lst, 7, 4, 5));
1090
        lst.Insert(3, 2);
1091
        Assert.IsTrue(IC.eq(lst, 7, 4, 5, 2));
1092
      }
1093

    
1094
      [Test]
1095
      public void InsertDuplicate()
1096
      {
1097
        lst.Insert(0, 5);
1098
        Assert.IsTrue(IC.eq(lst, 5));
1099
        lst.Insert(0, 7);
1100
        Assert.IsTrue(IC.eq(lst, 7, 5));
1101
        lst.Insert(1, 5);
1102
        Assert.IsTrue(IC.eq(lst, 7, 5, 5));
1103
      }
1104

    
1105
      [Test]
1106
      public void InsertAllDuplicate1()
1107
      {
1108
        lst.Insert(0, 3);
1109
        Assert.IsTrue(IC.eq(lst, 3));
1110
        lst.Insert(0, 7);
1111
        Assert.IsTrue(IC.eq(lst, 7, 3));
1112
        lst.InsertAll<int>(1, new int[] { 1, 2, 3, 4 });
1113
        Assert.IsTrue(IC.eq(lst, 7, 1, 2, 3, 4, 3));
1114
        Assert.IsTrue(lst.Check());
1115
      }
1116
      [Test]
1117
      public void InsertAllDuplicate2()
1118
      {
1119
        lst.Insert(0, 3);
1120
        Assert.IsTrue(IC.eq(lst, 3));
1121
        lst.Insert(0, 7);
1122
        Assert.IsTrue(IC.eq(lst, 7, 3));
1123
        lst.InsertAll<int>(1, new int[] { 5, 6, 5, 8 });
1124
        Assert.IsTrue(lst.Check());
1125
        Assert.IsTrue(IC.eq(lst, 7, 5, 6, 5, 8, 3));
1126
      }
1127

    
1128
      [Test]
1129
      [ExpectedException(typeof(IndexOutOfRangeException))]
1130
      public void BadInsertLow()
1131
      {
1132
        lst.Add(7);
1133
        lst.Insert(-1, 9);
1134
      }
1135

    
1136

    
1137
      [Test]
1138
      [ExpectedException(typeof(IndexOutOfRangeException))]
1139
      public void BadInsertHi()
1140
      {
1141
        lst.Add(6);
1142
        lst.Insert(2, 11);
1143
      }
1144

    
1145

    
1146
      [Test]
1147
      public void FIFO()
1148
      {
1149
        for (int i = 0; i < 7; i++)
1150
          lst.Add(2 * i);
1151

    
1152
        Assert.IsTrue(lst.FIFO);
1153
        Assert.AreEqual(0, lst.Remove());
1154
        Assert.AreEqual(2, lst.Remove());
1155
        lst.FIFO = false;
1156
        Assert.AreEqual(12, lst.Remove());
1157
        Assert.AreEqual(10, lst.Remove());
1158
        lst.FIFO = true;
1159
        Assert.AreEqual(4, lst.Remove());
1160
        Assert.AreEqual(6, lst.Remove());
1161
      }
1162

    
1163

    
1164
      [Test]
1165
      public void InsertFirstLast()
1166
      {
1167
        lst.InsertFirst(4);
1168
        lst.InsertLast(5);
1169
        lst.InsertFirst(14);
1170
        lst.InsertLast(15);
1171
        lst.InsertFirst(24);
1172
        lst.InsertLast(25);
1173
        lst.InsertFirst(34);
1174
        lst.InsertLast(55);
1175
        Assert.IsTrue(IC.eq(lst, 34, 24, 14, 4, 5, 15, 25, 55));
1176
      }
1177

    
1178

    
1179
      [Test]
1180
      public void InsertFirst()
1181
      {
1182
        lst.Add(2);
1183
        lst.Add(3);
1184
        lst.Add(2);
1185
        lst.Add(5);
1186
        lst.ViewOf(2).InsertFirst(7);
1187
        Assert.IsTrue(lst.Check());
1188
        Assert.IsTrue(IC.eq(lst, 7, 2, 3, 2, 5));
1189
        lst.ViewOf(3).InsertFirst(8);
1190
        Assert.IsTrue(lst.Check());
1191
        Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 5));
1192
        lst.ViewOf(5).InsertFirst(9);
1193
        Assert.IsTrue(lst.Check());
1194
        Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 9, 5));
1195
      }
1196

    
1197

    
1198
      [Test]
1199
      public void BadInsertFirst()
1200
      {
1201
        lst.Add(2);
1202
        lst.Add(3);
1203
        lst.Add(2);
1204
        lst.Add(5);
1205
        Assert.IsNull(lst.ViewOf(4));
1206
      }
1207

    
1208

    
1209
      [Test]
1210
      public void InsertAfter()
1211
      {
1212
        lst.Add(1);
1213
        lst.Add(2);
1214
        lst.Add(3);
1215
        lst.Add(2);
1216
        lst.Add(5);
1217
        lst.LastViewOf(2).InsertLast(7);
1218
        Assert.IsTrue(lst.Check());
1219
        Assert.IsTrue(IC.eq(lst, 1, 2, 3, 2, 7, 5));
1220
        lst.LastViewOf(1).InsertLast(8);
1221
        Assert.IsTrue(lst.Check());
1222
        Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5));
1223
        lst.LastViewOf(5).InsertLast(9);
1224
        Assert.IsTrue(lst.Check());
1225
        Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5, 9));
1226
      }
1227

    
1228

    
1229
      [Test]
1230
      public void BadInsertAfter()
1231
      {
1232
        lst.Add(2);
1233
        lst.Add(3);
1234
        lst.Add(2);
1235
        lst.Add(5);
1236
        Assert.IsNull(lst.ViewOf(4));
1237
      }
1238

    
1239

    
1240
      [Test]
1241
      public void InsertAll()
1242
      {
1243
        lst.Add(1);
1244
        lst.Add(2);
1245
        lst.Add(3);
1246
        lst.Add(4);
1247

    
1248
        IList<int> lst2 = new LinkedList<int>();
1249

    
1250
        lst2.Add(7); lst2.Add(8); lst2.Add(9);
1251
        lst.InsertAll(0, lst2);
1252
        Assert.IsTrue(lst.Check());
1253
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4));
1254
        lst.InsertAll(7, lst2);
1255
        Assert.IsTrue(lst.Check());
1256
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4, 7, 8, 9));
1257
        lst.InsertAll(5, lst2);
1258
        Assert.IsTrue(lst.Check());
1259
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9));
1260
      }
1261

    
1262

    
1263
      [Test]
1264
      public void Map()
1265
      {
1266
        Fun<int, string> m = delegate(int i) { return "<<" + i + ">>"; };
1267
        IList<string> r = lst.Map(m);
1268

    
1269
        Assert.IsTrue(r.Check());
1270
        Assert.IsTrue(r.IsEmpty);
1271
        lst.Add(1);
1272
        lst.Add(2);
1273
        lst.Add(3);
1274
        lst.Add(4);
1275
        r = lst.Map(m);
1276
        Assert.IsTrue(r.Check());
1277
        Assert.AreEqual(4, r.Count);
1278
        for (int i = 0; i < 4; i++)
1279
          Assert.AreEqual("<<" + (i + 1) + ">>", r[i]);
1280
      }
1281
      [Test]
1282
      [ExpectedException(typeof(CollectionModifiedException))]
1283
      public void BadMapper()
1284
      {
1285
        lst.Add(1);
1286
        lst.Add(2);
1287
        lst.Add(3);
1288
        Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
1289
        lst.Map(m);
1290
      }
1291

    
1292
      [Test]
1293
      [ExpectedException(typeof(CollectionModifiedException))]
1294
      public void ModifyingFindAll()
1295
      {
1296
        lst.Add(1);
1297
        lst.Add(2);
1298
        lst.Add(3);
1299
        Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
1300
        lst.FindAll(m);
1301
      }
1302

    
1303
      [Test]
1304
      [ExpectedException(typeof(CollectionModifiedException))]
1305
      public void BadMapperView()
1306
      {
1307
        lst = lst.View(0, 0);
1308
        lst.Add(1);
1309
        lst.Add(2);
1310
        lst.Add(3);
1311
        Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
1312
        lst.Map(m);
1313
      }
1314

    
1315
      [Test]
1316
      [ExpectedException(typeof(CollectionModifiedException))]
1317
      public void ModifyingFindAllView()
1318
      {
1319
        lst = lst.View(0, 0);
1320
        lst.Add(1);
1321
        lst.Add(2);
1322
        lst.Add(3);
1323
        Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
1324
        lst.FindAll(m);
1325
      }
1326

    
1327

    
1328
      [Test]
1329
      [ExpectedException(typeof(NoSuchItemException))]
1330
      public void BadRemove() { lst.Remove(); }
1331

    
1332
      [Test]
1333
      [ExpectedException(typeof(NoSuchItemException))]
1334
      public void BadRemoveFirst() { lst.RemoveFirst(); }
1335

    
1336
      [Test]
1337
      [ExpectedException(typeof(NoSuchItemException))]
1338
      public void BadRemoveLast() { lst.RemoveLast(); }
1339

    
1340

    
1341
      [Test]
1342
      public void RemoveFirstLast()
1343
      {
1344
        lst.Add(1);
1345
        lst.Add(2);
1346
        lst.Add(3);
1347
        lst.Add(4);
1348
        Assert.AreEqual(1, lst.RemoveFirst());
1349
        Assert.AreEqual(4, lst.RemoveLast());
1350
        Assert.AreEqual(2, lst.RemoveFirst());
1351
        Assert.AreEqual(3, lst.RemoveLast());
1352
        Assert.IsTrue(lst.IsEmpty);
1353
      }
1354

    
1355
      [Test]
1356
      [ExpectedException(typeof(NoSuchItemException))]
1357
      public void RemoveFirstEmpty()
1358
      {
1359
        lst.RemoveFirst();
1360
      }
1361

    
1362
      [Test]
1363
      [ExpectedException(typeof(NoSuchItemException))]
1364
      public void RemoveLastEmpty()
1365
      {
1366
        lst.RemoveLast();
1367
      }
1368

    
1369
      [Test]
1370
      public void Reverse()
1371
      {
1372
        for (int i = 0; i < 10; i++)
1373
          lst.Add(i);
1374

    
1375
        lst.Reverse();
1376
        Assert.IsTrue(lst.Check());
1377
        Assert.IsTrue(IC.eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
1378
        lst.View(0, 3).Reverse();
1379
        Assert.IsTrue(lst.Check());
1380
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
1381
        lst.View(7, 0).Reverse();
1382
        Assert.IsTrue(lst.Check());
1383
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
1384
        lst.View(7, 3).Reverse();
1385
        Assert.IsTrue(lst.Check());
1386
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
1387
        lst.View(5, 1).Reverse();
1388
        Assert.IsTrue(lst.Check());
1389
        Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
1390
      }
1391

    
1392

    
1393
      [Test]
1394
      [ExpectedException(typeof(ArgumentOutOfRangeException))]
1395
      public void BadReverse()
1396
      {
1397
        for (int i = 0; i < 10; i++)
1398
          lst.Add(i);
1399

    
1400
        lst.View(8, 3).Reverse();
1401
      }
1402
    }
1403

    
1404

    
1405

    
1406
    [TestFixture]
1407
    public class SortingTests
1408
    {
1409
      private IList<int> lst;
1410

    
1411

    
1412
      [SetUp]
1413
      public void Init() { lst = new LinkedList<int>(); }
1414

    
1415

    
1416
      [TearDown]
1417
      public void Dispose() { lst = null; }
1418

    
1419

    
1420
      [Test]
1421
      public void Sort()
1422
      {
1423
        lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
1424
        Assert.IsFalse(lst.IsSorted(new IC()));
1425
        lst.Sort(new IC());
1426
        Assert.IsTrue(lst.Check());
1427
        Assert.IsTrue(lst.IsSorted());
1428
        Assert.IsTrue(lst.IsSorted(new IC()));
1429
        Assert.IsTrue(IC.eq(lst, 3, 5, 5, 6, 7));
1430
      }
1431

    
1432

    
1433
      [Test]
1434
      public void Stability()
1435
      {
1436
        IList<KeyValuePair<int, string>> lst2 = new LinkedList<KeyValuePair<int, string>>();
1437
        SCG.IComparer<KeyValuePair<int, string>> c = new KeyValuePairComparer<int, string>(new IC());
1438

    
1439
        lst2.Add(new KeyValuePair<int, string>(5, "a"));
1440
        lst2.Add(new KeyValuePair<int, string>(5, "b"));
1441
        lst2.Add(new KeyValuePair<int, string>(6, "c"));
1442
        lst2.Add(new KeyValuePair<int, string>(4, "d"));
1443
        lst2.Add(new KeyValuePair<int, string>(3, "e"));
1444
        lst2.Add(new KeyValuePair<int, string>(4, "f"));
1445
        lst2.Add(new KeyValuePair<int, string>(5, "handle"));
1446
        Assert.IsFalse(lst2.IsSorted(c));
1447
        lst2.Sort(c);
1448
        Assert.IsTrue(lst2.IsSorted(c));
1449

    
1450
        KeyValuePair<int, string> p = lst2.RemoveFirst();
1451

    
1452
        Assert.AreEqual(3, p.Key);
1453
        Assert.AreEqual("e", p.Value);
1454
        p = lst2.RemoveFirst();
1455
        Assert.AreEqual(4, p.Key);
1456
        Assert.AreEqual("d", p.Value);
1457
        p = lst2.RemoveFirst();
1458
        Assert.AreEqual(4, p.Key);
1459
        Assert.AreEqual("f", p.Value);
1460
        p = lst2.RemoveFirst();
1461
        Assert.AreEqual(5, p.Key);
1462
        Assert.AreEqual("a", p.Value);
1463
        p = lst2.RemoveFirst();
1464
        Assert.AreEqual(5, p.Key);
1465
        Assert.AreEqual("b", p.Value);
1466
        p = lst2.RemoveFirst();
1467
        Assert.AreEqual(5, p.Key);
1468
        Assert.AreEqual("handle", p.Value);
1469
        p = lst2.RemoveFirst();
1470
        Assert.AreEqual(6, p.Key);
1471
        Assert.AreEqual("c", p.Value);
1472
        Assert.IsTrue(lst2.IsEmpty);
1473
      }
1474
    }
1475
    [TestFixture]
1476
    public class ShuffleTests
1477
    {
1478
      private IList<int> lst;
1479

    
1480

    
1481
      [SetUp]
1482
      public void Init() { lst = new LinkedList<int>(); }
1483

    
1484

    
1485
      [TearDown]
1486
      public void Dispose() { lst = null; }
1487

    
1488

    
1489
      [Test]
1490
      public void Shuffle()
1491
      {
1492
        lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
1493
        for (int i = 0; i < 100; i++)
1494
        {
1495
          lst.Shuffle(new C5Random(i + 1));
1496
          Assert.IsTrue(lst.Check(), "Check " + i);
1497
          int[] lst2 = lst.ToArray();
1498
          Sorting.IntroSort<int>(lst2);
1499
          Assert.IsTrue(IC.eq(lst2, 3, 5, 5, 6, 7), "Contents " + i);
1500
        }
1501
      }
1502
    }
1503
  }
1504

    
1505

    
1506
  namespace IStackQueue
1507
  {
1508
    [TestFixture]
1509
    public class Stack
1510
    {
1511
      private IStack<int> list;
1512

    
1513

    
1514
      [SetUp]
1515
      public void Init() { list = new LinkedList<int>(); }
1516

    
1517

    
1518
      [Test]
1519
      public void Normal()
1520
      {
1521
        list.Push(7);
1522
        list.Push(5);
1523
        list.Push(7);
1524
        list.Push(8);
1525
        list.Push(9);
1526
        Assert.AreEqual(9, list.Pop());
1527
        Assert.AreEqual(8, list.Pop());
1528
        Assert.AreEqual(7, list.Pop());
1529
        Assert.AreEqual(5, list.Pop());
1530
        Assert.AreEqual(7, list.Pop());
1531
      }
1532

    
1533

    
1534
      [Test]
1535
      [ExpectedException(typeof(NoSuchItemException))]
1536
      public void PopEmpty()
1537
      {
1538
        list.Push(5);
1539
        Assert.AreEqual(5, list.Pop());
1540
        list.Pop();
1541
      }
1542

    
1543

    
1544
      [TearDown]
1545
      public void Dispose() { list = null; }
1546
    }
1547
    [TestFixture]
1548
    public class Queue
1549
    {
1550
      private IQueue<int> list;
1551

    
1552

    
1553
      [SetUp]
1554
      public void Init() { list = new LinkedList<int>(); }
1555

    
1556

    
1557
      [Test]
1558
      public void Normal()
1559
      {
1560
        list.Enqueue(7);
1561
        list.Enqueue(5);
1562
        list.Enqueue(7);
1563
        list.Enqueue(8);
1564
        list.Enqueue(9);
1565
        Assert.AreEqual(7, list.Dequeue());
1566
        Assert.AreEqual(5, list.Dequeue());
1567
        Assert.AreEqual(7, list.Dequeue());
1568
        Assert.AreEqual(8, list.Dequeue());
1569
        Assert.AreEqual(9, list.Dequeue());
1570
      }
1571

    
1572

    
1573
      [Test]
1574
      [ExpectedException(typeof(NoSuchItemException))]
1575
      public void DeQueueEmpty()
1576
      {
1577
        list.Enqueue(5);
1578
        Assert.AreEqual(5, list.Dequeue());
1579
        list.Dequeue();
1580
      }
1581

    
1582

    
1583
      [TearDown]
1584
      public void Dispose() { list = null; }
1585
    }
1586
  }
1587

    
1588

    
1589
  namespace Range
1590
  {
1591
    [TestFixture]
1592
    public class Range
1593
    {
1594
      private IList<int> lst;
1595

    
1596

    
1597
      [SetUp]
1598
      public void Init() { lst = new LinkedList<int>(); }
1599

    
1600

    
1601
      [TearDown]
1602
      public void Dispose() { lst = null; }
1603

    
1604

    
1605
      [Test]
1606
      public void GetRange()
1607
      {
1608
        //Assert.IsTrue(IC.eq(lst[0, 0)));
1609
        for (int i = 0; i < 10; i++) lst.Add(i);
1610

    
1611
        Assert.IsTrue(IC.eq(lst[0, 3], 0, 1, 2));
1612
        Assert.IsTrue(IC.eq(lst[3, 4], 3, 4, 5, 6));
1613
        Assert.IsTrue(IC.eq(lst[6, 4], 6, 7, 8, 9));
1614
      }
1615

    
1616

    
1617
      [Test]
1618
      [ExpectedException(typeof(ArgumentOutOfRangeException))]
1619
      public void BadGetRange()
1620
      {
1621
        object foo = lst[0, 11];
1622
      }
1623

    
1624

    
1625
      [Test]
1626
      public void Backwards()
1627
      {
1628
        for (int i = 0; i < 10; i++) lst.Add(i);
1629

    
1630
        Assert.IsTrue(IC.eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
1631
        Assert.IsTrue(IC.eq(lst[0, 4].Backwards(), 3, 2, 1, 0));
1632
        Assert.IsTrue(IC.eq(lst[3, 4].Backwards(), 6, 5, 4, 3));
1633
        Assert.IsTrue(IC.eq(lst[6, 4].Backwards(), 9, 8, 7, 6));
1634
      }
1635

    
1636

    
1637
      [Test]
1638
      public void DirectionAndCount()
1639
      {
1640
        for (int i = 0; i < 10; i++) lst.Add(i);
1641

    
1642
        Assert.AreEqual(EnumerationDirection.Forwards, lst.Direction);
1643
        Assert.AreEqual(EnumerationDirection.Forwards, lst[3, 7].Direction);
1644
        Assert.AreEqual(EnumerationDirection.Backwards, lst[3, 7].Backwards().Direction);
1645
        Assert.AreEqual(EnumerationDirection.Backwards, lst.Backwards().Direction);
1646
        Assert.AreEqual(4, lst[3, 4].Count);
1647
        Assert.AreEqual(4, lst[3, 4].Backwards().Count);
1648
        Assert.AreEqual(10, lst.Backwards().Count);
1649
      }
1650

    
1651

    
1652
      [Test]
1653
      [ExpectedException(typeof(CollectionModifiedException))]
1654
      public void MoveNextAfterUpdate()
1655
      {
1656
        for (int i = 0; i < 10; i++) lst.Add(i);
1657

    
1658
        foreach (int i in lst)
1659
        {
1660
          lst.Add(45 + i);
1661
        }
1662
      }
1663
    }
1664
  }
1665

    
1666

    
1667

    
1668

    
1669
  namespace View
1670
  {
1671
    [TestFixture]
1672
    public class Simple
1673
    {
1674
      LinkedList<int> list, view;
1675

    
1676

    
1677
      [SetUp]
1678
      public void Init()
1679
      {
1680
        list = new LinkedList<int>();
1681
        list.Add(0); list.Add(1); list.Add(2); list.Add(3);
1682
        view = (LinkedList<int>)list.View(1, 2);
1683
      }
1684

    
1685

    
1686
      [TearDown]
1687
      public void Dispose()
1688
      {
1689
        list = view = null;
1690
      }
1691

    
1692

    
1693
      void check()
1694
      {
1695
        Assert.IsTrue(list.Check());
1696
        Assert.IsTrue(view.Check());
1697
      }
1698

    
1699

    
1700
      [Test]
1701
      public void InsertPointer()
1702
      {
1703
        IList<int> view2 = list.View(2, 0);
1704
        list.Insert(view2, 7);
1705
        check();
1706
        list.Insert(list, 8);
1707
        check();
1708
        view.Insert(view2, 9);
1709
        check();
1710
        view.Insert(list.View(3, 2), 10);
1711
        check();
1712
        view.Insert(list.ViewOf(0), 11);
1713
        check();
1714
        Assert.IsTrue(IC.eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8));
1715
        Assert.IsTrue(IC.eq(view, 11, 1, 9, 7, 2, 10));
1716
      }
1717

    
1718
      [Test]
1719
      [ExpectedException(typeof(IndexOutOfRangeException))]
1720
      public void InsertPointerBad1()
1721
      {
1722
        view.Insert(list.View(0, 0), 7);
1723
      }
1724

    
1725
      [Test]
1726
      [ExpectedException(typeof(IndexOutOfRangeException))]
1727
      public void InsertPointerBad2()
1728
      {
1729
        view.Insert(list, 7);
1730
      }
1731

    
1732
      [Test]
1733
      [ExpectedException(typeof(IncompatibleViewException))]
1734
      public void InsertPointerBad3()
1735
      {
1736
        list.Insert(new ArrayList<int>(), 7);
1737
      }
1738

    
1739
      [Test]
1740
      [ExpectedException(typeof(IncompatibleViewException))]
1741
      public void InsertPointerBad4()
1742
      {
1743
        list.Insert(new ArrayList<int>().View(0, 0), 7);
1744
      }
1745

    
1746
      [Test]
1747
      public void Span()
1748
      {
1749
        IList<int> span = list.View(1, 0).Span(list.View(2, 0));
1750
        Assert.IsTrue(span.Check());
1751
        Assert.AreEqual(1, span.Offset);
1752
        Assert.AreEqual(1, span.Count);
1753
        span = list.View(0, 2).Span(list.View(2, 2));
1754
        Assert.IsTrue(span.Check());
1755
        Assert.AreEqual(0, span.Offset);
1756
        Assert.AreEqual(4, span.Count);
1757
        span = list.View(3, 1).Span(list.View(1, 1));
1758
        Assert.IsNull(span);
1759
      }
1760

    
1761
      [Test]
1762
      public void ViewOf()
1763
      {
1764
        for (int i = 0; i < 4; i++)
1765
          list.Add(i);
1766
        IList<int> v = view.ViewOf(2);
1767
        Assert.IsTrue(v.Check());
1768
        Assert.IsTrue(IC.eq(v, 2));
1769
        Assert.AreEqual(2, v.Offset);
1770
        v = list.ViewOf(2);
1771
        Assert.IsTrue(v.Check());
1772
        Assert.IsTrue(IC.eq(v, 2));
1773
        Assert.AreEqual(2, v.Offset);
1774
        v = list.LastViewOf(2);
1775
        Assert.IsTrue(v.Check());
1776
        Assert.IsTrue(IC.eq(v, 2));
1777
        Assert.AreEqual(6, v.Offset);
1778
      }
1779

    
1780
      [Test]
1781
      public void BadViewOf()
1782
      {
1783
        Assert.IsNull(view.ViewOf(5));
1784
        Assert.IsNull(view.LastViewOf(5));
1785
        Assert.IsNull(view.ViewOf(3));
1786
        Assert.IsNull(view.LastViewOf(3));
1787
        Assert.IsNull(view.ViewOf(0));
1788
        Assert.IsNull(view.LastViewOf(0));
1789
      }
1790

    
1791
      [Test]
1792
      public void ArrayStuff()
1793
      {
1794
        Assert.IsTrue(IC.eq(view.ToArray(), 1, 2));
1795
        int[] extarray = new int[5];
1796
        view.CopyTo(extarray, 2);
1797
        Assert.IsTrue(IC.eq(extarray, 0, 0, 1, 2, 0));
1798
      }
1799

    
1800

    
1801
      [Test]
1802
      public void Add()
1803
      {
1804
        check();
1805
        Assert.IsTrue(IC.eq(list, 0, 1, 2, 3));
1806
        Assert.IsTrue(IC.eq(view, 1, 2));
1807
        view.InsertFirst(10);
1808
        check();
1809
        Assert.IsTrue(IC.eq(list, 0, 10, 1, 2, 3));
1810
        Assert.IsTrue(IC.eq(view, 10, 1, 2));
1811
        view.Clear();
1812
        Assert.IsFalse(view.IsReadOnly);
1813
        Assert.IsTrue(view.AllowsDuplicates);
1814
        Assert.IsTrue(view.IsEmpty);
1815
        check();
1816
        Assert.IsTrue(IC.eq(list, 0, 3));
1817
        Assert.IsTrue(IC.eq(view));
1818
        view.Add(8);
1819
        Assert.IsFalse(view.IsEmpty);
1820
        Assert.IsTrue(view.AllowsDuplicates);
1821
        Assert.IsFalse(view.IsReadOnly);
1822
        check();
1823
        Assert.IsTrue(IC.eq(list, 0, 8, 3));
1824
        Assert.IsTrue(IC.eq(view, 8));
1825
        view.Add(12);
1826
        check();
1827
        Assert.IsTrue(IC.eq(list, 0, 8, 12, 3));
1828
        Assert.IsTrue(IC.eq(view, 8, 12));
1829
        view./*ViewOf(12).*/InsertLast(15);
1830
        check();
1831
        Assert.IsTrue(IC.eq(list, 0, 8, 12, 15, 3));
1832
        Assert.IsTrue(IC.eq(view, 8, 12, 15));
1833
        view.ViewOf(12).InsertFirst(18);
1834
        check();
1835
        Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 3));
1836
        Assert.IsTrue(IC.eq(view, 8, 18, 12, 15));
1837

    
1838
        LinkedList<int> lst2 = new LinkedList<int>();
1839

    
1840
        lst2.Add(90); lst2.Add(92);
1841
        view.AddAll(lst2);
1842
        check();
1843
        Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 3));
1844
        Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92));
1845
        view.InsertLast(66);
1846
        check();
1847
        Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3));
1848
        Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92, 66));
1849
      }
1850

    
1851

    
1852
      [Test]
1853
      public void Bxxx()
1854
      {
1855
        Assert.IsTrue(IC.eq(view.Backwards(), 2, 1));
1856
        Assert.AreSame(list, view.Underlying);
1857
        Assert.IsNull(list.Underlying);
1858
        Assert.AreEqual(EnumerationDirection.Forwards, view.Direction);
1859
        Assert.AreEqual(EnumerationDirection.Backwards, view.Backwards().Direction);
1860
        Assert.AreEqual(0, list.Offset);
1861
        Assert.AreEqual(1, view.Offset);
1862
      }
1863

    
1864

    
1865
      [Test]
1866
      public void Contains()
1867
      {
1868
        Assert.IsTrue(view.Contains(1));
1869
        Assert.IsFalse(view.Contains(0));
1870

    
1871
        LinkedList<int> lst2 = new LinkedList<int>();
1872

    
1873
        lst2.Add(2);
1874
        Assert.IsTrue(view.ContainsAll(lst2));
1875
        lst2.Add(3);
1876
        Assert.IsFalse(view.ContainsAll(lst2));
1877
        Assert.AreEqual(Speed.Linear, view.ContainsSpeed);
1878
        Assert.AreEqual(2, view.Count);
1879
        view.Add(1);
1880
        Assert.AreEqual(1, view.ContainsCount(2));
1881
        Assert.AreEqual(2, view.ContainsCount(1));
1882
        Assert.AreEqual(3, view.Count);
1883
      }
1884

    
1885

    
1886
      [Test]
1887
      public void CreateView()
1888
      {
1889
        LinkedList<int> view2 = (LinkedList<int>)view.View(1, 0);
1890

    
1891
        Assert.AreSame(list, view2.Underlying);
1892
      }
1893

    
1894

    
1895
      [Test]
1896
      public void FIFO()
1897
      {
1898
        Assert.IsTrue(view.FIFO);
1899
        view.Add(23); view.Add(24); view.Add(25);
1900
        check();
1901
        Assert.IsTrue(IC.eq(view, 1, 2, 23, 24, 25));
1902
        Assert.AreEqual(1, view.Remove());
1903
        check();
1904
        Assert.IsTrue(IC.eq(view, 2, 23, 24, 25));
1905
        view.FIFO = false;
1906
        Assert.IsFalse(view.FIFO);
1907
        Assert.AreEqual(25, view.Remove());
1908
        check();
1909
        Assert.IsTrue(IC.eq(view, 2, 23, 24));
1910
      }
1911

    
1912

    
1913
      [Test]
1914
      public void MapEtc()
1915
      {
1916
        LinkedList<double> dbl = (LinkedList<double>)view.Map(new Fun<int, double>(delegate(int i) { return i / 10.0; }));
1917

    
1918
        Assert.IsTrue(dbl.Check());
1919
        Assert.AreEqual(0.1, dbl[0]);
1920
        Assert.AreEqual(0.2, dbl[1]);
1921
        for (int i = 0; i < 10; i++) view.Add(i);
1922

    
1923
        list = (LinkedList<int>)view.FindAll(new Fun<int, bool>(delegate(int i) { return i % 4 == 1; }));
1924
        Assert.IsTrue(list.Check());
1925
        Assert.IsTrue(IC.eq(list, 1, 1, 5, 9));
1926
      }
1927

    
1928

    
1929
      [Test]
1930
      public void FL()
1931
      {
1932
        Assert.AreEqual(1, view.First);
1933
        Assert.AreEqual(2, view.Last);
1934
      }
1935

    
1936

    
1937
      [Test]
1938
      public void Indexing()
1939
      {
1940
        list.Clear();
1941
        for (int i = 0; i < 20; i++) list.Add(i);
1942

    
1943
        view = (LinkedList<int>)list.View(5, 7);
1944
        for (int i = 0; i < 7; i++) Assert.AreEqual(i + 5, view[i]);
1945

    
1946
        for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.IndexOf(i + 5));
1947

    
1948
        for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.LastIndexOf(i + 5));
1949
      }
1950

    
1951

    
1952
      [Test]
1953
      public void INsert()
1954
      {
1955
        view.Insert(0, 34);
1956
        view.Insert(1, 35);
1957
        view.Insert(4, 36);
1958
        Assert.IsTrue(view.Check());
1959
        Assert.IsTrue(IC.eq(view, 34, 35, 1, 2, 36));
1960

    
1961
        IList<int> list2 = new LinkedList<int>();
1962

    
1963
        list2.AddAll(view);
1964
        view.InsertAll(3, list2);
1965
        Assert.IsTrue(view.Check());
1966
        Assert.IsTrue(IC.eq(view, 34, 35, 1, 34, 35, 1, 2, 36, 2, 36));
1967
      }
1968

    
1969

    
1970
      [Test]
1971
      public void Sort()
1972
      {
1973
        view.Add(45); view.Add(47); view.Add(46); view.Add(48);
1974
        Assert.IsFalse(view.IsSorted(new IC()));
1975
        view.Sort(new IC());
1976
        check();
1977
        Assert.IsTrue(IC.eq(list, 0, 1, 2, 45, 46, 47, 48, 3));
1978
        Assert.IsTrue(IC.eq(view, 1, 2, 45, 46, 47, 48));
1979
      }
1980

    
1981

    
1982
      [Test]
1983
      public void Remove()
1984
      {
1985
        view.FIFO = false;
1986
        view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
1987
        Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
1988
        Assert.IsTrue(view.Remove(1));
1989
        check();
1990
        Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 3, 0));
1991
        Assert.IsTrue(view.Remove(1));
1992
        check();
1993
        Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3, 0));
1994
        Assert.IsTrue(view.Remove(0));
1995
        check();
1996
        Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3));
1997
        view.RemoveAllCopies(3);
1998
        check();
1999
        Assert.IsTrue(IC.eq(view, 1, 2, 5));
2000
        Assert.IsTrue(IC.eq(list, 0, 1, 2, 5, 3));
2001
        view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
2002
        Assert.IsTrue(IC.eq(view, 1, 2, 5, 1, 5, 3, 1, 3, 0));
2003

    
2004
        view.FIFO = true;
2005
        view.Clear(); view.Add(1); view.Add(2);
2006

    
2007
        view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
2008
        Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
2009
        Assert.IsTrue(view.Remove(1));
2010
        check();
2011
        Assert.IsTrue(IC.eq(view, 2, 1, 5, 3, 1, 3, 0));
2012
        Assert.IsTrue(view.Remove(1));
2013
        check();
2014
        Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3, 0));
2015
        Assert.IsTrue(view.Remove(0));
2016
        check();
2017
        Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3));
2018
        view.RemoveAllCopies(3);
2019
        check();
2020
        Assert.IsTrue(IC.eq(view, 2, 5, 1));
2021
        Assert.IsTrue(IC.eq(list, 0, 2, 5, 1, 3));
2022
        view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
2023
        Assert.IsTrue(IC.eq(view, 2, 5, 1, 1, 5, 3, 1, 3, 0));
2024

    
2025
        LinkedList<int> l2 = new LinkedList<int>();
2026

    
2027
        l2.Add(1); l2.Add(2); l2.Add(2); l2.Add(3); l2.Add(1);
2028
        view.RemoveAll(l2);
2029
        check();
2030
        Assert.IsTrue(IC.eq(view, 5, 5, 1, 3, 0));
2031
        view.RetainAll(l2);
2032
        check();
2033
        Assert.IsTrue(IC.eq(view, 1, 3));
2034
        view.Add(2); view.Add(4); view.Add(5);
2035
        Assert.AreEqual(1, view.RemoveAt(0));
2036
        Assert.AreEqual(5, view.RemoveAt(3));
2037
        Assert.AreEqual(2, view.RemoveAt(1));
2038
        check();
2039
        Assert.IsTrue(IC.eq(view, 3, 4));
2040
        view.Add(8);
2041
        Assert.AreEqual(3, view.RemoveFirst());
2042
        Assert.AreEqual(8, view.RemoveLast());
2043
        view.Add(2); view.Add(5); view.Add(3); view.Add(1);
2044
        view.RemoveInterval(1, 2);
2045
        check();
2046
        Assert.IsTrue(IC.eq(view, 4, 3, 1));
2047
      }
2048

    
2049

    
2050
      [Test]
2051
      public void Reverse()
2052
      {
2053
        view.Clear();
2054
        for (int i = 0; i < 10; i++) view.Add(10 + i);
2055

    
2056
        view.View(3, 4).Reverse();
2057
        check();
2058
        Assert.IsTrue(IC.eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19));
2059
        view.Reverse();
2060
        Assert.IsTrue(IC.eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10));
2061
        Assert.IsTrue(IC.eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3));
2062
      }
2063

    
2064

    
2065
      [Test]
2066
      public void Slide()
2067
      {
2068
        view.Slide(1);
2069
        check();
2070
        Assert.IsTrue(IC.eq(view, 2, 3));
2071
        view.Slide(-2);
2072
        check();
2073
        Assert.IsTrue(IC.eq(view, 0, 1));
2074
        view.Slide(0, 3);
2075
        check();
2076
        Assert.IsTrue(IC.eq(view, 0, 1, 2));
2077
        view.Slide(2, 1);
2078
        check();
2079
        Assert.IsTrue(IC.eq(view, 2));
2080
        Assert.AreEqual(view, view.Slide(-1, 0));
2081
        check();
2082
        Assert.IsTrue(IC.eq(view));
2083
        view.Add(28);
2084
        Assert.IsTrue(IC.eq(list, 0, 28, 1, 2, 3));
2085
      }
2086
      [Test]
2087
      public void Iterate()
2088
      {
2089
        list.Clear();
2090
        view = null;
2091
        foreach (int i in new int[] { 2, 4, 8, 13, 6, 1, 2, 7 }) list.Add(i);
2092

    
2093
        view = (LinkedList<int>)list.View(list.Count - 2, 2);
2094
        while (true)
2095
        {
2096
          //Console.WriteLine("View: {0}:  {1} --> {2}", view.Count, view.First, view.Last);
2097
          if ((view.Last - view.First) % 2 == 1)
2098
            view.Insert(1, 666);
2099
          check();
2100
          if (view.Offset == 0)
2101
            break;
2102
          else
2103
            view.Slide(-1, 2);
2104
        }
2105
        //foreach (int cell in list) Console.Write(" " + cell);
2106
        //Assert.IsTrue(list.Check());
2107
        Assert.IsTrue(IC.eq(list, 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7));
2108
      }
2109

    
2110

    
2111
      [Test]
2112
      public void SyncRoot()
2113
      {
2114
        Assert.AreSame(((System.Collections.IList)view).SyncRoot, ((System.Collections.IList)list).SyncRoot);
2115
      }
2116
    }
2117

    
2118
    [TestFixture]
2119
    public class MulipleViews
2120
    {
2121
      IList<int> list;
2122
      IList<int>[][] views;
2123
      [SetUp]
2124
      public void Init()
2125
      {
2126
        list = new LinkedList<int>();
2127
        for (int i = 0; i < 6; i++)
2128
          list.Add(i);
2129
        views = new IList<int>[7][];
2130
        for (int i = 0; i < 7; i++)
2131
        {
2132
          views[i] = new IList<int>[7 - i];
2133
          for (int j = 0; j < 7 - i; j++)
2134
            views[i][j] = list.View(i, j);
2135
        }
2136
      }
2137
      [TearDown]
2138
      public void Dispose()
2139
      {
2140
        list = null;
2141
        views = null;
2142
      }
2143
      [Test]
2144
      public void Insert()
2145
      {
2146
        Assert.IsTrue(list.Check(), "list check before insert");
2147
        list.Insert(3, 777);
2148
        Assert.IsTrue(list.Check(), "list check after insert");
2149
        for (int i = 0; i < 7; i++)
2150
          for (int j = 0; j < 7 - i; j++)
2151
          {
2152
            Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2153
            Assert.AreEqual(i < 3 && i + j > 3 ? j + 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2154
          }
2155
      }
2156
      [Test]
2157
      public void RemoveAt()
2158
      {
2159
        Assert.IsTrue(list.Check(), "list check before remove");
2160
        list.RemoveAt(3);
2161
        Assert.IsTrue(list.Check(), "list check after remove");
2162
        for (int i = 0; i < 7; i++)
2163
          for (int j = 0; j < 7 - i; j++)
2164
          {
2165
            Assert.AreEqual(i <= 3 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2166
            Assert.AreEqual(i <= 3 && i + j > 3 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2167
          }
2168
      }
2169

    
2170
      [Test]
2171
      public void RemoveInterval()
2172
      {
2173
        Assert.IsTrue(list.Check(), "list check before remove");
2174
        list.RemoveInterval(3, 2);
2175
        Assert.IsTrue(list.Check(), "list check after remove");
2176
        for (int i = 0; i < 7; i++)
2177
          for (int j = 0; j < 7 - i; j++)
2178
          {
2179
            Assert.AreEqual(i <= 3 ? i : i <= 5 ? 3 : i - 2, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2180
            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");
2181
          }
2182
      }
2183

    
2184

    
2185
      [Test]
2186
      public void InsertAtEnd()
2187
      {
2188
        Assert.IsTrue(list.Check(), "list check before insert");
2189
        list.InsertLast(777);
2190
        Assert.IsTrue(list.Check(), "list check after insert");
2191
        for (int i = 0; i < 7; i++)
2192
          for (int j = 0; j < 7 - i; j++)
2193
          {
2194
            Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2195
            Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2196
          }
2197
      }
2198
      [Test]
2199
      public void RemoveAtEnd()
2200
      {
2201
        Assert.IsTrue(list.Check(), "list check before remove");
2202
        list.RemoveAt(5);
2203
        Assert.IsTrue(list.Check(), "list check after remove");
2204
        for (int i = 0; i < 7; i++)
2205
          for (int j = 0; j < 7 - i; j++)
2206
          {
2207
            Assert.AreEqual(i <= 5 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2208
            Assert.AreEqual(i <= 5 && i + j > 5 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2209
          }
2210
      }
2211
      [Test]
2212
      public void InsertAtStart()
2213
      {
2214
        Assert.IsTrue(list.Check(), "list check before insert");
2215
        list.Insert(0, 777);
2216
        Assert.IsTrue(list.Check(), "list check after insert");
2217
        for (int i = 0; i < 7; i++)
2218
          for (int j = 0; j < 7 - i; j++)
2219
          {
2220
            Assert.AreEqual(i == 0 && j == 0 ? 0 : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2221
            Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2222
          }
2223
      }
2224
      [Test]
2225
      public void RemoveAtStart()
2226
      {
2227
        Assert.IsTrue(list.Check(), "list check before remove");
2228
        list.RemoveAt(0);
2229
        Assert.IsTrue(list.Check(), "list check after remove");
2230
        for (int i = 0; i < 7; i++)
2231
          for (int j = 0; j < 7 - i; j++)
2232
          {
2233
            Assert.AreEqual(i == 0 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2234
            Assert.AreEqual(i == 0 && j > 0 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2235
          }
2236
      }
2237
      [Test]
2238
      public void Clear()
2239
      {
2240
        Assert.IsTrue(list.Check(), "list check before clear");
2241
        views[2][3].Clear();
2242
        Assert.IsTrue(list.Check(), "list check after clear");
2243
        for (int i = 0; i < 7; i++)
2244
          for (int j = 0; j < 7 - i; j++)
2245
          {
2246
            Assert.AreEqual(i < 2 ? i : i < 6 ? 2 : i - 3, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2247
            Assert.AreEqual(s(i, j), views[i][j].Count, "view[" + i + "][" + j + "] count");
2248
          }
2249
      }
2250

    
2251
      private int s(int i, int j)
2252
      {
2253
        if (j == 0) return 0;
2254
        int k = i + j - 1; //end
2255
        if (i > 4 || k <= 1) return j;
2256
        if (i >= 2) return k > 4 ? k - 4 : 0;
2257
        if (i <= 2) return k >= 4 ? j - 3 : 2 - i;
2258
        return -1;
2259
      }
2260
      [Test]
2261
      public void InsertAll()
2262
      {
2263
        LinkedList<int> list2 = new LinkedList<int>();
2264
        for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
2265
        Assert.IsTrue(list.Check(), "list check before insertAll");
2266
        list.InsertAll(3, list2);
2267
        Assert.IsTrue(list.Check(), "list check after insertAll");
2268
        for (int i = 0; i < 7; i++)
2269
          for (int j = 0; j < 7 - i; j++)
2270
          {
2271
            Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2272
            Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2273
          }
2274
      }
2275

    
2276
      [Test]
2277
      public void AddAll()
2278
      {
2279
        LinkedList<int> list2 = new LinkedList<int>();
2280
        for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
2281
        Assert.IsTrue(list.Check(), "list check before AddAll");
2282
        list.View(1, 2).AddAll(list2);
2283
        Assert.IsTrue(list.Check(), "list check after AddAll");
2284
        for (int i = 0; i < 7; i++)
2285
          for (int j = 0; j < 7 - i; j++)
2286
          {
2287
            Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2288
            Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
2289
          }
2290
      }
2291

    
2292
      [Test]
2293
      public void RemoveAll1()
2294
      {
2295
        LinkedList<int> list2 = new LinkedList<int>();
2296
        list2.Add(1); list2.Add(3); list2.Add(4);
2297

    
2298
        for (int i = 0; i < 7; i++)
2299
        {
2300
          for (int j = 0; j < 7 - i; j++)
2301
          {
2302
            list = new LinkedList<int>();
2303
            for (int k = 0; k < 6; k++) list.Add(k);
2304
            LinkedList<int> v = (LinkedList<int>)list.View(i, j);
2305
            list.RemoveAll(list2);
2306
            Assert.IsTrue(list.Check(), "list check after RemoveAll, i=" + i + ", j=" + j);
2307
          }
2308
        }
2309
      }
2310
      [Test]
2311
      public void RemoveAll2()
2312
      {
2313
        LinkedList<int> list2 = new LinkedList<int>();
2314
        list2.Add(1); list2.Add(3); list2.Add(4);
2315
        Assert.IsTrue(list.Check(), "list check before RemoveAll");
2316
        list.RemoveAll(list2);
2317

    
2318
        Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
2319
        Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
2320
        Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
2321
        Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
2322
        Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
2323
        Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
2324
        Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
2325
        Assert.AreEqual(1, views[1][0].Offset, "view [1][0] offset");
2326
        Assert.AreEqual(1, views[1][1].Offset, "view [1][1] offset");
2327
        Assert.AreEqual(1, views[1][2].Offset, "view [1][2] offset");
2328
        Assert.AreEqual(1, views[1][3].Offset, "view [1][3] offset");
2329
        Assert.AreEqual(1, views[1][4].Offset, "view [1][4] offset");
2330
        Assert.AreEqual(1, views[1][5].Offset, "view [1][5] offset");
2331
        Assert.AreEqual(1, views[2][0].Offset, "view [2][0] offset");
2332
        Assert.AreEqual(1, views[2][1].Offset, "view [2][1] offset");
2333
        Assert.AreEqual(1, views[2][2].Offset, "view [2][2] offset");
2334
        Assert.AreEqual(1, views[2][3].Offset, "view [2][3] offset");
2335
        Assert.AreEqual(1, views[2][4].Offset, "view [2][4] offset");
2336
        Assert.AreEqual(2, views[3][0].Offset, "view [3][0] offset");
2337
        Assert.AreEqual(2, views[3][1].Offset, "view [3][1] offset");
2338
        Assert.AreEqual(2, views[3][2].Offset, "view [3][2] offset");
2339
        Assert.AreEqual(2, views[3][3].Offset, "view [3][3] offset");
2340
        Assert.AreEqual(2, views[4][0].Offset, "view [4][0] offset");
2341
        Assert.AreEqual(2, views[4][1].Offset, "view [4][1] offset");
2342
        Assert.AreEqual(2, views[4][2].Offset, "view [4][2] offset");
2343
        Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
2344
        Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
2345
        Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
2346

    
2347
        Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
2348
        Assert.AreEqual(1, views[0][1].Count, "view [0][1] count");
2349
        Assert.AreEqual(1, views[0][2].Count, "view [0][2] count");
2350
        Assert.AreEqual(2, views[0][3].Count, "view [0][3] count");
2351
        Assert.AreEqual(2, views[0][4].Count, "view [0][4] count");
2352
        Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
2353
        Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
2354
        Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
2355
        Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
2356
        Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
2357
        Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
2358
        Assert.AreEqual(1, views[1][4].Count, "view [1][4] count");
2359
        Assert.AreEqual(2, views[1][5].Count, "view [1][5] count");
2360
        Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
2361
        Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
2362
        Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
2363
        Assert.AreEqual(1, views[2][3].Count, "view [2][3] count");
2364
        Assert.AreEqual(2, views[2][4].Count, "view [2][4] count");
2365
        Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
2366
        Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
2367
        Assert.AreEqual(0, views[3][2].Count, "view [3][2] count");
2368
        Assert.AreEqual(1, views[3][3].Count, "view [3][3] count");
2369
        Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
2370
        Assert.AreEqual(0, views[4][1].Count, "view [4][1] count");
2371
        Assert.AreEqual(1, views[4][2].Count, "view [4][2] count");
2372
        Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
2373
        Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
2374
        Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
2375

    
2376
        Assert.IsTrue(list.Check(), "list check after RemoveAll");
2377
      }
2378

    
2379
      [Test]
2380
      public void RetainAll()
2381
      {
2382
        LinkedList<int> list2 = new LinkedList<int>();
2383
        list2.Add(2); list2.Add(4); list2.Add(5);
2384
        Assert.IsTrue(list.Check(), "list check before RetainAll");
2385
        list.RetainAll(list2);
2386
        Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
2387
        Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
2388
        Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
2389
        Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
2390
        Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
2391
        Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
2392
        Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
2393
        Assert.AreEqual(0, views[1][0].Offset, "view [1][0] offset");
2394
        Assert.AreEqual(0, views[1][1].Offset, "view [1][1] offset");
2395
        Assert.AreEqual(0, views[1][2].Offset, "view [1][2] offset");
2396
        Assert.AreEqual(0, views[1][3].Offset, "view [1][3] offset");
2397
        Assert.AreEqual(0, views[1][4].Offset, "view [1][4] offset");
2398
        Assert.AreEqual(0, views[1][5].Offset, "view [1][5] offset");
2399
        Assert.AreEqual(0, views[2][0].Offset, "view [2][0] offset");
2400
        Assert.AreEqual(0, views[2][1].Offset, "view [2][1] offset");
2401
        Assert.AreEqual(0, views[2][2].Offset, "view [2][2] offset");
2402
        Assert.AreEqual(0, views[2][3].Offset, "view [2][3] offset");
2403
        Assert.AreEqual(0, views[2][4].Offset, "view [2][4] offset");
2404
        Assert.AreEqual(1, views[3][0].Offset, "view [3][0] offset");
2405
        Assert.AreEqual(1, views[3][1].Offset, "view [3][1] offset");
2406
        Assert.AreEqual(1, views[3][2].Offset, "view [3][2] offset");
2407
        Assert.AreEqual(1, views[3][3].Offset, "view [3][3] offset");
2408
        Assert.AreEqual(1, views[4][0].Offset, "view [4][0] offset");
2409
        Assert.AreEqual(1, views[4][1].Offset, "view [4][1] offset");
2410
        Assert.AreEqual(1, views[4][2].Offset, "view [4][2] offset");
2411
        Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
2412
        Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
2413
        Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
2414

    
2415
        Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
2416
        Assert.AreEqual(0, views[0][1].Count, "view [0][1] count");
2417
        Assert.AreEqual(0, views[0][2].Count, "view [0][2] count");
2418
        Assert.AreEqual(1, views[0][3].Count, "view [0][3] count");
2419
        Assert.AreEqual(1, views[0][4].Count, "view [0][4] count");
2420
        Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
2421
        Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
2422
        Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
2423
        Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
2424
        Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
2425
        Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
2426
        Assert.AreEqual(2, views[1][4].Count, "view [1][4] count");
2427
        Assert.AreEqual(3, views[1][5].Count, "view [1][5] count");
2428
        Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
2429
        Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
2430
        Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
2431
        Assert.AreEqual(2, views[2][3].Count, "view [2][3] count");
2432
        Assert.AreEqual(3, views[2][4].Count, "view [2][4] count");
2433
        Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
2434
        Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
2435
        Assert.AreEqual(1, views[3][2].Count, "view [3][2] count");
2436
        Assert.AreEqual(2, views[3][3].Count, "view [3][3] count");
2437
        Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
2438
        Assert.AreEqual(1, views[4][1].Count, "view [4][1] count");
2439
        Assert.AreEqual(2, views[4][2].Count, "view [4][2] count");
2440
        Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
2441
        Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
2442
        Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
2443

    
2444

    
2445
        Assert.IsTrue(list.Check(), "list check after RetainAll");
2446
      }
2447

    
2448
      [Test]
2449
      public void RemoveAllCopies()
2450
      {
2451
        LinkedList<int> list2 = new LinkedList<int>();
2452
        list2.Add(0); list2.Add(2); list2.Add(2); list2.Add(2); list2.Add(5); list2.Add(2); list2.Add(1);
2453
        for (int i = 0; i < 7; i++)
2454
        {
2455
          for (int j = 0; j < 7 - i; j++)
2456
          {
2457
            list = new LinkedList<int>();
2458
            list.AddAll(list2);
2459
            LinkedList<int> v = (LinkedList<int>)list.View(i, j);
2460
            list.RemoveAllCopies(2);
2461
            Assert.AreEqual(i == 0 ? 0 : i <= 4 ? 1 : i <= 6 ? 2 : 3, v.Offset, "v.Offset, i=" + i + ", j=" + j);
2462
            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);
2463
            Assert.IsTrue(list.Check(), "list check after RemoveAllCopies, i=" + i + ", j=" + j);
2464
          }
2465
        }
2466
      }
2467

    
2468
      private void checkDisposed(bool reverse, int start, int count)
2469
      {
2470
        int k = 0;
2471
        for (int i = 0; i < 7; i++)
2472
          for (int j = 0; j < 7 - i; j++)
2473
          {
2474
            if (i + j <= start || i >= start + count || (i <= start && i + j >= start + count) || (reverse && start <= i && start + count >= i + j))
2475
            {
2476
              try
2477
              {
2478
                k = views[i][j].Count;
2479
              }
2480
              catch (ViewDisposedException)
2481
              {
2482
                Assert.Fail("view[" + i + "][" + j + "] threw");
2483
              }
2484
              Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] size");
2485
              if (reverse && ((j > 0 && start <= i && start + count >= i + j) || (j == 0 && start < i && start + count > i)))
2486
                Assert.AreEqual(start + (start + count - i - j), views[i][j].Offset, "view[" + i + "][" + j + "] offset (mirrored)");
2487
              else
2488
                Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
2489
            }
2490
            else
2491
            {
2492
              try
2493
              {
2494
                k = views[i][j].Count;
2495
                Assert.Fail("view[" + i + "][" + j + "] no throw");
2496
              }
2497
              catch (ViewDisposedException) { }
2498
            }
2499
          }
2500
      }
2501

    
2502
      [Test]
2503
      public void Reverse()
2504
      {
2505
        int start = 2, count = 3;
2506
        IList<int> list2 = list.View(start, count);
2507
        Assert.IsTrue(list.Check(), "list check before Reverse");
2508
        list2.Reverse();
2509
        Assert.IsTrue(list.Check(), "list check after Reverse");
2510
        checkDisposed(true, start, count);
2511
      }
2512
      [Test]
2513
      public void Sort()
2514
      {
2515
        int start = 2, count = 3;
2516
        IList<int> list2 = list.View(start, count);
2517
        Assert.IsTrue(list.Check(), "list check before Sort");
2518
        list2.Sort();
2519
        Assert.IsTrue(list.Check(), "list check after Sort");
2520
        checkDisposed(false, start, count);
2521
      }
2522
      [Test]
2523
      public void Shuffle()
2524
      {
2525
        int start = 2, count = 3;
2526
        IList<int> list2 = list.View(start, count);
2527
        Assert.IsTrue(list.Check(), "list check before Shuffle");
2528
        list2.Shuffle();
2529
        Assert.IsTrue(list.Check(), "list check after Shuffle");
2530
        checkDisposed(false, start, count);
2531
      }
2532

    
2533

    
2534
    }
2535

    
2536

    
2537
    [TestFixture]
2538
    public class Validity
2539
    {
2540
      IList<int> list;
2541
      IList<int> view;
2542
      [SetUp]
2543
      public void Init()
2544
      {
2545
        list = new LinkedList<int>();
2546
        for (int i = 0; i < 6; i++)
2547
          list.Add(i);
2548
        view = list.View(2, 3);
2549
        view.Dispose();
2550
      }
2551
      [TearDown]
2552
      public void Dispose()
2553
      {
2554
        list = null;
2555
        view = null;
2556
      }
2557

    
2558
      //Properties
2559

    
2560
      //
2561
      /*ActiveEvents,
2562
AllowsDuplicates,
2563
ContainsSpeed,
2564
Count,
2565
CountSpeed,
2566
Direction,
2567
DuplicatesByCounting,
2568
FIFO,
2569
First,
2570
EqualityComparer,
2571
IsEmpty,
2572
IsReadOnly,
2573
this[int index],
2574
this[int start, int count],
2575
Last,
2576
Offset,
2577
SyncRoot,
2578
Underlying
2579
*/
2580
      [Test]
2581
      [ExpectedException(typeof(ViewDisposedException))]
2582
      public void Add()
2583
      {
2584
        view.Add(5);
2585
      }
2586
      [Test]
2587
      [ExpectedException(typeof(ViewDisposedException))]
2588
      public void AddAll_int_()
2589
      {
2590
        view.AddAll<int>(new int[] { });
2591
      }
2592
      [Test]
2593
      [ExpectedException(typeof(ViewDisposedException))]
2594
      public void AddAll()
2595
      {
2596
        view.AddAll<int>(new int[] { });
2597
      }
2598
      [Test]
2599
      [ExpectedException(typeof(ViewDisposedException))]
2600
      public void All()
2601
      {
2602
        view.All(delegate(int i) { return false; });
2603
      }
2604
      [Test]
2605
      [ExpectedException(typeof(ViewDisposedException))]
2606
      public void Apply()
2607
      {
2608
        view.Apply(delegate(int i) { });
2609
      }
2610
      [Test]
2611
      [ExpectedException(typeof(ViewDisposedException))]
2612
      public void Backwards()
2613
      {
2614
        view.Backwards();
2615
      }
2616
      [Test]
2617
      [ExpectedException(typeof(ViewDisposedException))]
2618
      public void Choose()
2619
      {
2620
        view.Choose();
2621
      }
2622
      [Test]
2623
      [ExpectedException(typeof(ViewDisposedException))]
2624
      public void Contains()
2625
      {
2626
        view.Contains(0);
2627
      }
2628
      [Test]
2629
      [ExpectedException(typeof(ViewDisposedException))]
2630
      public void Clear()
2631
      {
2632
        view.Clear();
2633
      }
2634
      [Test]
2635
      [ExpectedException(typeof(ViewDisposedException))]
2636
      public void ContainsAll()
2637
      {
2638
        view.ContainsAll<int>(new int[] { });
2639
      }
2640
      [Test]
2641
      [ExpectedException(typeof(ViewDisposedException))]
2642
      public void ContainsCount()
2643
      {
2644
        view.ContainsCount(0);
2645
      }
2646
      [Test]
2647
      [ExpectedException(typeof(ViewDisposedException))]
2648
      public void CopyTo()
2649
      {
2650
        view.CopyTo(new int[1], 0);
2651
      }
2652
      [Test]
2653
      [ExpectedException(typeof(ViewDisposedException))]
2654
      public void Dequeue()
2655
      {
2656
        ((LinkedList<int>)view).Dequeue();
2657
      }
2658
      [Test]
2659
      [ExpectedException(typeof(ViewDisposedException))]
2660
      public void Enqueue()
2661
      {
2662
        ((LinkedList<int>)view).Enqueue(0);
2663
      }
2664
      [Test]
2665
      [ExpectedException(typeof(ViewDisposedException))]
2666
      public void Exists()
2667
      {
2668
        view.Exists(delegate(int i) { return false; });
2669
      }
2670
      [Test]
2671
      [ExpectedException(typeof(ViewDisposedException))]
2672
      public void Filter()
2673
      {
2674
        view.Filter(delegate(int i) { return true; });
2675
      }
2676
      [Test]
2677
      [ExpectedException(typeof(ViewDisposedException))]
2678
      public void Find()
2679
      {
2680
        int i = 0;
2681
        view.Find(ref i);
2682
      }
2683
      [Test]
2684
      [ExpectedException(typeof(ViewDisposedException))]
2685
      public void FindAll()
2686
      {
2687
        view.FindAll(delegate(int i) { return false; });
2688
      }
2689
      [Test]
2690
      [ExpectedException(typeof(ViewDisposedException))]
2691
      public void FindOrAdd()
2692
      {
2693
        int i = 0;
2694
        view.FindOrAdd(ref i);
2695
      }
2696

    
2697
      //TODO: wonder if it is allright to wait with the exception till the enumerator is actually used?
2698
      /*    [Test]
2699
      [ExpectedException(typeof(ListDisposedException))]
2700
      public void GetEnumerator()
2701
      {
2702
        view.GetEnumerator();
2703
      }
2704
    */
2705
      /*Method overview
2706
      Check(),
2707
      checkRange(int start, int count),
2708
      Dispose(),
2709
      Equals(object obj),
2710
      Finalize(),
2711
      fireBagItemsAdded(T item, int count),
2712
      fireBagItemsRemoved(T item, int count),
2713
      fireCollectionChanged(),
2714
      fireCollectionCleared(int start, int count),
2715
      fireItemAdded(T item),
2716
      fireItemInserted(T item, int index),
2717
      fireItemRemoved(T item),
2718
      fireItemRemovedAt(T item, int index),
2719
      GetEnumerator(),
2720
      GetHashCode(),
2721
      GetSequencedHashCode(),
2722
      GetType(),
2723
      GetUnsequencedHashCode(),
2724
      IndexOf(T item),
2725
      Insert(int i, T item),
2726
      ViewOf().InsertLast(T item, T target),
2727
      InsertAll(int i, IEnumerable<T> items),
2728
      ViewOf().InsertFirst(T item, T target),
2729
      InsertFirst(T item),
2730
      InsertLast(T item),
2731
      IsSorted(SCG.IComparer<T> c),
2732
      LastIndexOf(T item),
2733
      LastViewOf(T item),
2734
      Map<V>(Fun<T,V> mapper),
2735
      Map<V>(Fun<T,V> mapper, SCG.IEqualityComparer<V> equalityComparer),
2736
      MemberwiseClone(),
2737
      modifycheck(int stamp),
2738
      Pop(),
2739
      Push(T item),
2740
      Remove(),
2741
      Remove(T item),
2742
      Remove(T item, out T removeditem),
2743
      RemoveAll(IEnumerable<T> items),
2744
      RemoveAllCopies(T item),
2745
      RemoveAt(int i),
2746
      RemoveFirst(),
2747
      RemoveInterval(int start, int count),
2748
      RemoveLast(),
2749
      RetainAll(IEnumerable<T> items),
2750
      Reverse(),
2751
      Reverse(int start, int count),
2752
      SequencedEquals(ISequenced<T> that),
2753
      Shuffle(),
2754
      Shuffle(System.Random rnd),
2755
      Slide(int offset),
2756
      Slide(int offset, int size),
2757
      Sort(),
2758
      Sort(SCG.IComparer<T> c),
2759
      ToArray(),
2760
      ToString(),
2761
      UnsequencedEquals(ICollection<T> that),
2762
      Update(T item),
2763
      Update(T item, out T olditem),
2764
      updatecheck(),
2765
      UpdateOrAdd(T item),
2766
      UpdateOrAdd(T item, out T olditem),
2767
      View(int start, int count),
2768
      ViewOf(T item)
2769
            */
2770
    }
2771
  }
2772

    
2773

    
2774

    
2775

    
2776
  namespace LinkedListOfTreesORLists
2777
  {
2778
    [TestFixture]
2779
    public class MultiLevelUnorderedOfUnOrdered
2780
    {
2781
      private ICollection<int> dit, dat, dut;
2782

    
2783
      private ICollection<ICollection<int>> Dit, Dat, Dut;
2784

    
2785

    
2786
      [SetUp]
2787
      public void Init()
2788
      {
2789
        dit = new LinkedList<int>();
2790
        dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
2791
        dut = new LinkedList<int>();
2792
        dit.Add(2); dit.Add(1);
2793
        dat.Add(1); dat.Add(2);
2794
        dut.Add(3);
2795
        Dit = new LinkedList<ICollection<int>>();
2796
        Dat = new LinkedList<ICollection<int>>();
2797
        Dut = new LinkedList<ICollection<int>>();
2798
      }
2799

    
2800

    
2801
      [Test]
2802
      public void Check()
2803
      {
2804
        Assert.IsTrue(dit.UnsequencedEquals(dat));
2805
        Assert.IsFalse(dit.UnsequencedEquals(dut));
2806
      }
2807

    
2808

    
2809
      [Test]
2810
      public void Multi()
2811
      {
2812
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
2813
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
2814
        Assert.IsTrue(Dit.UnsequencedEquals(Dat));
2815
        Assert.IsFalse(Dit.UnsequencedEquals(Dut));
2816
      }
2817

    
2818

    
2819
      [TearDown]
2820
      public void Dispose()
2821
      {
2822
        dit = dat = dut = null;
2823
        Dit = Dat = Dut = null;
2824
      }
2825
    }
2826

    
2827

    
2828

    
2829
    [TestFixture]
2830
    public class MultiLevelOrderedOfUnOrdered
2831
    {
2832
      private ICollection<int> dit, dat, dut;
2833

    
2834
      private ISequenced<ICollection<int>> Dit, Dat, Dut;
2835

    
2836

    
2837
      [SetUp]
2838
      public void Init()
2839
      {
2840
        dit = new LinkedList<int>();
2841
        dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
2842
        dut = new LinkedList<int>();
2843
        dit.Add(2); dit.Add(1);
2844
        dat.Add(1); dat.Add(2);
2845
        dut.Add(3);
2846
        Dit = new LinkedList<ICollection<int>>();
2847
        Dat = new LinkedList<ICollection<int>>();
2848
        Dut = new LinkedList<ICollection<int>>();
2849
      }
2850

    
2851

    
2852
      [Test]
2853
      public void Check()
2854
      {
2855
        Assert.IsTrue(dit.UnsequencedEquals(dat));
2856
        Assert.IsFalse(dit.UnsequencedEquals(dut));
2857
      }
2858

    
2859

    
2860
      [Test]
2861
      public void Multi()
2862
      {
2863
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
2864
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
2865
        Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
2866
        Assert.IsFalse(Dit.SequencedEquals(Dat));
2867
        Assert.IsTrue(Dit.SequencedEquals(Dut));
2868
      }
2869

    
2870

    
2871
      [TearDown]
2872
      public void Dispose()
2873
      {
2874
        dit = dat = dut = null;
2875
        Dit = Dat = Dut = null;
2876
      }
2877
    }
2878

    
2879

    
2880

    
2881
    [TestFixture]
2882
    public class MultiLevelUnOrderedOfOrdered
2883
    {
2884
      private ISequenced<int> dit, dat, dut, dot;
2885

    
2886
      private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
2887

    
2888

    
2889
      [SetUp]
2890
      public void Init()
2891
      {
2892
        dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
2893
        dat = new LinkedList<int>();
2894
        dut = new LinkedList<int>();
2895
        dot = new LinkedList<int>();
2896
        dit.Add(2); dit.Add(1);
2897
        dat.Add(2); dat.Add(1);
2898
        dut.Add(3);
2899
        dot.Add(1); dot.Add(2);
2900
        Dit = new LinkedList<ISequenced<int>>();
2901
        Dat = new LinkedList<ISequenced<int>>();
2902
        Dut = new LinkedList<ISequenced<int>>();
2903
        Dot = new LinkedList<ISequenced<int>>();
2904
      }
2905

    
2906

    
2907
      [Test]
2908
      public void Check()
2909
      {
2910
        Assert.IsFalse(dit.SequencedEquals(dat));
2911
        Assert.IsTrue(dit.SequencedEquals(dot));
2912
        Assert.IsFalse(dit.SequencedEquals(dut));
2913
      }
2914

    
2915

    
2916
      [Test]
2917
      public void Multi()
2918
      {
2919
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
2920
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
2921
        Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
2922
        Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
2923
        Assert.IsTrue(Dit.UnsequencedEquals(Dut));
2924
        Assert.IsFalse(Dit.UnsequencedEquals(Dat));
2925
        Assert.IsTrue(Dit.UnsequencedEquals(Dot));
2926
      }
2927

    
2928

    
2929
      [TearDown]
2930
      public void Dispose()
2931
      {
2932
        dit = dat = dut = dot = null;
2933
        Dit = Dat = Dut = Dot = null;
2934
      }
2935
    }
2936

    
2937

    
2938

    
2939
    [TestFixture]
2940
    public class MultiLevelOrderedOfOrdered
2941
    {
2942
      private ISequenced<int> dit, dat, dut, dot;
2943

    
2944
      private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
2945

    
2946

    
2947
      [SetUp]
2948
      public void Init()
2949
      {
2950
        dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
2951
        dat = new LinkedList<int>();
2952
        dut = new LinkedList<int>();
2953
        dot = new LinkedList<int>();
2954
        dit.Add(2); dit.Add(1);
2955
        dat.Add(2); dat.Add(1);
2956
        dut.Add(3);
2957
        dot.Add(1); dot.Add(2);
2958
        Dit = new LinkedList<ISequenced<int>>();
2959
        Dat = new LinkedList<ISequenced<int>>();
2960
        Dut = new LinkedList<ISequenced<int>>();
2961
        Dot = new LinkedList<ISequenced<int>>();
2962
      }
2963

    
2964

    
2965
      [Test]
2966
      public void Check()
2967
      {
2968
        Assert.IsFalse(dit.SequencedEquals(dat));
2969
        Assert.IsTrue(dit.SequencedEquals(dot));
2970
        Assert.IsFalse(dit.SequencedEquals(dut));
2971
      }
2972

    
2973

    
2974
      [Test]
2975
      public void Multi()
2976
      {
2977
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
2978
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
2979
        Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
2980
        Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
2981
        Assert.IsTrue(Dit.SequencedEquals(Dut));
2982
        Assert.IsFalse(Dit.SequencedEquals(Dat));
2983
        Assert.IsFalse(Dit.SequencedEquals(Dot));
2984
      }
2985

    
2986

    
2987
      [TearDown]
2988
      public void Dispose()
2989
      {
2990
        dit = dat = dut = dot = null;
2991
        Dit = Dat = Dut = Dot = null;
2992
      }
2993
    }
2994
  }
2995

    
2996

    
2997

    
2998

    
2999
  namespace HashingAndEquals
3000
  {
3001
    [TestFixture]
3002
    public class ISequenced
3003
    {
3004
      private ISequenced<int> dit, dat, dut;
3005

    
3006

    
3007
      [SetUp]
3008
      public void Init()
3009
      {
3010
        dit = new LinkedList<int>();
3011
        dat = new LinkedList<int>();
3012
        dut = new LinkedList<int>();
3013
      }
3014

    
3015

    
3016
      [Test]
3017
      public void EmptyEmpty()
3018
      {
3019
        Assert.IsTrue(dit.SequencedEquals(dat));
3020
      }
3021

    
3022

    
3023
      [Test]
3024
      public void EmptyNonEmpty()
3025
      {
3026
        dit.Add(3);
3027
        Assert.IsFalse(dit.SequencedEquals(dat));
3028
        Assert.IsFalse(dat.SequencedEquals(dit));
3029
      }
3030

    
3031
      [Test]
3032
      public void HashVal()
3033
      {
3034
        Assert.AreEqual(CHC.sequencedhashcode(), dit.GetSequencedHashCode());
3035
        dit.Add(3);
3036
        Assert.AreEqual(CHC.sequencedhashcode(3), dit.GetSequencedHashCode());
3037
        dit.Add(7);
3038
        Assert.AreEqual(CHC.sequencedhashcode(3, 7), dit.GetSequencedHashCode());
3039
        Assert.AreEqual(CHC.sequencedhashcode(), dut.GetSequencedHashCode());
3040
        dut.Add(7);
3041
        Assert.AreEqual(CHC.sequencedhashcode(7), dut.GetSequencedHashCode());
3042
        dut.Add(3);
3043
        Assert.AreEqual(CHC.sequencedhashcode(7, 3), dut.GetSequencedHashCode());
3044
      }
3045

    
3046

    
3047
      [Test]
3048
      public void EqualHashButDifferent()
3049
      {
3050
        dit.Add(0); dit.Add(31);
3051
        dat.Add(1); dat.Add(0);
3052
        Assert.AreEqual(dit.GetSequencedHashCode(), dat.GetSequencedHashCode());
3053
        Assert.IsFalse(dit.SequencedEquals(dat));
3054
      }
3055

    
3056

    
3057
      [Test]
3058
      public void Normal()
3059
      {
3060
        dit.Add(3);
3061
        dit.Add(7);
3062
        dat.Add(3);
3063
        Assert.IsFalse(dit.SequencedEquals(dat));
3064
        Assert.IsFalse(dat.SequencedEquals(dit));
3065
        dat.Add(7);
3066
        Assert.IsTrue(dit.SequencedEquals(dat));
3067
        Assert.IsTrue(dat.SequencedEquals(dit));
3068
      }
3069

    
3070

    
3071
      [Test]
3072
      public void WrongOrder()
3073
      {
3074
        dit.Add(3);
3075
        dut.Add(3);
3076
        Assert.IsTrue(dit.SequencedEquals(dut));
3077
        Assert.IsTrue(dut.SequencedEquals(dit));
3078
        dit.Add(7);
3079
        ((LinkedList<int>)dut).InsertFirst(7);
3080
        Assert.IsFalse(dit.SequencedEquals(dut));
3081
        Assert.IsFalse(dut.SequencedEquals(dit));
3082
      }
3083

    
3084

    
3085
      [Test]
3086
      public void Reflexive()
3087
      {
3088
        Assert.IsTrue(dit.SequencedEquals(dit));
3089
        dit.Add(3);
3090
        Assert.IsTrue(dit.SequencedEquals(dit));
3091
        dit.Add(7);
3092
        Assert.IsTrue(dit.SequencedEquals(dit));
3093
      }
3094

    
3095

    
3096
      [TearDown]
3097
      public void Dispose()
3098
      {
3099
        dit = null;
3100
        dat = null;
3101
        dut = null;
3102
      }
3103
    }
3104

    
3105

    
3106

    
3107
    [TestFixture]
3108
    public class IEditableCollection
3109
    {
3110
      private ICollection<int> dit, dat, dut;
3111

    
3112

    
3113
      [SetUp]
3114
      public void Init()
3115
      {
3116
        dit = new LinkedList<int>();
3117
        dat = new LinkedList<int>();
3118
        dut = new LinkedList<int>();
3119
      }
3120

    
3121

    
3122
      [Test]
3123
      public void EmptyEmpty()
3124
      {
3125
        Assert.IsTrue(dit.UnsequencedEquals(dat));
3126
      }
3127

    
3128

    
3129
      [Test]
3130
      public void EmptyNonEmpty()
3131
      {
3132
        dit.Add(3);
3133
        Assert.IsFalse(dit.UnsequencedEquals(dat));
3134
        Assert.IsFalse(dat.UnsequencedEquals(dit));
3135
      }
3136

    
3137

    
3138
      [Test]
3139
      public void HashVal()
3140
      {
3141
        Assert.AreEqual(CHC.unsequencedhashcode(), dit.GetUnsequencedHashCode());
3142
        dit.Add(3);
3143
        Assert.AreEqual(CHC.unsequencedhashcode(3), dit.GetUnsequencedHashCode());
3144
        dit.Add(7);
3145
        Assert.AreEqual(CHC.unsequencedhashcode(3, 7), dit.GetUnsequencedHashCode());
3146
        Assert.AreEqual(CHC.unsequencedhashcode(), dut.GetUnsequencedHashCode());
3147
        dut.Add(3);
3148
        Assert.AreEqual(CHC.unsequencedhashcode(3), dut.GetUnsequencedHashCode());
3149
        dut.Add(7);
3150
        Assert.AreEqual(CHC.unsequencedhashcode(7, 3), dut.GetUnsequencedHashCode());
3151
      }
3152

    
3153

    
3154
      [Test]
3155
      public void EqualHashButDifferent()
3156
      {
3157
        dit.Add(-1657792980); dit.Add(-1570288808);
3158
        dat.Add(1862883298); dat.Add(-272461342);
3159
        Assert.AreEqual(dit.GetUnsequencedHashCode(), dat.GetUnsequencedHashCode());
3160
        Assert.IsFalse(dit.UnsequencedEquals(dat));
3161
      }
3162

    
3163

    
3164
      [Test]
3165
      public void Normal()
3166
      {
3167
        dit.Add(3);
3168
        dit.Add(7);
3169
        dat.Add(3);
3170
        Assert.IsFalse(dit.UnsequencedEquals(dat));
3171
        Assert.IsFalse(dat.UnsequencedEquals(dit));
3172
        dat.Add(7);
3173
        Assert.IsTrue(dit.UnsequencedEquals(dat));
3174
        Assert.IsTrue(dat.UnsequencedEquals(dit));
3175
      }
3176

    
3177

    
3178
      [Test]
3179
      public void WrongOrder()
3180
      {
3181
        dit.Add(3);
3182
        dut.Add(3);
3183
        Assert.IsTrue(dit.UnsequencedEquals(dut));
3184
        Assert.IsTrue(dut.UnsequencedEquals(dit));
3185
        dit.Add(7);
3186
        dut.Add(7);
3187
        Assert.IsTrue(dit.UnsequencedEquals(dut));
3188
        Assert.IsTrue(dut.UnsequencedEquals(dit));
3189
      }
3190

    
3191

    
3192
      [Test]
3193
      public void Reflexive()
3194
      {
3195
        Assert.IsTrue(dit.UnsequencedEquals(dit));
3196
        dit.Add(3);
3197
        Assert.IsTrue(dit.UnsequencedEquals(dit));
3198
        dit.Add(7);
3199
        Assert.IsTrue(dit.UnsequencedEquals(dit));
3200
      }
3201

    
3202

    
3203
      [TearDown]
3204
      public void Dispose()
3205
      {
3206
        dit = null;
3207
        dat = null;
3208
        dut = null;
3209
      }
3210
    }
3211

    
3212

    
3213

    
3214
    [TestFixture]
3215
    public class MultiLevelUnorderedOfUnOrdered
3216
    {
3217
      private ICollection<int> dit, dat, dut;
3218

    
3219
      private ICollection<ICollection<int>> Dit, Dat, Dut;
3220

    
3221

    
3222
      [SetUp]
3223
      public void Init()
3224
      {
3225
        dit = new LinkedList<int>();
3226
        dat = new LinkedList<int>();
3227
        dut = new LinkedList<int>();
3228
        dit.Add(2); dit.Add(1);
3229
        dat.Add(1); dat.Add(2);
3230
        dut.Add(3);
3231
        Dit = new LinkedList<ICollection<int>>();
3232
        Dat = new LinkedList<ICollection<int>>();
3233
        Dut = new LinkedList<ICollection<int>>();
3234
      }
3235

    
3236

    
3237
      [Test]
3238
      public void Check()
3239
      {
3240
        Assert.IsTrue(dit.UnsequencedEquals(dat));
3241
        Assert.IsFalse(dit.UnsequencedEquals(dut));
3242
      }
3243

    
3244

    
3245
      [Test]
3246
      public void Multi()
3247
      {
3248
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
3249
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
3250
        Assert.IsTrue(Dit.UnsequencedEquals(Dat));
3251
        Assert.IsFalse(Dit.UnsequencedEquals(Dut));
3252
      }
3253

    
3254

    
3255
      [TearDown]
3256
      public void Dispose()
3257
      {
3258
        dit = dat = dut = null;
3259
        Dit = Dat = Dut = null;
3260
      }
3261
    }
3262

    
3263

    
3264

    
3265
    [TestFixture]
3266
    public class MultiLevelOrderedOfUnOrdered
3267
    {
3268
      private ICollection<int> dit, dat, dut;
3269

    
3270
      private ISequenced<ICollection<int>> Dit, Dat, Dut;
3271

    
3272

    
3273
      [SetUp]
3274
      public void Init()
3275
      {
3276
        dit = new LinkedList<int>();
3277
        dat = new LinkedList<int>();
3278
        dut = new LinkedList<int>();
3279
        dit.Add(2); dit.Add(1);
3280
        dat.Add(1); dat.Add(2);
3281
        dut.Add(3);
3282
        Dit = new LinkedList<ICollection<int>>();
3283
        Dat = new LinkedList<ICollection<int>>();
3284
        Dut = new LinkedList<ICollection<int>>();
3285
      }
3286

    
3287

    
3288
      [Test]
3289
      public void Check()
3290
      {
3291
        Assert.IsTrue(dit.UnsequencedEquals(dat));
3292
        Assert.IsFalse(dit.UnsequencedEquals(dut));
3293
      }
3294

    
3295

    
3296
      [Test]
3297
      public void Multi()
3298
      {
3299
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
3300
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
3301
        Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
3302
        Assert.IsFalse(Dit.SequencedEquals(Dat));
3303
        Assert.IsTrue(Dit.SequencedEquals(Dut));
3304
      }
3305

    
3306

    
3307
      [TearDown]
3308
      public void Dispose()
3309
      {
3310
        dit = dat = dut = null;
3311
        Dit = Dat = Dut = null;
3312
      }
3313
    }
3314

    
3315

    
3316

    
3317
    [TestFixture]
3318
    public class MultiLevelUnOrderedOfOrdered
3319
    {
3320
      private ISequenced<int> dit, dat, dut, dot;
3321

    
3322
      private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
3323

    
3324

    
3325
      [SetUp]
3326
      public void Init()
3327
      {
3328
        dit = new LinkedList<int>();
3329
        dat = new LinkedList<int>();
3330
        dut = new LinkedList<int>();
3331
        dot = new LinkedList<int>();
3332
        dit.Add(2); dit.Add(1);
3333
        dat.Add(1); dat.Add(2);
3334
        dut.Add(3);
3335
        dot.Add(2); dot.Add(1);
3336
        Dit = new LinkedList<ISequenced<int>>();
3337
        Dat = new LinkedList<ISequenced<int>>();
3338
        Dut = new LinkedList<ISequenced<int>>();
3339
        Dot = new LinkedList<ISequenced<int>>();
3340
      }
3341

    
3342

    
3343
      [Test]
3344
      public void Check()
3345
      {
3346
        Assert.IsFalse(dit.SequencedEquals(dat));
3347
        Assert.IsTrue(dit.SequencedEquals(dot));
3348
        Assert.IsFalse(dit.SequencedEquals(dut));
3349
      }
3350

    
3351

    
3352
      [Test]
3353
      public void Multi()
3354
      {
3355
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
3356
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
3357
        Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
3358
        Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
3359
        Assert.IsTrue(Dit.UnsequencedEquals(Dut));
3360
        Assert.IsFalse(Dit.UnsequencedEquals(Dat));
3361
        Assert.IsTrue(Dit.UnsequencedEquals(Dot));
3362
      }
3363

    
3364

    
3365
      [TearDown]
3366
      public void Dispose()
3367
      {
3368
        dit = dat = dut = dot = null;
3369
        Dit = Dat = Dut = Dot = null;
3370
      }
3371
    }
3372

    
3373

    
3374

    
3375
    [TestFixture]
3376
    public class MultiLevelOrderedOfOrdered
3377
    {
3378
      private ISequenced<int> dit, dat, dut, dot;
3379

    
3380
      private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
3381

    
3382

    
3383
      [SetUp]
3384
      public void Init()
3385
      {
3386
        dit = new LinkedList<int>();
3387
        dat = new LinkedList<int>();
3388
        dut = new LinkedList<int>();
3389
        dot = new LinkedList<int>();
3390
        dit.Add(2); dit.Add(1);
3391
        dat.Add(1); dat.Add(2);
3392
        dut.Add(3);
3393
        dot.Add(2); dot.Add(1);
3394
        Dit = new LinkedList<ISequenced<int>>();
3395
        Dat = new LinkedList<ISequenced<int>>();
3396
        Dut = new LinkedList<ISequenced<int>>();
3397
        Dot = new LinkedList<ISequenced<int>>();
3398
      }
3399

    
3400

    
3401
      [Test]
3402
      public void Check()
3403
      {
3404
        Assert.IsFalse(dit.SequencedEquals(dat));
3405
        Assert.IsTrue(dit.SequencedEquals(dot));
3406
        Assert.IsFalse(dit.SequencedEquals(dut));
3407
      }
3408

    
3409

    
3410
      [Test]
3411
      public void Multi()
3412
      {
3413
        Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
3414
        Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
3415
        Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
3416
        Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
3417
        Assert.IsTrue(Dit.SequencedEquals(Dut));
3418
        Assert.IsFalse(Dit.SequencedEquals(Dat));
3419
        Assert.IsFalse(Dit.SequencedEquals(Dot));
3420
      }
3421

    
3422

    
3423
      [TearDown]
3424
      public void Dispose()
3425
      {
3426
        dit = dat = dut = dot = null;
3427
        Dit = Dat = Dut = Dot = null;
3428
      }
3429
    }
3430
  }
3431
}