diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index 510efdad..fbe3e19c 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -13,10 +13,10 @@ public class GenericTesters [Test] public void TestEvents() { - ArrayList factory() { return new ArrayList(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.ListTester>().Test(factory); - new C5.Tests.Templates.Events.QueueTester>().Test(factory); - new C5.Tests.Templates.Events.StackTester>().Test(factory); + ArrayList factory() { return new ArrayList(TenEqualityComparer.Instance); } + new Templates.Events.ListTester>().Test(factory); + new Templates.Events.QueueTester>().Test(factory); + new Templates.Events.StackTester>().Test(factory); } [Test] @@ -43,7 +43,7 @@ public class IList_ [SetUp] public void Init() { - list = new ArrayList(TenEqualityComparer.Default); + list = new ArrayList(TenEqualityComparer.Instance); seen = new CollectionEventList(SCG.EqualityComparer.Default); } @@ -514,7 +514,7 @@ public class StackQueue [SetUp] public void Init() { - list = new ArrayList(TenEqualityComparer.Default); + list = new ArrayList(TenEqualityComparer.Instance); seen = new CollectionEventList(SCG.EqualityComparer.Default); } @@ -591,7 +591,7 @@ public class BadEnumerable [SetUp] public void Init() { - list = new ArrayList(); + list = []; } [Test] @@ -608,7 +608,7 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 9, 8, 7, 56, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 9, 8, 7, 56, 8 })); }); } @@ -627,7 +627,7 @@ public void AddAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 9, 8, 7, 56, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 9, 8, 7, 56, 8 })); }); } @@ -645,7 +645,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 8 })); }); } @@ -663,7 +663,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 8 })); }); } @@ -682,7 +682,7 @@ public void ContainsAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 8 })); }); } @@ -724,7 +724,7 @@ public class Multiops [SetUp] public void Init() { - list = new ArrayList(); + list = []; always = delegate { return true; }; never = delegate { return false; }; even = delegate (int i) { return i % 2 == 0; }; @@ -811,7 +811,7 @@ public class GetEnumerator [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] @@ -921,7 +921,7 @@ public class CollectionOrSink [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] public void Choose() @@ -960,15 +960,15 @@ public void AddAll() { list.Add(3); list.Add(4); list.Add(5); - ArrayList list2 = new(); + ArrayList list2 = []; list2.AddAll(list); - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); list.AddAll(list2); Assert.Multiple(() => { - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); - Assert.That(IC.Eq(list, 3, 4, 5, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(list, Is.EqualTo(new[] { 3, 4, 5, 3, 4, 5 })); }); } @@ -985,7 +985,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new ArrayList(TenEqualityComparer.Default); + list = new ArrayList(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -1047,7 +1047,7 @@ public class UniqueItems private ArrayList list; [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -1057,14 +1057,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 2, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 2), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -1079,7 +1079,7 @@ public class ArrayTest [SetUp] public void Init() { - list = new ArrayList(); + list = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -1091,55 +1091,34 @@ public void Init() [TearDown] public void Dispose() { list.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - [Test] public void ToArray() { - Assert.That(aeq(list.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.Empty); list.Add(7); list.Add(7); - Assert.That(aeq(list.ToArray(), 7, 7), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.EqualTo(new[] { 7, 7 })); } - [Test] public void CopyTo() { list.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(6); list.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(4); list.Add(4); list.Add(9); list.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009 })); list.Clear(); list.Add(7); list.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7 })); } - [Test] public void CopyToBad() { @@ -1185,7 +1164,7 @@ public class Searching [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] public void NullEqualityComparerinConstructor1() @@ -1267,7 +1246,7 @@ public void RemoveAllCopies() Assert.That(list.ContainsCount(7), Is.EqualTo(1)); list.Add(5); list.Add(8); list.Add(5); list.RemoveAllCopies(8); - Assert.That(IC.Eq(list, 7, 5, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7, 5, 5 })); } @@ -1281,7 +1260,7 @@ public void FindAll() Assert.Multiple(() => { Assert.That(((ArrayList)list.FindAll(f)).Check(), Is.True); - Assert.That(IC.Eq(list.FindAll(f), 8, 10, 8), Is.True); + Assert.That(list.FindAll(f), Is.EqualTo(new[] { 8, 10, 8 })); }); } @@ -1289,7 +1268,7 @@ public void FindAll() [Test] public void ContainsAll() { - ArrayList list2 = new(); + ArrayList list2 = []; Assert.That(list.ContainsAll(list2), Is.True); list2.Add(4); @@ -1308,7 +1287,7 @@ public void ContainsAll() [Test] public void RetainAll() { - ArrayList list2 = new(); + ArrayList list2 = []; list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4); @@ -1316,7 +1295,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -1325,20 +1304,20 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 5, 6 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RetainAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list), Is.True); + Assert.That(list, Is.Empty); } [Test] public void RemoveAll() { - ArrayList list2 = new(); + ArrayList list2 = []; list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4); @@ -1346,7 +1325,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 6 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -1355,13 +1334,13 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RemoveAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4 })); } @@ -1377,16 +1356,16 @@ public void Remove() Assert.That(list.Remove(4), Is.True); }); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(4)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 7 })); }); list.FIFO = true; @@ -1396,16 +1375,16 @@ public void Remove() Assert.That(list.Check(), Is.True); Assert.That(list.Remove(4), Is.True); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 4, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 4, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 4 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(4)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 4, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 4, 7 })); }); } @@ -1438,7 +1417,7 @@ public class Searching [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; } @@ -1480,7 +1459,7 @@ public class Removing [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; } @@ -1491,15 +1470,15 @@ public void RemoveAt() Assert.Multiple(() => { Assert.That(dit.RemoveAt(1), Is.EqualTo(7)); - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 5, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 5, 9, 1, 2 })); Assert.That(dit.RemoveAt(0), Is.EqualTo(5)); }); - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1, 2 })); Assert.That(dit.RemoveAt(2), Is.EqualTo(2)); - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1 })); } @@ -1532,39 +1511,39 @@ public void RemoveInterval() dit.RemoveInterval(3, 0); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 40, 50, 60 })); }); dit.RemoveInterval(3, 1); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 50, 60 })); }); dit.RemoveInterval(1, 3); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 60 })); }); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.Empty); }); dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40, 50, 60 })); }); dit.RemoveInterval(2, 2); Assert.Multiple(() => { - Assert.That(((ArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40 })); }); } @@ -1638,7 +1617,7 @@ public void This() Assert.That(lst.First, Is.EqualTo(56)); lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7); lst[0] = 45; lst[2] = 78; lst[4] = 101; - Assert.That(IC.Eq(lst, 45, 7, 78, 7, 101), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 45, 7, 78, 7, 101 })); } @@ -1721,37 +1700,37 @@ public class Inserting public void Insert() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 4); - Assert.That(IC.Eq(lst, 7, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5 })); lst.Insert(3, 2); - Assert.That(IC.Eq(lst, 7, 4, 5, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5, 2 })); } [Test] public void InsertDuplicate() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 5); - Assert.That(IC.Eq(lst, 7, 5, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 5 })); } [Test] public void InsertAllDuplicate1() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); lst.InsertAll(1, [1, 2, 3, 4]); Assert.Multiple(() => { - Assert.That(IC.Eq(lst, 7, 1, 2, 3, 4, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 1, 2, 3, 4, 3 })); Assert.That(lst.Check(), Is.True); }); } @@ -1760,14 +1739,14 @@ public void InsertAllDuplicate1() public void InsertAllDuplicate2() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); lst.InsertAll(1, [5, 6, 5, 8]); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 5, 6, 5, 8, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 6, 5, 8, 3 })); }); } @@ -1822,7 +1801,7 @@ public void InsertFirstLast() lst.InsertLast(25); lst.InsertFirst(34); lst.InsertLast(55); - Assert.That(IC.Eq(lst, 34, 24, 14, 4, 5, 15, 25, 55), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 34, 24, 14, 4, 5, 15, 25, 55 })); } @@ -1837,19 +1816,19 @@ public void InsertFirst() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 3, 2, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 3, 2, 5 })); }); lst.ViewOf(3).InsertFirst(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 2, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 2, 5 })); }); lst.ViewOf(5).InsertFirst(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 2, 9, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 2, 9, 5 })); }); } @@ -1865,19 +1844,19 @@ public void InsertAfter() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 3, 2, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 3, 2, 7, 5 })); }); lst.LastViewOf(1).InsertLast(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 3, 2, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 3, 2, 7, 5 })); }); lst.LastViewOf(5).InsertLast(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 3, 2, 7, 5, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 3, 2, 7, 5, 9 })); }); } @@ -1895,19 +1874,19 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4 })); }); lst.InsertAll(7, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4, 7, 8, 9 })); }); lst.InsertAll(5, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9 })); }); } @@ -2032,31 +2011,31 @@ public void Reverse() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(0, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 0).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); lst.View(5, 1).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); } @@ -2096,14 +2075,14 @@ public void Init() [Test] public void Find() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { Assert.That(lst.Find(ref p), Is.True); Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Find(ref p), Is.False); } @@ -2111,7 +2090,7 @@ public void Find() [Test] public void FindOrAdd() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -2119,7 +2098,7 @@ public void FindOrAdd() Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 79); + p = new SCG.KeyValuePair(13, 79); Assert.Multiple(() => { Assert.That(lst.FindOrAdd(ref p), Is.False); @@ -2132,7 +2111,7 @@ public void FindOrAdd() [Test] public void Update() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -2140,7 +2119,7 @@ public void Update() Assert.That(lst[3].Key, Is.EqualTo(3)); Assert.That(lst[3].Value, Is.EqualTo(78)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Update(p), Is.False); } @@ -2148,7 +2127,7 @@ public void Update() [Test] public void UpdateOrAdd1() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -2156,7 +2135,7 @@ public void UpdateOrAdd1() Assert.That(lst[3].Key, Is.EqualTo(3)); Assert.That(lst[3].Value, Is.EqualTo(78)); }); - p = new System.Collections.Generic.KeyValuePair(13, 79); + p = new SCG.KeyValuePair(13, 79); Assert.Multiple(() => { Assert.That(lst.UpdateOrAdd(p), Is.False); @@ -2184,7 +2163,7 @@ public void UpdateOrAdd2() [Test] public void RemoveWithReturn() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -2194,7 +2173,7 @@ public void RemoveWithReturn() Assert.That(lst[3].Key, Is.EqualTo(4)); Assert.That(lst[3].Value, Is.EqualTo(34)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Remove(p, out _), Is.False); } } @@ -2218,13 +2197,13 @@ public class SortingTests public void Sort() { lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3); - Assert.That(lst.IsSorted(new IC()), Is.False); - lst.Sort(new IC()); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.False); + lst.Sort(new IntegerComparer()); Assert.Multiple(() => { Assert.That(lst.IsSorted(), Is.True); - Assert.That(lst.IsSorted(new IC()), Is.True); - Assert.That(IC.Eq(lst, 3, 5, 5, 6, 7), Is.True); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -2232,21 +2211,21 @@ public void Sort() [Test] public void Stability() { - IList> lst2 = new ArrayList>(); - SCG.IComparer> c = new KeyValuePairComparer(new IC()); + IList> lst2 = new ArrayList>(); + SCG.IComparer> c = new KeyValuePairComparer(new IntegerComparer()); - lst2.Add(new System.Collections.Generic.KeyValuePair(5, "a")); - lst2.Add(new System.Collections.Generic.KeyValuePair(5, "b")); - lst2.Add(new System.Collections.Generic.KeyValuePair(6, "c")); - lst2.Add(new System.Collections.Generic.KeyValuePair(4, "d")); - lst2.Add(new System.Collections.Generic.KeyValuePair(3, "e")); - lst2.Add(new System.Collections.Generic.KeyValuePair(4, "f")); - lst2.Add(new System.Collections.Generic.KeyValuePair(5, "handle")); + lst2.Add(new SCG.KeyValuePair(5, "a")); + lst2.Add(new SCG.KeyValuePair(5, "b")); + lst2.Add(new SCG.KeyValuePair(6, "c")); + lst2.Add(new SCG.KeyValuePair(4, "d")); + lst2.Add(new SCG.KeyValuePair(3, "e")); + lst2.Add(new SCG.KeyValuePair(4, "f")); + lst2.Add(new SCG.KeyValuePair(5, "handle")); Assert.That(lst2.IsSorted(c), Is.False); lst2.Sort(c); Assert.That(lst2.IsSorted(c), Is.True); - System.Collections.Generic.KeyValuePair p = lst2.RemoveFirst(); + SCG.KeyValuePair p = lst2.RemoveFirst(); Assert.Multiple(() => { @@ -2296,35 +2275,23 @@ public void Stability() [TestFixture] public class ShuffleTests { - private IList lst; - - - [SetUp] - public void Init() { lst = new ArrayList(); } - - - [TearDown] - public void Dispose() { lst.Dispose(); } - - [Test] public void Shuffle() { - lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3); + ArrayList lst = [5, 6, 5, 7, 3]; + for (int i = 0; i < 100; i++) { lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); - Assert.That(IC.Eq(lst2, 3, 5, 5, 6, 7), Is.True, "Contents " + i); + Sorting.IntroSort(lst2); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 5, 6, 7 }), "Contents " + i); } } } - } - namespace IStackQueue { [TestFixture] @@ -2334,7 +2301,7 @@ public class Stack [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] @@ -2375,7 +2342,7 @@ public class Queue private ArrayList list; [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] public void Normal() @@ -2428,7 +2395,6 @@ public class Range [Test] public void GetRange() { - //Assert.IsTrue(IC.eq(lst[0, 0))); for (int i = 0; i < 10; i++) { lst.Add(i); @@ -2436,9 +2402,9 @@ public void GetRange() Assert.Multiple(() => { - Assert.That(IC.Eq(lst[0, 3], 0, 1, 2), Is.True); - Assert.That(IC.Eq(lst[3, 4], 3, 4, 5, 6), Is.True); - Assert.That(IC.Eq(lst[6, 4], 6, 7, 8, 9), Is.True); + Assert.That(lst[0, 3], Is.EqualTo(new[] { 0, 1, 2 })); + Assert.That(lst[3, 4], Is.EqualTo(new[] { 3, 4, 5, 6 })); + Assert.That(lst[6, 4], Is.EqualTo(new[] { 6, 7, 8, 9 })); }); } @@ -2462,10 +2428,10 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[0, 4].Backwards(), 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[3, 4].Backwards(), 6, 5, 4, 3), Is.True); - Assert.That(IC.Eq(lst[6, 4].Backwards(), 9, 8, 7, 6), Is.True); + Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); + Assert.That(lst[0, 4].Backwards(), Is.EqualTo(new[] { 3, 2, 1, 0 })); + Assert.That(lst[3, 4].Backwards(), Is.EqualTo(new[] { 6, 5, 4, 3 })); + Assert.That(lst[6, 4].Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6 })); }); } @@ -2523,7 +2489,7 @@ public class Simple [SetUp] public void Init() { - list = new ArrayList { 0, 1, 2, 3 }; + list = [0, 1, 2, 3]; view = (ArrayList)list.View(1, 2); } @@ -2562,8 +2528,8 @@ public void InsertPointer() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8), Is.True); - Assert.That(IC.Eq(view, 11, 1, 9, 7, 2, 10), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 11, 1, 9, 7, 2, 10, 3, 8 })); + Assert.That(view, Is.EqualTo(new[] { 11, 1, 9, 7, 2, 10 })); }); } @@ -2624,21 +2590,21 @@ public void ViewOf() Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.ViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.LastViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(6)); }); } @@ -2646,10 +2612,10 @@ public void ViewOf() [Test] public void ArrayStuff() { - Assert.That(IC.Eq(view.ToArray(), 1, 2), Is.True); + Assert.That(view.ToArray(), Is.EqualTo(new[] { 1, 2 })); int[] extarray = new int[5]; view.CopyTo(extarray, 2); - Assert.That(IC.Eq(extarray, 0, 0, 1, 2, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 0, 1, 2, 0 })); } [Test] @@ -2672,15 +2638,15 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2 })); }); view.InsertFirst(10); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 10, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 10, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 10, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 10, 1, 2 })); }); view.Clear(); Assert.Multiple(() => @@ -2690,8 +2656,8 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); - Assert.That(IC.Eq(view), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.True); @@ -2699,46 +2665,46 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 3), Is.True); - Assert.That(IC.Eq(view, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8 })); }); view.Add(12); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12 })); }); view./*ViewOf(12)*/InsertLast(15); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12, 15 })); }); view.ViewOf(12).InsertFirst(18); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15 })); }); - ArrayList lst2 = new() { 90, 92 }; + ArrayList lst2 = [90, 92]; view.AddAll(lst2); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92 })); }); view.InsertLast(66); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92, 66), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 66, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92, 66 })); }); } @@ -2748,7 +2714,7 @@ public void Bxxx() { Assert.Multiple(() => { - Assert.That(IC.Eq(view.Backwards(), 2, 1), Is.True); + Assert.That(view.Backwards(), Is.EqualTo(new[] { 2, 1 })); Assert.That(view.Underlying, Is.SameAs(list)); Assert.That(list.Underlying, Is.Null); Assert.That(view.Direction, Is.EqualTo(Direction.Forwards)); @@ -2768,7 +2734,7 @@ public void Contains() Assert.That(view.Contains(0), Is.False); }); - ArrayList lst2 = new() { 2 }; + ArrayList lst2 = [2]; Assert.That(view.ContainsAll(lst2), Is.True); lst2.Add(3); @@ -2806,11 +2772,11 @@ public void FIFO() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 23, 24, 25 })); Assert.That(view.Remove(), Is.EqualTo(1)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24, 25 })); view.FIFO = false; Assert.Multiple(() => { @@ -2818,7 +2784,7 @@ public void FIFO() Assert.That(view.Remove(), Is.EqualTo(25)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24 })); } @@ -2842,7 +2808,7 @@ public void MapEtc() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 1, 1, 5, 9), Is.True); + Assert.That(list, Is.EqualTo(new[] { 1, 1, 5, 9 })); }); } @@ -2894,7 +2860,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 2, 36 })); }); IList list2 = new ArrayList(); @@ -2904,7 +2870,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 34, 35, 1, 2, 36, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 34, 35, 1, 2, 36, 2, 36 })); }); } @@ -2931,13 +2897,13 @@ public void RangeCheck2() public void Sort() { view.Add(45); view.Add(47); view.Add(46); view.Add(48); - Assert.That(view.IsSorted(new IC()), Is.False); - view.Sort(new IC()); + Assert.That(view.IsSorted(new IntegerComparer()), Is.False); + view.Sort(new IntegerComparer()); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 45, 46, 47, 48, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2, 45, 46, 47, 48), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 45, 46, 47, 48, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 45, 46, 47, 48 })); }); } @@ -2948,32 +2914,32 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5, 3, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 3, 3, 0 })); Assert.That(view.Remove(0), Is.True); }); check(); - Assert.That(IC.Eq(view, 1, 2, 5, 3, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 3, 3 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5), Is.True); - Assert.That(IC.Eq(list, 0, 1, 2, 5, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5 })); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 5, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 1, 2, 5, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 1, 5, 3, 1, 3, 0 })); view.FIFO = true; view.Clear(); view.Add(1); view.Add(2); @@ -2981,43 +2947,43 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(0), Is.True); }); check(); - Assert.That(IC.Eq(view, 2, 5, 3, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 3, 1, 3 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5, 1), Is.True); - Assert.That(IC.Eq(list, 0, 2, 5, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1 })); + Assert.That(list, Is.EqualTo(new[] { 0, 2, 5, 1, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 2, 5, 1, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1, 1, 5, 3, 1, 3, 0 })); view.FIFO = false; - ArrayList l2 = new() { 1, 2, 2, 3, 1 }; + ArrayList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); - Assert.That(IC.Eq(view, 5, 5, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 5, 5, 1, 3, 0 })); view.RetainAll(l2); check(); - Assert.That(IC.Eq(view, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 3 })); view.Add(2); view.Add(4); view.Add(5); Assert.Multiple(() => { @@ -3026,7 +2992,7 @@ public void Remove() Assert.That(view.RemoveAt(1), Is.EqualTo(2)); }); check(); - Assert.That(IC.Eq(view, 3, 4), Is.True); + Assert.That(view, Is.EqualTo(new[] { 3, 4 })); view.Add(8); Assert.Multiple(() => { @@ -3036,7 +3002,7 @@ public void Remove() view.Add(2); view.Add(5); view.Add(3); view.Add(1); view.RemoveInterval(1, 2); check(); - Assert.That(IC.Eq(view, 4, 3, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 4, 3, 1 })); } @@ -3051,12 +3017,12 @@ public void Reverse() view.View(3, 4).Reverse(); check(); - Assert.That(IC.Eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19), Is.True); + Assert.That(view, Is.EqualTo(new[] { 10, 11, 12, 16, 15, 14, 13, 17, 18, 19 })); view.Reverse(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10), Is.True); - Assert.That(IC.Eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 19, 18, 17, 13, 14, 15, 16, 12, 11, 10 })); + Assert.That(list, Is.EqualTo(new[] { 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3 })); }); } @@ -3066,24 +3032,24 @@ public void Slide() { view.Slide(1); check(); - Assert.That(IC.Eq(view, 2, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 3 })); view.Slide(-2); check(); - Assert.That(IC.Eq(view, 0, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1 })); view.Slide(0, 3); check(); - Assert.That(IC.Eq(view, 0, 1, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1, 2 })); view.Slide(2, 1); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2 })); Assert.That(view.Slide(-1, 0), Is.EqualTo(view)); }); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(28); - Assert.That(IC.Eq(list, 0, 28, 1, 2, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } [Test] public void Iterate() @@ -3117,7 +3083,7 @@ public void Iterate() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7 })); }); } @@ -3136,7 +3102,7 @@ public class MulipleViews [SetUp] public void Init() { - list = new ArrayList(); + list = []; for (int i = 0; i < 6; i++) { list.Add(i); @@ -3334,7 +3300,7 @@ private int s(int i, int j) [Test] public void InsertAll() { - ArrayList list2 = new(); + ArrayList list2 = []; for (int i = 0; i < 5; i++) { list2.Add(100 + i); } Assert.That(list.Check(), Is.True, "list check before insertAll"); list.InsertAll(3, list2); @@ -3355,7 +3321,7 @@ public void InsertAll() [Test] public void AddAll() { - ArrayList list2 = new(); + ArrayList list2 = []; for (int i = 0; i < 5; i++) { list2.Add(100 + i); } Assert.That(list.Check(), Is.True, "list check before AddAll"); list.View(1, 2).AddAll(list2); @@ -3376,13 +3342,13 @@ public void AddAll() [Test] public void RemoveAll1() { - ArrayList list2 = new() { 1, 3, 4 }; + ArrayList list2 = [1, 3, 4]; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7 - i; j++) { - list = new ArrayList(); + list = []; for (int k = 0; k < 6; k++) { list.Add(k); @@ -3397,7 +3363,7 @@ public void RemoveAll1() [Test] public void RemoveAll2() { - ArrayList list2 = new() { 1, 3, 4 }; + ArrayList list2 = [1, 3, 4]; Assert.That(list.Check(), Is.True, "list check before RemoveAll"); list.RemoveAll(list2); @@ -3468,7 +3434,7 @@ public void RemoveAll2() [Test] public void RetainAll() { - ArrayList list2 = new() { 2, 4, 5 }; + ArrayList list2 = [2, 4, 5]; Assert.That(list.Check(), Is.True, "list check before RetainAll"); list.RetainAll(list2); @@ -3539,13 +3505,13 @@ public void RetainAll() [Test] public void RemoveAllCopies() { - ArrayList list2 = new() { 0, 2, 2, 2, 5, 2, 1 }; + ArrayList list2 = [0, 2, 2, 2, 5, 2, 1]; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7 - i; j++) { - list = new ArrayList(); + list = []; list.AddAll(list2); ArrayList v = (ArrayList)list.View(i, j); list.RemoveAllCopies(2); @@ -3654,15 +3620,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new ArrayList(); + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3717,15 +3683,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new ArrayList(); + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3786,17 +3752,17 @@ public class MultiLevelUnOrderedOfOrdered public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dat = new ArrayList(); - dut = new ArrayList(); - dot = new ArrayList(); + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(2); dat.Add(1); dut.Add(3); dot.Add(1); dot.Add(2); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); - Dot = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } [Test] @@ -3857,17 +3823,17 @@ public class MultiLevelOrderedOfOrdered public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dat = new ArrayList(); - dut = new ArrayList(); - dot = new ArrayList(); + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(2); dat.Add(1); dut.Add(3); dot.Add(1); dot.Add(2); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); - Dot = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3925,9 +3891,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; } [Test] @@ -4010,7 +3976,7 @@ public void WrongOrder() Assert.That(dut.SequencedEquals(dit), Is.True); }); dit.Add(7); - ((ArrayList)dut).InsertFirst(7); + dut.InsertFirst(7); Assert.Multiple(() => { Assert.That(dit.SequencedEquals(dut), Is.False); @@ -4048,9 +4014,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; } [Test] @@ -4171,15 +4137,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -4230,15 +4196,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -4290,18 +4256,18 @@ public class MultiLevelUnOrderedOfOrdered [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); - dot = new ArrayList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); - Dot = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -4360,18 +4326,18 @@ public class MultiLevelOrderedOfOrdered [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); - dot = new ArrayList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new ArrayList>(); - Dat = new ArrayList>(); - Dut = new ArrayList>(); - Dot = new ArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } diff --git a/C5.Tests/Arrays/CircularQueueTest.cs b/C5.Tests/Arrays/CircularQueueTest.cs index e8e66fde..e722b780 100644 --- a/C5.Tests/Arrays/CircularQueueTest.cs +++ b/C5.Tests/Arrays/CircularQueueTest.cs @@ -12,8 +12,8 @@ public class GenericTesters public void TestEvents() { CircularQueue factory() { return new CircularQueue(); } - new C5.Tests.Templates.Events.QueueTester>().Test(factory); - new C5.Tests.Templates.Events.StackTester>().Test(factory); + new Templates.Events.QueueTester>().Test(factory); + new Templates.Events.StackTester>().Test(factory); } //[Test] @@ -123,7 +123,7 @@ public void Expand() { Assert.That(queue.Check(), Is.True); loadup3(); - Assert.That(IC.Eq(queue, 14, 15, 16, 17), Is.True); + Assert.That(queue, Is.EqualTo(new[] { 14, 15, 16, 17 })); } [Test] @@ -134,7 +134,7 @@ public void Simple() { Assert.That(queue.Check(), Is.True); Assert.That(queue, Has.Count.EqualTo(5)); - Assert.That(IC.Eq(queue, 12, 13, 103, 14, 15), Is.True); + Assert.That(queue, Is.EqualTo(new[] { 12, 13, 103, 14, 15 })); }); Assert.That(queue.Choose(), Is.EqualTo(12)); } @@ -179,7 +179,7 @@ public void Simple2() { Assert.That(queue.Check(), Is.True); Assert.That(queue, Has.Count.EqualTo(5)); - Assert.That(IC.Eq(queue, 15, 1000, 1001, 1002, 1003), Is.True); + Assert.That(queue, Is.EqualTo(new[] { 15, 1000, 1001, 1002, 1003 })); }); Assert.That(queue.Choose(), Is.EqualTo(15)); } @@ -203,7 +203,7 @@ public void Counting() [Test] public void SW200602() { - C5.CircularQueue list = new(8); + CircularQueue list = new(8); for (int count = 0; count <= 7; count++) { list.Enqueue(count); diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index 99e0fa03..f29f2753 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -13,8 +13,8 @@ public class GenericTesters [Test] public void TestEvents() { - HashedArrayList factory() { return new HashedArrayList(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.ListTester>().Test(factory); + HashedArrayList factory() { return new HashedArrayList(TenEqualityComparer.Instance); } + new Templates.Events.ListTester>().Test(factory); } [Test] @@ -511,7 +511,7 @@ public class BadEnumerable [SetUp] public void Init() { - list = new HashedArrayList(); + list = []; } [Test] @@ -528,7 +528,7 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 91, 81, 71, 56, 18), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 91, 81, 71, 56, 18 })); }); } @@ -546,7 +546,7 @@ public void AddAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 91, 81, 71, 56, 18), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 91, 81, 71, 56, 18 })); }); } @@ -564,7 +564,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 18), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 18 })); }); } @@ -582,7 +582,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 18), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 18 })); }); } @@ -601,7 +601,7 @@ public void ContainsAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 56, 18), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 56, 18 })); }); } @@ -644,7 +644,7 @@ public class Multiops [SetUp] public void Init() { - list = new HashedArrayList(); + list = []; always = delegate { return true; }; never = delegate { return false; }; even = delegate (int i) { return i % 2 == 0; }; @@ -731,7 +731,7 @@ public class GetEnumerator [SetUp] - public void Init() { list = new HashedArrayList(); } + public void Init() { list = []; } [Test] @@ -838,7 +838,7 @@ public class CollectionOrSink [SetUp] - public void Init() { list = new HashedArrayList(); } + public void Init() { list = []; } [Test] public void Choose() @@ -884,15 +884,15 @@ public void AddAll() { list.Add(3); list.Add(4); list.Add(5); - HashedArrayList list2 = new(); + HashedArrayList list2 = []; list2.AddAll(list); - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); list.AddAll(list2); Assert.Multiple(() => { - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); - Assert.That(IC.Eq(list, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(list, Is.EqualTo(new[] { 3, 4, 5 })); }); } @@ -910,7 +910,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new HashedArrayList(TenEqualityComparer.Default); + list = new HashedArrayList(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -972,7 +972,7 @@ public class UniqueItems private HashedArrayList list; [SetUp] - public void Init() { list = new HashedArrayList(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -982,14 +982,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 1, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 1), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -1004,7 +1004,7 @@ public class ArrayTest [SetUp] public void Init() { - list = new HashedArrayList(); + list = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -1016,70 +1016,46 @@ public void Init() [TearDown] public void Dispose() { list.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(list.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.Empty); list.Add(7); list.Add(8); - Assert.That(aeq(list.ToArray(), 7, 8), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.EqualTo(new[] { 7, 8 })); } - [Test] public void CopyTo() { list.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(6); list.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(4); list.Add(5); list.Add(9); list.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 1009 })); list.Clear(); list.Add(7); list.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 7 })); } - [Test] public void CopyToBad() { Assert.Throws(() => list.CopyTo(a, 11)); } - [Test] public void CopyToBad2() { Assert.Throws(() => list.CopyTo(a, -1)); } - [Test] public void CopyToTooFar() { @@ -1110,7 +1086,7 @@ public class Searching [SetUp] - public void Init() { list = new HashedArrayList(); } + public void Init() { list = []; } [Test] @@ -1203,7 +1179,7 @@ public void RemoveAllCopies() }); list.Add(5); list.Add(8); list.RemoveAllCopies(8); - Assert.That(IC.Eq(list, 7, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7, 5 })); } @@ -1217,7 +1193,7 @@ public void FindAll() Assert.Multiple(() => { Assert.That(((HashedArrayList)list.FindAll(f)).Check(), Is.True); - Assert.That(IC.Eq(list.FindAll(f), 8, 10), Is.True); + Assert.That(list.FindAll(f), Is.EqualTo(new[] { 8, 10 })); }); } @@ -1225,7 +1201,7 @@ public void FindAll() [Test] public void ContainsAll() { - HashedArrayList list2 = new(); + HashedArrayList list2 = []; Assert.That(list.ContainsAll(list2), Is.True); list2.Add(4); @@ -1240,7 +1216,7 @@ public void ContainsAll() [Test] public void RetainAll() { - HashedArrayList list2 = new(); + HashedArrayList list2 = []; list.Add(4); list.Add(5); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); @@ -1248,7 +1224,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -1257,20 +1233,20 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 6 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RetainAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list), Is.True); + Assert.That(list, Is.Empty); } [Test] public void RemoveAll() { - HashedArrayList list2 = new(); + HashedArrayList list2 = []; list.Add(4); list.Add(5); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); @@ -1278,7 +1254,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 6 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -1287,13 +1263,13 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RemoveAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4 })); } @@ -1308,16 +1284,16 @@ public void Remove() Assert.That(list.Remove(4), Is.True); }); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(5)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7 })); }); } @@ -1350,7 +1326,7 @@ public class Searching [SetUp] public void Init() { - dit = new HashedArrayList(); + dit = []; } @@ -1391,7 +1367,7 @@ public class Removing [SetUp] public void Init() { - dit = new HashedArrayList(); + dit = []; } [Test] @@ -1401,15 +1377,15 @@ public void RemoveAt() Assert.Multiple(() => { Assert.That(dit.RemoveAt(1), Is.EqualTo(7)); - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 5, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 5, 9, 1, 2 })); Assert.That(dit.RemoveAt(0), Is.EqualTo(5)); }); - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1, 2 })); Assert.That(dit.RemoveAt(2), Is.EqualTo(2)); - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1 })); } [Test] @@ -1439,39 +1415,39 @@ public void RemoveInterval() dit.RemoveInterval(3, 0); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 40, 50, 60 })); }); dit.RemoveInterval(3, 1); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 50, 60 })); }); dit.RemoveInterval(1, 3); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 60 })); }); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.Empty); }); dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40, 50, 60 })); }); dit.RemoveInterval(2, 2); Assert.Multiple(() => { - Assert.That(((HashedArrayList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40 })); }); } @@ -1542,7 +1518,7 @@ public void This() Assert.That(lst.First, Is.EqualTo(56)); lst.Add(7); lst.Add(77); lst.Add(777); lst.Add(7777); lst[0] = 45; lst[2] = 78; lst[4] = 101; - Assert.That(IC.Eq(lst, 45, 7, 78, 777, 101), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 45, 7, 78, 777, 101 })); } [Test] @@ -1656,22 +1632,22 @@ public class Inserting public void Insert() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 4); - Assert.That(IC.Eq(lst, 7, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5 })); lst.Insert(3, 2); - Assert.That(IC.Eq(lst, 7, 4, 5, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5, 2 })); } [Test] public void InsertDuplicate() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); Assert.Throws(() => lst.Insert(1, 5)); } @@ -1680,9 +1656,9 @@ public void InsertDuplicate() public void InsertAllDuplicate1() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); try { lst.InsertAll(1, [1, 2, 3, 4]); @@ -1694,7 +1670,7 @@ public void InsertAllDuplicate1() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 1, 2, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 1, 2, 3 })); }); } @@ -1702,9 +1678,9 @@ public void InsertAllDuplicate1() public void InsertAllDuplicate2() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); try { lst.InsertAll(1, [5, 6, 5, 8]); @@ -1716,7 +1692,7 @@ public void InsertAllDuplicate2() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 5, 6, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 6, 3 })); }); } @@ -1768,7 +1744,7 @@ public void InsertFirstLast() lst.InsertLast(25); lst.InsertFirst(34); lst.InsertLast(55); - Assert.That(IC.Eq(lst, 34, 24, 14, 4, 5, 15, 25, 55), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 34, 24, 14, 4, 5, 15, 25, 55 })); } @@ -1783,19 +1759,19 @@ public void InsertFirst() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 3, 4, 5 })); }); lst.ViewOf(3).InsertFirst(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 4, 5 })); }); lst.ViewOf(5).InsertFirst(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 4, 9, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 4, 9, 5 })); }); } @@ -1821,19 +1797,19 @@ public void InsertAfter() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 7, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 7, 3, 4, 5 })); }); lst.LastViewOf(1).InsertLast(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 7, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 7, 3, 4, 5 })); }); lst.LastViewOf(5).InsertLast(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 7, 3, 4, 5, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 7, 3, 4, 5, 9 })); }); } @@ -1865,21 +1841,21 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4 })); }); lst.RemoveAll(lst2); lst.InsertAll(4, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 3, 4, 7, 8, 9 })); }); lst.RemoveAll(lst2); lst.InsertAll(2, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 7, 8, 9, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 7, 8, 9, 3, 4 })); }); } @@ -2022,31 +1998,31 @@ public void Reverse() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(0, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 0).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); lst.View(5, 1).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); } @@ -2211,13 +2187,13 @@ public class Sorting public void Sort() { lst.Add(5); lst.Add(6); lst.Add(55); lst.Add(7); lst.Add(3); - Assert.That(lst.IsSorted(new IC()), Is.False); - lst.Sort(new IC()); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.False); + lst.Sort(new IntegerComparer()); Assert.Multiple(() => { Assert.That(lst.IsSorted(), Is.True); - Assert.That(lst.IsSorted(new IC()), Is.True); - Assert.That(IC.Eq(lst, 3, 5, 6, 7, 55), Is.True); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } } @@ -2235,13 +2211,12 @@ public class Range [SetUp] - public void Init() { lst = new HashedArrayList(); } + public void Init() { lst = []; } [TearDown] public void Dispose() { lst.Dispose(); } - [Test] public void GetRange() { @@ -2253,14 +2228,13 @@ public void GetRange() Assert.Multiple(() => { - Assert.That(IC.Eq(lst[0, 3], 0, 1, 2), Is.True); - Assert.That(IC.Eq(lst[3, 3], 3, 4, 5), Is.True); - Assert.That(IC.Eq(lst[6, 3], 6, 7, 8), Is.True); - Assert.That(IC.Eq(lst[6, 4], 6, 7, 8, 9), Is.True); + Assert.That(lst[0, 3], Is.EqualTo(new[] { 0, 1, 2 })); + Assert.That(lst[3, 3], Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(lst[6, 3], Is.EqualTo(new[] { 6, 7, 8 })); + Assert.That(lst[6, 4], Is.EqualTo(new[] { 6, 7, 8, 9 })); }); } - [Test] public void Backwards() { @@ -2271,14 +2245,13 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[0, 3].Backwards(), 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[3, 3].Backwards(), 5, 4, 3), Is.True); - Assert.That(IC.Eq(lst[6, 4].Backwards(), 9, 8, 7, 6), Is.True); + Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); + Assert.That(lst[0, 3].Backwards(), Is.EqualTo(new[] { 2, 1, 0 })); + Assert.That(lst[3, 3].Backwards(), Is.EqualTo(new[] { 5, 4, 3 })); + Assert.That(lst[6, 4].Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6 })); }); } - [Test] public void DirectionAndCount() { @@ -2333,13 +2306,13 @@ public class Simple [SetUp] public void Init() { - list = new HashedArrayList - { + list = + [ 0, 1, 2, 3 - }; + ]; view = (HashedArrayList)list.View(1, 2); } @@ -2376,8 +2349,8 @@ public void InsertPointer() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8), Is.True); - Assert.That(IC.Eq(view, 11, 1, 9, 7, 2, 10), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 11, 1, 9, 7, 2, 10, 3, 8 })); + Assert.That(view, Is.EqualTo(new[] { 11, 1, 9, 7, 2, 10 })); }); } @@ -2438,21 +2411,21 @@ public void ViewOf() Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.ViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.LastViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); } @@ -2475,10 +2448,10 @@ public void BadViewOf() [Test] public void ArrayStuff() { - Assert.That(IC.Eq(view.ToArray(), 1, 2), Is.True); + Assert.That(view.ToArray(), Is.EqualTo(new[] { 1, 2 })); int[] extarray = new int[5]; view.CopyTo(extarray, 2); - Assert.That(IC.Eq(extarray, 0, 0, 1, 2, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 0, 1, 2, 0 })); } @@ -2488,15 +2461,15 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2 })); }); view.InsertFirst(10); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 10, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 10, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 10, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 10, 1, 2 })); }); view.Clear(); Assert.Multiple(() => @@ -2506,8 +2479,8 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); - Assert.That(IC.Eq(view), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.False); @@ -2515,49 +2488,49 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 3), Is.True); - Assert.That(IC.Eq(view, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8 })); }); view.Add(12); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12 })); }); view./*ViewOf(12).*/InsertLast(15); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12, 15 })); }); view.ViewOf(12).InsertFirst(18); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15 })); }); - HashedArrayList lst2 = new() - { + HashedArrayList lst2 = + [ 90, 92 - }; + ]; view.AddAll(lst2); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92 })); }); view.InsertLast(66); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92, 66), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 66, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92, 66 })); }); } @@ -2567,7 +2540,7 @@ public void Bxxx() { Assert.Multiple(() => { - Assert.That(IC.Eq(view.Backwards(), 2, 1), Is.True); + Assert.That(view.Backwards(), Is.EqualTo(new[] { 2, 1 })); Assert.That(view.Underlying, Is.SameAs(list)); Assert.That(list.Underlying, Is.Null); Assert.That(view.Direction, Is.EqualTo(Direction.Forwards)); @@ -2587,10 +2560,10 @@ public void Contains() Assert.That(view.Contains(0), Is.False); }); - HashedArrayList lst2 = new() - { + HashedArrayList lst2 = + [ 2 - }; + ]; Assert.That(view.ContainsAll(lst2), Is.True); lst2.Add(3); Assert.Multiple(() => @@ -2627,11 +2600,11 @@ public void FIFO() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 23, 24, 25 })); Assert.That(view.Remove(), Is.EqualTo(1)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24, 25 })); view.FIFO = false; Assert.Multiple(() => { @@ -2639,7 +2612,7 @@ public void FIFO() Assert.That(view.Remove(), Is.EqualTo(25)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24 })); } @@ -2664,7 +2637,7 @@ public void MapEtc() Assert.Multiple(() => { Assert.That(list2.Check(), Is.True); - Assert.That(IC.Eq(list2, 1, 5, 9), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 1, 5, 9 })); }); } @@ -2716,7 +2689,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 2, 36 })); }); IList list2 = new HashedArrayList @@ -2728,7 +2701,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 40, 41, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 40, 41, 2, 36 })); }); } @@ -2737,13 +2710,13 @@ public void Insert() public void Sort() { view.Add(45); view.Add(47); view.Add(46); view.Add(48); - Assert.That(view.IsSorted(new IC()), Is.False); - view.Sort(new IC()); + Assert.That(view.IsSorted(new IntegerComparer()), Is.False); + view.Sort(new IntegerComparer()); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 45, 46, 47, 48, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2, 45, 46, 47, 48), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 45, 46, 47, 48, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 45, 46, 47, 48 })); }); } @@ -2754,47 +2727,47 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); Assert.That(view.Remove(1), Is.False); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); Assert.That(view.Remove(0), Is.False); }); check(); - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); - Assert.That(IC.Eq(list, 0, 2, 5, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); + Assert.That(list, Is.EqualTo(new[] { 0, 2, 5, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 2, 5, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1 })); - HashedArrayList l2 = new() - { + HashedArrayList l2 = + [ 1, 2, 2, 3, 1 - }; + ]; view.RemoveAll(l2); check(); - Assert.That(IC.Eq(view, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 5 })); view.RetainAll(l2); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(2); view.Add(4); view.Add(5); Assert.Multiple(() => { @@ -2803,7 +2776,7 @@ public void Remove() }); Assert.That(view.RemoveAt(0), Is.EqualTo(4)); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); view.Add(6); view.Add(78); Assert.Multiple(() => { @@ -2813,7 +2786,7 @@ public void Remove() view.Add(2); view.Add(5); view.Add(3); view.Add(1); view.RemoveInterval(1, 2); check(); - Assert.That(IC.Eq(view, 6, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 6, 1 })); } @@ -2828,12 +2801,12 @@ public void Reverse() view.View(3, 4).Reverse(); check(); - Assert.That(IC.Eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19), Is.True); + Assert.That(view, Is.EqualTo(new[] { 10, 11, 12, 16, 15, 14, 13, 17, 18, 19 })); view.Reverse(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10), Is.True); - Assert.That(IC.Eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 19, 18, 17, 13, 14, 15, 16, 12, 11, 10 })); + Assert.That(list, Is.EqualTo(new[] { 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3 })); }); } @@ -2843,21 +2816,21 @@ public void Slide() { view.Slide(1); check(); - Assert.That(IC.Eq(view, 2, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 3 })); view.Slide(-2); check(); - Assert.That(IC.Eq(view, 0, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1 })); view.Slide(0, 3); check(); - Assert.That(IC.Eq(view, 0, 1, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1, 2 })); view.Slide(2, 1); check(); - Assert.That(IC.Eq(view, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2 })); view.Slide(-1, 0); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(28); - Assert.That(IC.Eq(list, 0, 28, 1, 2, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } [Test] public void Iterate() @@ -2891,7 +2864,7 @@ public void Iterate() } //foreach (int cell in list) Console.Write(" " + cell); //Assert.IsTrue(list.Check()); - Assert.That(IC.Eq(list, 2, 4, 8, 668, 13, 6, 1, 667, 10, 666, 11), Is.True); + Assert.That(list, Is.EqualTo(new[] { 2, 4, 8, 668, 13, 6, 1, 667, 10, 666, 11 })); } @@ -3459,9 +3432,9 @@ public class IIndexed [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; } @@ -3546,7 +3519,7 @@ public void WrongOrder() Assert.That(dut.SequencedEquals(dit), Is.True); }); dit.Add(7); - ((HashedArrayList)dut).InsertFirst(7); + dut.InsertFirst(7); Assert.Multiple(() => { Assert.That(dit.SequencedEquals(dut), Is.False); @@ -3586,9 +3559,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; } @@ -3713,15 +3686,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new HashedArrayList>(); - Dat = new HashedArrayList>(); - Dut = new HashedArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3774,15 +3747,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new HashedArrayList>(); - Dat = new HashedArrayList>(); - Dut = new HashedArrayList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3836,18 +3809,18 @@ public class MultiLevelUnOrderedOfOrdered [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); - dot = new HashedArrayList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new HashedArrayList>(); - Dat = new HashedArrayList>(); - Dut = new HashedArrayList>(); - Dot = new HashedArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3906,18 +3879,18 @@ public class MultiLevelOrderedOfOrdered [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); - dot = new HashedArrayList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); //{2,1} dat.Add(1); dat.Add(2); //{1,2} dut.Add(3); //{3} dot.Add(2); dot.Add(1); //{2,1} - Dit = new HashedArrayList>(); - Dat = new HashedArrayList>(); - Dut = new HashedArrayList>(); - Dot = new HashedArrayList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index 903e67c4..c7eb9260 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -13,8 +13,8 @@ public class GenericTesters [Test] public void TestEvents() { - SortedArray factory() { return new SortedArray(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.SortedIndexedTester>().Test(factory); + SortedArray factory() { return new SortedArray(TenEqualityComparer.Instance); } + new Templates.Events.SortedIndexedTester>().Test(factory); } } @@ -59,7 +59,7 @@ public class Ranges [SetUp] public void Init() { - c = new IC(); + c = new IntegerComparer(); array = new SortedArray(c); for (int i = 1; i <= 10; i++) { @@ -101,37 +101,37 @@ public void Remove() int[] all = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]; array.RemoveRangeFrom(18); - Assert.That(IC.Eq(array, [2, 4, 6, 8, 10, 12, 14, 16]), Is.True); + Assert.That(array, Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16 })); array.RemoveRangeFrom(28); - Assert.That(IC.Eq(array, [2, 4, 6, 8, 10, 12, 14, 16]), Is.True); + Assert.That(array, Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16 })); array.RemoveRangeFrom(13); - Assert.That(IC.Eq(array, [2, 4, 6, 8, 10, 12]), Is.True); + Assert.That(array, Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12 })); array.RemoveRangeFrom(2); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); foreach (int i in all) { array.Add(i); } array.RemoveRangeTo(10); - Assert.That(IC.Eq(array, [10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(array, Is.EqualTo(new[] { 10, 12, 14, 16, 18, 20 })); array.RemoveRangeTo(2); - Assert.That(IC.Eq(array, [10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(array, Is.EqualTo(new[] { 10, 12, 14, 16, 18, 20 })); array.RemoveRangeTo(21); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); foreach (int i in all) { array.Add(i); } array.RemoveRangeFromTo(4, 8); - Assert.That(IC.Eq(array, 2, 8, 10, 12, 14, 16, 18, 20), Is.True); + Assert.That(array, Is.EqualTo(new[] { 2, 8, 10, 12, 14, 16, 18, 20 })); array.RemoveRangeFromTo(14, 28); - Assert.That(IC.Eq(array, 2, 8, 10, 12), Is.True); + Assert.That(array, Is.EqualTo(new[] { 2, 8, 10, 12 })); array.RemoveRangeFromTo(0, 9); - Assert.That(IC.Eq(array, 10, 12), Is.True); + Assert.That(array, Is.EqualTo(new[] { 10, 12 })); array.RemoveRangeFromTo(0, 81); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); } [Test] @@ -141,31 +141,31 @@ public void Normal() Assert.Multiple(() => { - Assert.That(IC.Eq(array, all), Is.True); - Assert.That(IC.Eq(array.RangeAll(), all), Is.True); + Assert.That(array, Is.EqualTo(all)); + Assert.That(array.RangeAll(), Is.EqualTo(all)); Assert.That(array.RangeAll(), Has.Count.EqualTo(10)); - Assert.That(IC.Eq(array.RangeFrom(11), [12, 14, 16, 18, 20]), Is.True); + Assert.That(array.RangeFrom(11), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); Assert.That(array.RangeFrom(11), Has.Count.EqualTo(5)); - Assert.That(IC.Eq(array.RangeFrom(12), [12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(array.RangeFrom(2), all), Is.True); - Assert.That(IC.Eq(array.RangeFrom(1), all), Is.True); - Assert.That(IC.Eq(array.RangeFrom(21), []), Is.True); - Assert.That(IC.Eq(array.RangeFrom(20), [20]), Is.True); - Assert.That(IC.Eq(array.RangeTo(8), [2, 4, 6]), Is.True); - Assert.That(IC.Eq(array.RangeTo(7), [2, 4, 6]), Is.True); + Assert.That(array.RangeFrom(12), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); + Assert.That(array.RangeFrom(2), Is.EqualTo(all)); + Assert.That(array.RangeFrom(1), Is.EqualTo(all)); + Assert.That(array.RangeFrom(21), Is.Empty); + Assert.That(array.RangeFrom(20), Is.EqualTo(new[] { 20 })); + Assert.That(array.RangeTo(8), Is.EqualTo(new[] { 2, 4, 6 })); + Assert.That(array.RangeTo(7), Is.EqualTo(new[] { 2, 4, 6 })); Assert.That(array.RangeTo(7), Has.Count.EqualTo(3)); - Assert.That(IC.Eq(array.RangeTo(2), []), Is.True); - Assert.That(IC.Eq(array.RangeTo(1), []), Is.True); - Assert.That(IC.Eq(array.RangeTo(3), [2]), Is.True); - Assert.That(IC.Eq(array.RangeTo(20), [2, 4, 6, 8, 10, 12, 14, 16, 18]), Is.True); - Assert.That(IC.Eq(array.RangeTo(21), all), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(7, 12), [8, 10]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 11), [6, 8, 10]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(1, 12), [2, 4, 6, 8, 10]), Is.True); + Assert.That(array.RangeTo(2), Is.Empty); + Assert.That(array.RangeTo(1), Is.Empty); + Assert.That(array.RangeTo(3), Is.EqualTo(new[] { 2 })); + Assert.That(array.RangeTo(20), Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16, 18 })); + Assert.That(array.RangeTo(21), Is.EqualTo(all)); + Assert.That(array.RangeFromTo(7, 12), Is.EqualTo(new[] { 8, 10 })); + Assert.That(array.RangeFromTo(6, 11), Is.EqualTo(new[] { 6, 8, 10 })); + Assert.That(array.RangeFromTo(1, 12), Is.EqualTo(new[] { 2, 4, 6, 8, 10 })); Assert.That(array.RangeFromTo(1, 12), Has.Count.EqualTo(5)); - Assert.That(IC.Eq(array.RangeFromTo(2, 12), [2, 4, 6, 8, 10]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 21), [6, 8, 10, 12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 20), [6, 8, 10, 12, 14, 16, 18]), Is.True); + Assert.That(array.RangeFromTo(2, 12), Is.EqualTo(new[] { 2, 4, 6, 8, 10 })); + Assert.That(array.RangeFromTo(6, 21), Is.EqualTo(new[] { 6, 8, 10, 12, 14, 16, 18, 20 })); + Assert.That(array.RangeFromTo(6, 20), Is.EqualTo(new[] { 6, 8, 10, 12, 14, 16, 18 })); }); } @@ -178,27 +178,27 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(array, all), Is.True); - Assert.That(IC.Eq(array.RangeAll().Backwards(), lla), Is.True); - Assert.That(IC.Eq(array.RangeFrom(11).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(array.RangeFrom(12).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(array.RangeFrom(2).Backwards(), lla), Is.True); - Assert.That(IC.Eq(array.RangeFrom(1).Backwards(), lla), Is.True); - Assert.That(IC.Eq(array.RangeFrom(21).Backwards(), []), Is.True); - Assert.That(IC.Eq(array.RangeFrom(20).Backwards(), [20]), Is.True); - Assert.That(IC.Eq(array.RangeTo(8).Backwards(), [6, 4, 2]), Is.True); - Assert.That(IC.Eq(array.RangeTo(7).Backwards(), [6, 4, 2]), Is.True); - Assert.That(IC.Eq(array.RangeTo(2).Backwards(), []), Is.True); - Assert.That(IC.Eq(array.RangeTo(1).Backwards(), []), Is.True); - Assert.That(IC.Eq(array.RangeTo(3).Backwards(), [2]), Is.True); - Assert.That(IC.Eq(array.RangeTo(20).Backwards(), [18, 16, 14, 12, 10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(array.RangeTo(21).Backwards(), lla), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(7, 12).Backwards(), [10, 8]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 11).Backwards(), [10, 8, 6]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(1, 12).Backwards(), [10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(2, 12).Backwards(), [10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 21).Backwards(), [20, 18, 16, 14, 12, 10, 8, 6]), Is.True); - Assert.That(IC.Eq(array.RangeFromTo(6, 20).Backwards(), [18, 16, 14, 12, 10, 8, 6]), Is.True); + Assert.That(array, Is.EqualTo(all)); + Assert.That(array.RangeAll().Backwards(), Is.EqualTo(lla)); + Assert.That(array.RangeFrom(11).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(array.RangeFrom(12).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(array.RangeFrom(2).Backwards(), Is.EqualTo(lla)); + Assert.That(array.RangeFrom(1).Backwards(), Is.EqualTo(lla)); + Assert.That(array.RangeFrom(21).Backwards(), Is.Empty); + Assert.That(array.RangeFrom(20).Backwards(), Is.EqualTo(new[] { 20 })); + Assert.That(array.RangeTo(8).Backwards(), Is.EqualTo(new[] { 6, 4, 2 })); + Assert.That(array.RangeTo(7).Backwards(), Is.EqualTo(new[] { 6, 4, 2 })); + Assert.That(array.RangeTo(2).Backwards(), Is.Empty); + Assert.That(array.RangeTo(1).Backwards(), Is.Empty); + Assert.That(array.RangeTo(3).Backwards(), Is.EqualTo(new[] { 2 })); + Assert.That(array.RangeTo(20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 8, 6, 4, 2 })); + Assert.That(array.RangeTo(21).Backwards(), Is.EqualTo(lla)); + Assert.That(array.RangeFromTo(7, 12).Backwards(), Is.EqualTo(new[] { 10, 8 })); + Assert.That(array.RangeFromTo(6, 11).Backwards(), Is.EqualTo(new[] { 10, 8, 6 })); + Assert.That(array.RangeFromTo(1, 12).Backwards(), Is.EqualTo(new[] { 10, 8, 6, 4, 2 })); + Assert.That(array.RangeFromTo(2, 12).Backwards(), Is.EqualTo(new[] { 10, 8, 6, 4, 2 })); + Assert.That(array.RangeFromTo(6, 21).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12, 10, 8, 6 })); + Assert.That(array.RangeFromTo(6, 20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 8, 6 })); }); } @@ -238,7 +238,7 @@ public class BagItf [SetUp] public void Init() { - array = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); for (int i = 10; i < 20; i++) { array.Add(i); @@ -278,7 +278,7 @@ public class Div [SetUp] public void Init() { - array = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); } [Test] @@ -377,13 +377,13 @@ public void Dispose() [TestFixture] public class FindOrAdd { - private SortedArray> bag; + private SortedArray> bag; [SetUp] public void Init() { - bag = new SortedArray>(new KeyValuePairComparer(new IC())); + bag = new SortedArray>(new KeyValuePairComparer(new IntegerComparer())); } @@ -424,7 +424,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new SortedArray(TenEqualityComparer.Default); + list = new SortedArray(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -496,14 +496,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 1, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 1), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -518,7 +518,7 @@ public class ArrayTest [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); a = new int[10]; for (int i = 0; i < 10; i++) { @@ -531,32 +531,13 @@ public void Init() public void Dispose() { tree = null; } - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(tree.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.Empty); tree.Add(7); tree.Add(4); - Assert.That(aeq(tree.ToArray(), 4, 7), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); } @@ -564,18 +545,18 @@ public void ToArray() public void CopyTo() { tree.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(6); tree.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(4); tree.Add(9); tree.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 1009 })); tree.Clear(); tree.Add(7); tree.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); } @@ -606,16 +587,16 @@ public void CopyToTooFar() [TestFixture] public class Combined { - private IIndexedSorted> lst; + private IIndexedSorted> lst; [SetUp] public void Init() { - lst = new SortedArray>(new KeyValuePairComparer(new IC())); + lst = new SortedArray>(new KeyValuePairComparer(new IntegerComparer())); for (int i = 0; i < 10; i++) { - lst.Add(new System.Collections.Generic.KeyValuePair(i, i + 30)); + lst.Add(new SCG.KeyValuePair(i, i + 30)); } } @@ -626,7 +607,7 @@ public void Init() [Test] public void Find() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -634,7 +615,7 @@ public void Find() Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Find(ref p), Is.False); } @@ -642,7 +623,7 @@ public void Find() [Test] public void FindOrAdd() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -650,7 +631,7 @@ public void FindOrAdd() Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 79); + p = new SCG.KeyValuePair(13, 79); Assert.Multiple(() => { Assert.That(lst.FindOrAdd(ref p), Is.False); @@ -663,7 +644,7 @@ public void FindOrAdd() [Test] public void Update() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -671,7 +652,7 @@ public void Update() Assert.That(lst[3].Key, Is.EqualTo(3)); Assert.That(lst[3].Value, Is.EqualTo(78)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Update(p), Is.False); } @@ -679,7 +660,7 @@ public void Update() [Test] public void UpdateOrAdd1() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -687,7 +668,7 @@ public void UpdateOrAdd1() Assert.That(lst[3].Key, Is.EqualTo(3)); Assert.That(lst[3].Value, Is.EqualTo(78)); }); - p = new System.Collections.Generic.KeyValuePair(13, 79); + p = new SCG.KeyValuePair(13, 79); Assert.Multiple(() => { Assert.That(lst.UpdateOrAdd(p), Is.False); @@ -716,7 +697,7 @@ public void UpdateOrAdd2() public void UpdateOrAddWithExpand() { // bug20071217 - SortedArray arr = new(); + SortedArray arr = []; for (int i = 0; i < 50; i++) { arr.UpdateOrAdd(i + 0.1); @@ -729,7 +710,7 @@ public void UpdateOrAddWithExpand() public void FindOrAddWithExpand() { // bug20071217 - SortedArray arr = new(); + SortedArray arr = []; for (int i = 0; i < 50; i++) { double iVar = i + 0.1; @@ -742,7 +723,7 @@ public void FindOrAddWithExpand() [Test] public void RemoveWithReturn() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -752,7 +733,7 @@ public void RemoveWithReturn() Assert.That(lst[3].Key, Is.EqualTo(4)); Assert.That(lst[3].Value, Is.EqualTo(34)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Remove(p, out _), Is.False); } } @@ -767,7 +748,7 @@ public class Remove [SetUp] public void Init() { - array = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); for (int i = 10; i < 20; i++) { array.Add(i); @@ -978,7 +959,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); } @@ -1241,7 +1222,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); } @@ -1320,7 +1301,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - array = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); } @@ -1481,7 +1462,7 @@ public class Enumerator [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1547,7 +1528,7 @@ public class RangeEnumerator [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1646,7 +1627,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); array = new SortedArray(ic); } @@ -1818,21 +1799,18 @@ public void FindAll() [Test] public void Map() { - Assert.That(array.Map(new Func(themap), new SC()), Is.Empty); + Assert.That(array.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); for (int i = 0; i < 11; i++) { array.Add(i * i * i); } - IIndexedSorted res = array.Map(new Func(themap), new SC()); + var res = array.Map(new Func(themap), StringComparer.InvariantCulture); Assert.Multiple(() => { Assert.That(((SortedArray)res).Check(), Is.True); Assert.That(res, Has.Count.EqualTo(11)); - }); - Assert.Multiple(() => - { Assert.That(res[0], Is.EqualTo("AA 0 BB")); Assert.That(res[3], Is.EqualTo("AA 27 BB")); Assert.That(res[5], Is.EqualTo("AA 125 BB")); @@ -1840,7 +1818,6 @@ public void Map() }); } - [Test] public void BadMap() { @@ -1849,7 +1826,7 @@ public void BadMap() array.Add(i * i * i); } - var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), new SC()); }); + var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), StringComparer.InvariantCulture); }); Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); } @@ -1886,11 +1863,11 @@ public void CutInt() Assert.Multiple(() => { - Assert.That(array.Cut(new IC(3), out int low, out bool lval, out int high, out bool hval), Is.False); + Assert.That(array.Cut(new IntegerComparer(3), out int low, out bool lval, out int high, out bool hval), Is.False); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(4)); Assert.That(low, Is.EqualTo(2)); - Assert.That(array.Cut(new IC(6), out low, out lval, out high, out hval), Is.True); + Assert.That(array.Cut(new IntegerComparer(6), out low, out lval, out high, out hval), Is.True); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(8)); Assert.That(low, Is.EqualTo(4)); @@ -1983,13 +1960,13 @@ public class AddAll [SetUp] - public void Init() { array = new SortedArray(new IC()); } + public void Init() { array = new SortedArray(new IntegerComparer()); } [Test] public void EmptyEmpty() { - array.AddAll(new FunEnumerable(0, new Func(sqr))); + array.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); } @@ -2003,7 +1980,7 @@ public void SomeEmpty() array.Add(i); } - array.AddAll(new FunEnumerable(0, new Func(sqr))); + array.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(array, Has.Count.EqualTo(5)); Assert.That(array.Check(), Is.True); } @@ -2012,7 +1989,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - array.AddAll(new FunEnumerable(4, new Func(sqr))); + array.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.Multiple(() => { Assert.That(array, Has.Count.EqualTo(4)); @@ -2033,12 +2010,12 @@ public void SomeSome() array.Add(i); } - array.AddAll(new FunEnumerable(4, new Func(sqr))); + array.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.That(array, Has.Count.EqualTo(9)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 3, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); }); } @@ -2061,13 +2038,13 @@ public class AddSorted [SetUp] - public void Init() { array = new SortedArray(new IC()); } + public void Init() { array = new SortedArray(new IntegerComparer()); } [Test] public void EmptyEmpty() { - array.AddSorted(new FunEnumerable(0, new Func(sqr))); + array.AddSorted(new FuncEnumerable(0, new Func(sqr))); Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); } @@ -2082,7 +2059,7 @@ public void SomeEmpty() array.Add(i); } - array.AddSorted(new FunEnumerable(0, new Func(sqr))); + array.AddSorted(new FuncEnumerable(0, new Func(sqr))); Assert.That(array, Has.Count.EqualTo(5)); Assert.That(array.Check(), Is.True); } @@ -2092,7 +2069,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - array.AddSorted(new FunEnumerable(4, new Func(sqr))); + array.AddSorted(new FuncEnumerable(4, new Func(sqr))); Assert.That(array, Has.Count.EqualTo(4)); Assert.Multiple(() => { @@ -2114,19 +2091,19 @@ public void SomeSome() array.Add(i); } - array.AddSorted(new FunEnumerable(4, new Func(sqr))); + array.AddSorted(new FuncEnumerable(4, new Func(sqr))); Assert.That(array, Has.Count.EqualTo(9)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 3, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); }); } [Test] public void EmptyBad() { - var exception = Assert.Throws(() => array.AddSorted(new FunEnumerable(9, new Func(bad)))); + var exception = Assert.Throws(() => array.AddSorted(new FuncEnumerable(9, new Func(bad)))); Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); } @@ -2144,8 +2121,8 @@ public class Rest [SetUp] public void Init() { - array = new SortedArray(new IC()); - array2 = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); + array2 = new SortedArray(new IntegerComparer()); for (int i = 0; i < 10; i++) { array.Add(i); @@ -2166,28 +2143,28 @@ public void RemoveAll() { Assert.That(array, Has.Count.EqualTo(8)); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); array.RemoveAll(array2.RangeFromTo(3, 7)); Assert.Multiple(() => { Assert.That(array, Has.Count.EqualTo(8)); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); array.RemoveAll(array2.RangeFromTo(13, 17)); Assert.That(array, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); array.RemoveAll(array2.RangeFromTo(3, 17)); Assert.That(array, Has.Count.EqualTo(7)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 0, 1, 2, 3, 5, 7, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); }); for (int i = 0; i < 10; i++) { @@ -2199,7 +2176,7 @@ public void RemoveAll() { Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); } @@ -2212,28 +2189,28 @@ public void RetainAll() { Assert.That(array, Has.Count.EqualTo(3)); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 4, 6, 8), Is.True); + Assert.That(array, Is.EqualTo(new[] { 4, 6, 8 })); }); array.RetainAll(array2.RangeFromTo(1, 17)); Assert.That(array, Has.Count.EqualTo(3)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 4, 6, 8), Is.True); + Assert.That(array, Is.EqualTo(new[] { 4, 6, 8 })); }); array.RetainAll(array2.RangeFromTo(3, 5)); Assert.That(array, Has.Count.EqualTo(1)); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array, 4), Is.True); + Assert.That(array, Is.EqualTo(new[] { 4 })); }); array.RetainAll(array2.RangeFromTo(7, 17)); Assert.That(array, Is.Empty); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -2245,7 +2222,7 @@ public void RetainAll() { Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -2257,7 +2234,7 @@ public void RetainAll() { Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); } @@ -2287,21 +2264,21 @@ public void RemoveInterval() { Assert.That(array.Check(), Is.True); Assert.That(array, Has.Count.EqualTo(6)); - Assert.That(IC.Eq(array, 0, 1, 2, 7, 8, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 7, 8, 9 })); }); array.RemoveInterval(2, 3); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); Assert.That(array, Has.Count.EqualTo(3)); - Assert.That(IC.Eq(array, 0, 1, 9), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 9 })); }); array.RemoveInterval(0, 3); Assert.Multiple(() => { Assert.That(array.Check(), Is.True); Assert.That(array, Is.Empty); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); } @@ -2332,9 +2309,9 @@ public void GetRange() { SCG.IEnumerable e = array[3, 3]; - Assert.That(IC.Eq(e, 3, 4, 5), Is.True); + Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); e = array[3, 0]; - Assert.That(IC.Eq(e), Is.True); + Assert.That(e, Is.Empty); } [Test] @@ -2428,7 +2405,7 @@ public void SafeUnSafe() [SetUp] - public void Init() { tree = new SortedArray(new IC()); } + public void Init() { tree = new SortedArray(new IntegerComparer()); } private void unsafe1() @@ -2515,7 +2492,7 @@ public class ConcurrentQueries [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); for (int i = 0; i < sz; i++) { tree.Add(i); @@ -2599,7 +2576,7 @@ public void Init() { dit = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); dat = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); - dut = new SortedArray(8, new RevIC(), EqualityComparer.Default); + dut = new SortedArray(8, new ReverseIntegerComparer(), EqualityComparer.Default); } @@ -2713,7 +2690,7 @@ public void Init() { dit = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); dat = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); - dut = new SortedArray(8, new RevIC(), EqualityComparer.Default); + dut = new SortedArray(8, new ReverseIntegerComparer(), EqualityComparer.Default); } diff --git a/C5.Tests/BasesTest.cs b/C5.Tests/BasesTest.cs index b9c5cbfd..3b1f78de 100644 --- a/C5.Tests/BasesTest.cs +++ b/C5.Tests/BasesTest.cs @@ -22,7 +22,7 @@ public ABT() : base(8, EqualityComparer.Default) { } public string this[int i] { get => array[i]; set => array[i] = value; } - public int thesize { get => size; set => size = value; } + public int TheSize { get => size; set => size = value; } } @@ -31,7 +31,7 @@ public void Check() { ABT abt = new() { - thesize = 3 + TheSize = 3 }; abt[2] = "aaa"; abt[0] = "##"; @@ -46,26 +46,25 @@ namespace itemops [TestFixture] public class Comparers { - private class dbl : IComparable + private class Dbl(double din) : IComparable { - private readonly double d; + private readonly double d = din; - public dbl(double din) { d = din; } - - public int CompareTo(dbl that) + public int CompareTo(Dbl? that) { - return d < that.d ? -1 : d == that.d ? 0 : 1; + return d < that?.d ? -1 : d == that?.d ? 0 : 1; } - public bool Equals(dbl that) { return d == that.d; } + + public bool Equals(Dbl that) { return d == that.d; } } [Test] public void GenericC() { - SCG.IComparer h = SCG.Comparer.Default; - dbl s = new(3.4); - dbl t = new(3.4); - dbl u = new(7.4); + SCG.IComparer h = SCG.Comparer.Default; + Dbl s = new(3.4); + Dbl t = new(3.4); + Dbl u = new(7.4); Assert.Multiple(() => { @@ -78,7 +77,7 @@ public void GenericC() [Test] public void OrdinaryC() { - SCG.IComparer h = SCG.Comparer.Default; + var h = SCG.Comparer.Default; string s = "bamse"; string t = "bamse"; string u = "bimse"; @@ -94,16 +93,16 @@ public void OrdinaryC() [Test] public void GenericCViaBuilder() { - SCG.IComparer h = SCG.Comparer.Default; - dbl s = new(3.4); - dbl t = new(3.4); - dbl u = new(7.4); + SCG.IComparer h = SCG.Comparer.Default; + Dbl s = new(3.4); + Dbl t = new(3.4); + Dbl u = new(7.4); Assert.Multiple(() => { Assert.That(h.Compare(s, t), Is.EqualTo(0)); Assert.That(h.Compare(s, u), Is.LessThan(0)); - Assert.That(SCG.Comparer.Default, Is.SameAs(h)); + Assert.That(SCG.Comparer.Default, Is.SameAs(h)); }); } @@ -111,7 +110,7 @@ public void GenericCViaBuilder() [Test] public void OrdinaryCViaBuilder() { - SCG.IComparer h = SCG.Comparer.Default; + var h = SCG.Comparer.Default; string s = "bamse"; string t = "bamse"; string u = "bimse"; @@ -125,10 +124,10 @@ public void OrdinaryCViaBuilder() } - public void ComparerViaBuilderTest(T item1, T item2) + private static void ComparerViaBuilderTest(T item1, T item2) where T : IComparable { - SCG.IComparer h = SCG.Comparer.Default; + var h = SCG.Comparer.Default; Assert.Multiple(() => { Assert.That(SCG.Comparer.Default, Is.SameAs(h)); @@ -144,25 +143,25 @@ public void ComparerViaBuilderTest(T item1, T item2) [Test] public void PrimitiveComparersViaBuilder() { - ComparerViaBuilderTest('A', 'a'); + ComparerViaBuilderTest('A', 'a'); ComparerViaBuilderTest(-122, 126); ComparerViaBuilderTest(122, 126); ComparerViaBuilderTest(-30000, 3); ComparerViaBuilderTest(3, 50000); - ComparerViaBuilderTest(-10000000, 10000); + ComparerViaBuilderTest(-10000000, 10000); ComparerViaBuilderTest(10000000, 3000000000); - ComparerViaBuilderTest(-1000000000000, 10000000); - ComparerViaBuilderTest(10000000000000UL, 10000000000004UL); - ComparerViaBuilderTest(-0.001F, 0.00001F); - ComparerViaBuilderTest(-0.001, 0.00001E-200); - ComparerViaBuilderTest(-20.001M, 19.999M); + ComparerViaBuilderTest(-1000000000000, 10000000); + ComparerViaBuilderTest(10000000000000UL, 10000000000004UL); + ComparerViaBuilderTest(-0.001F, 0.00001F); + ComparerViaBuilderTest(-0.001, 0.00001E-200); + ComparerViaBuilderTest(-20.001M, 19.999M); } // This test is obsoleted by the one above, but we keep it for good measure [Test] public void IntComparerViaBuilder() { - SCG.IComparer h = SCG.Comparer.Default; + var h = SCG.Comparer.Default; int s = 4; int t = 4; int u = 5; @@ -465,10 +464,10 @@ public void DecimalequalityComparerViaBuilder() [Test] public void UnseqequalityComparerViaBuilder() { - SCG.IEqualityComparer> h = EqualityComparer>.Default; - C5.ICollection s = new LinkedList(); - C5.ICollection t = new LinkedList(); - C5.ICollection u = new LinkedList(); + var h = EqualityComparer>.Default; + var s = new LinkedList(); + var t = new LinkedList(); + var u = new LinkedList(); s.Add(1); s.Add(2); s.Add(3); t.Add(3); t.Add(2); t.Add(1); u.Add(3); u.Add(2); u.Add(4); @@ -485,15 +484,15 @@ public void UnseqequalityComparerViaBuilder() public void SeqequalityComparerViaBuilder2() { SCG.IEqualityComparer> h = EqualityComparer>.Default; - LinkedList s = new() { 1, 2, 3 }; + LinkedList s = [1, 2, 3]; Assert.That(h.GetHashCode(s), Is.EqualTo(CHC.SequencedHashCode(1, 2, 3))); } [Test] public void UnseqequalityComparerViaBuilder2() { - SCG.IEqualityComparer> h = EqualityComparer>.Default; - C5.HashSet s = new() { 1, 2, 3 }; + SCG.IEqualityComparer> h = EqualityComparer>.Default; + HashSet s = [1, 2, 3]; Assert.That(h.GetHashCode(s), Is.EqualTo(CHC.UnsequencedHashCode(1, 2, 3))); } @@ -501,14 +500,14 @@ public void UnseqequalityComparerViaBuilder2() [Test] public void SeqequalityComparerViaBuilder3() { - SCG.IEqualityComparer> h = EqualityComparer>.Default; - C5.IList s = new LinkedList() { 1, 2, 3 }; + SCG.IEqualityComparer> h = EqualityComparer>.Default; + IList s = new LinkedList() { 1, 2, 3 }; Assert.That(h.GetHashCode(s), Is.EqualTo(CHC.SequencedHashCode(1, 2, 3))); } - private interface IFoo : C5.ICollection { void Bamse(); } + private interface IFoo : ICollection { void Bamse(); } - private class Foo : C5.HashSet, IFoo + private class Foo : HashSet, IFoo { internal Foo() : base() { } public void Bamse() { } @@ -541,29 +540,29 @@ public void SeqequalityComparerViaBuilder4() Assert.That(h.GetHashCode(s), Is.EqualTo(CHC.SequencedHashCode(1, 2, 3))); } - private interface IBar : C5.ICollection + private interface IBar : ICollection { void Bamse(); } - private class Bar : C5.HashSet, IBar + private class Bar : HashSet, IBar { internal Bar() : base() { } public void Bamse() { } //TODO: remove all this workaround stuff: - bool C5.ICollection.ContainsAll(System.Collections.Generic.IEnumerable items) + bool ICollection.ContainsAll(SCG.IEnumerable items) { throw new NotImplementedException(); } - void C5.ICollection.RemoveAll(System.Collections.Generic.IEnumerable items) + void ICollection.RemoveAll(SCG.IEnumerable items) { throw new NotImplementedException(); } - void C5.ICollection.RetainAll(System.Collections.Generic.IEnumerable items) + void ICollection.RetainAll(SCG.IEnumerable items) { throw new NotImplementedException(); } @@ -586,7 +585,7 @@ public void UnseqequalityComparerViaBuilder4() [Test] public void StaticEqualityComparerWithNull() { - ArrayList arr = new(); + ArrayList arr = []; SCG.IEqualityComparer eqc = EqualityComparer.Default; Assert.Multiple(() => { @@ -599,7 +598,7 @@ public void StaticEqualityComparerWithNull() private class EveryThingIsEqual : SCG.IEqualityComparer { - public new bool Equals(object o1, object o2) + public new bool Equals(object? o1, object? o2) { return true; } @@ -614,15 +613,15 @@ public int GetHashCode(object o) public void UnsequencedCollectionComparerEquality() { // Repro for bug20101103 - SCG.IEqualityComparer eqc = new EveryThingIsEqual(); + var eqc = new EveryThingIsEqual(); object o1 = new(), o2 = new(); - C5.ICollection coll1 = new ArrayList(eqc); - C5.ICollection coll2 = new ArrayList(eqc); + var coll1 = new ArrayList(eqc); + var coll2 = new ArrayList(eqc); coll1.Add(o1); coll2.Add(o2); Assert.Multiple(() => { - Assert.That(o1.Equals(o2), Is.False); + Assert.That(o1, Is.Not.EqualTo(o2)); Assert.That(coll1.UnsequencedEquals(coll2), Is.True); }); } diff --git a/C5.Tests/Hashing/HashBagTests.cs b/C5.Tests/Hashing/HashBagTests.cs index f2f0cc68..a2982185 100644 --- a/C5.Tests/Hashing/HashBagTests.cs +++ b/C5.Tests/Hashing/HashBagTests.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using System; +using SCG = System.Collections.Generic; + namespace C5.Tests.hashtable.bag { [TestFixture] @@ -11,8 +13,8 @@ public class GenericTesters [Test] public void TestEvents() { - HashBag factory() { return new HashBag(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.CollectionTester>().Test(factory); + HashBag factory() { return new HashBag(TenEqualityComparer.Instance); } + new Templates.Events.CollectionTester>().Test(factory); } //[Test] @@ -211,7 +213,7 @@ public class CollectionOrSink public void Init() { Debug.UseDeterministicHashing = true; - hashbag = new HashBag(); + hashbag = []; } [Test] @@ -283,26 +285,24 @@ public void CountEtAl() }); } - [Test] public void AddAll() { hashbag.Add(3); hashbag.Add(4); hashbag.Add(4); hashbag.Add(5); hashbag.Add(4); - HashBag hashbag2 = new(); + HashBag hashbag2 = []; hashbag2.AddAll(hashbag); - Assert.That(IC.SetEq(hashbag2, 3, 4, 4, 4, 5), Is.True); + Assert.That(hashbag2, Is.EquivalentTo(new[] { 3, 4, 4, 4, 5 })); hashbag.Add(9); hashbag.AddAll(hashbag2); Assert.Multiple(() => { - Assert.That(IC.SetEq(hashbag2, 3, 4, 4, 4, 5), Is.True); - Assert.That(IC.SetEq(hashbag, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 9), Is.True); + Assert.That(hashbag2, Is.EquivalentTo(new[] { 3, 4, 4, 4, 5 })); + Assert.That(hashbag, Is.EquivalentTo(new[] { 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 9 })); }); } - [Test] public void ContainsCount() { @@ -341,14 +341,14 @@ public void RemoveAllCopies() Assert.That(hashbag.ContainsCount(7), Is.EqualTo(1)); hashbag.Add(5); hashbag.Add(8); hashbag.Add(5); hashbag.RemoveAllCopies(8); - Assert.That(IC.Eq(hashbag, 7, 5, 5), Is.True); + Assert.That(hashbag, Is.EqualTo(new[] { 7, 5, 5 })); } [Test] public void ContainsAll() { - HashBag list2 = new(); + HashBag list2 = []; Assert.That(hashbag.ContainsAll(list2), Is.True); list2.Add(4); @@ -367,45 +367,42 @@ public void ContainsAll() Assert.That(hashbag.ContainsAll(list2), Is.True); } - [Test] public void RetainAll() { - HashBag list2 = new(); + HashBag list2 = []; hashbag.Add(4); hashbag.Add(5); hashbag.Add(4); hashbag.Add(6); hashbag.Add(4); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(4); hashbag.RetainAll(list2); - Assert.That(IC.SetEq(hashbag, 4, 4, 5), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 5 })); hashbag.Add(6); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); hashbag.RetainAll(list2); - Assert.That(IC.Eq(hashbag), Is.True); + Assert.That(hashbag, Is.Empty); } - [Test] public void RemoveAll() { - HashBag list2 = new(); + HashBag list2 = []; hashbag.Add(4); hashbag.Add(5); hashbag.Add(6); hashbag.Add(4); hashbag.Add(5); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(4); hashbag.RemoveAll(list2); - Assert.That(IC.SetEq(hashbag, 5, 6), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 5, 6 })); hashbag.Add(5); hashbag.Add(4); list2.Clear(); list2.Add(6); list2.Add(5); hashbag.RemoveAll(list2); - Assert.That(IC.SetEq(hashbag, 4, 5), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 5 })); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); hashbag.RemoveAll(list2); - Assert.That(IC.SetEq(hashbag, 4, 5), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 5 })); } - [Test] public void Remove() { @@ -414,27 +411,26 @@ public void Remove() { Assert.That(hashbag.Remove(2), Is.False); Assert.That(hashbag.Remove(4), Is.True); - Assert.That(IC.SetEq(hashbag, 4, 4, 5, 6), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 5, 6 })); }); hashbag.Add(7); hashbag.Add(21); hashbag.Add(37); hashbag.Add(53); hashbag.Add(69); hashbag.Add(53); hashbag.Add(85); Assert.Multiple(() => { Assert.That(hashbag.Remove(5), Is.True); - Assert.That(IC.SetEq(hashbag, 4, 4, 6, 7, 21, 37, 53, 53, 69, 85), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 6, 7, 21, 37, 53, 53, 69, 85 })); Assert.That(hashbag.Remove(165), Is.False); Assert.That(hashbag.Check(), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 6, 7, 21, 37, 53, 53, 69, 85 })); + Assert.That(hashbag.Remove(53), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 6, 7, 21, 37, 53, 69, 85 })); + Assert.That(hashbag.Remove(37), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 6, 7, 21, 53, 69, 85 })); + Assert.That(hashbag.Remove(85), Is.True); + Assert.That(hashbag, Is.EquivalentTo(new[] { 4, 4, 6, 7, 21, 53, 69 })); }); - Assert.That(IC.SetEq(hashbag, 4, 4, 6, 7, 21, 37, 53, 53, 69, 85), Is.True); - Assert.That(hashbag.Remove(53), Is.True); - Assert.That(IC.SetEq(hashbag, 4, 4, 6, 7, 21, 37, 53, 69, 85), Is.True); - Assert.That(hashbag.Remove(37), Is.True); - Assert.That(IC.SetEq(hashbag, 4, 4, 6, 7, 21, 53, 69, 85), Is.True); - Assert.That(hashbag.Remove(85), Is.True); - Assert.That(IC.SetEq(hashbag, 4, 4, 6, 7, 21, 53, 69), Is.True); } - [TearDown] public void Dispose() { @@ -453,7 +449,7 @@ public class FindPredicate public void Init() { Debug.UseDeterministicHashing = true; - list = new HashBag(TenEqualityComparer.Default); + list = new HashBag(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -486,7 +482,7 @@ public class UniqueItems private HashBag list; [SetUp] - public void Init() { list = new HashBag(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list = null; } @@ -496,14 +492,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 2, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 2), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -519,7 +515,7 @@ public class ArrayTest public void Init() { Debug.UseDeterministicHashing = true; - hashbag = new HashBag(); + hashbag = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -535,30 +531,10 @@ public void Dispose() hashbag = null; } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(hashbag.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(hashbag.ToArray(), Is.Empty); hashbag.Add(7); hashbag.Add(3); hashbag.Add(10); @@ -567,30 +543,29 @@ public void ToArray() int[] r = hashbag.ToArray(); Array.Sort(r); - Assert.That(aeq(r, 3, 3, 7, 10), Is.EqualTo("Alles klar")); + Assert.That(r, Is.EqualTo(new[] { 3, 3, 7, 10 })); } - [Test] public void CopyTo() { //Note: for small ints the itemequalityComparer is the identity! hashbag.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); hashbag.Add(6); hashbag.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); hashbag.Add(4); hashbag.Add(6); hashbag.Add(9); hashbag.CopyTo(a, 4); //TODO: make independent of interequalityComparer - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 6, 9, 4, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 6, 9, 4, 1008, 1009 })); hashbag.Clear(); hashbag.Add(7); hashbag.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 6, 9, 4, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 6, 9, 4, 1008, 7 })); } @@ -628,8 +603,8 @@ public class HashingEquals [SetUp] public void Init() { - h1 = new HashBag(); - h2 = new LinkedList(); + h1 = []; + h2 = []; } [TearDown] diff --git a/C5.Tests/Hashing/HashDictionaryTests.cs b/C5.Tests/Hashing/HashDictionaryTests.cs index f7cc833d..406ffe26 100644 --- a/C5.Tests/Hashing/HashDictionaryTests.cs +++ b/C5.Tests/Hashing/HashDictionaryTests.cs @@ -15,8 +15,8 @@ public class GenericTesters [Test] public void TestEvents() { - DictionaryIntToInt factory() { return new DictionaryIntToInt(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.DictionaryTester().Test(factory); + DictionaryIntToInt factory() { return new DictionaryIntToInt(TenEqualityComparer.Instance); } + new Templates.Events.DictionaryTester().Test(factory); } } @@ -68,27 +68,27 @@ public class HashDict [SetUp] public void Init() { - dict = new HashDictionary(); + dict = []; //dict = TreeDictionary.MakeNaturalO(); } [Test] public void NullEqualityComparerinConstructor1() { - Assert.Throws(() => new HashDictionary(null)); + Assert.Throws(() => new DictionaryIntToInt(null)); } [Test] public void NullEqualityComparerinConstructor2() { - Assert.Throws(() => new HashDictionary(5, 0.5, null)); + Assert.Throws(() => new DictionaryIntToInt(5, 0.5, null)); } [Test] public void Choose() { dict.Add("ER", "FOO"); - Assert.That(dict.Choose(), Is.EqualTo(new System.Collections.Generic.KeyValuePair("ER", "FOO"))); + Assert.That(dict.Choose(), Is.EqualTo(new SCG.KeyValuePair("ER", "FOO"))); } [Test] @@ -261,7 +261,7 @@ public void CombinedOps() [Test] public void DeepBucket() { - HashDictionary dict2 = new(); + DictionaryIntToInt dict2 = []; for (int i = 0; i < 5; i++) { diff --git a/C5.Tests/Hashing/HashTableTests.cs b/C5.Tests/Hashing/HashTableTests.cs index 4ad49246..c91f2784 100644 --- a/C5.Tests/Hashing/HashTableTests.cs +++ b/C5.Tests/Hashing/HashTableTests.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using System; +using System.Collections.Generic; using SCG = System.Collections.Generic; namespace C5.Tests.hashtable.set { @@ -12,8 +13,8 @@ public class GenericTesters [Test] public void TestEvents() { - HashSet factory() { return new HashSet(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.CollectionTester>().Test(factory); + HashSet factory() { return new HashSet(TenEqualityComparer.Instance); } + new Templates.Events.CollectionTester>().Test(factory); } } @@ -37,7 +38,7 @@ public class Multiops public void Init() { Debug.UseDeterministicHashing = true; - list = new HashSet(); + list = []; always = delegate { return true; }; never = delegate { return false; }; even = delegate (int i) { return i % 2 == 0; }; @@ -128,7 +129,7 @@ public class GetEnumerator [SetUp] - public void Init() { hashset = new HashSet(); } + public void Init() { hashset = []; } [Test] @@ -153,7 +154,7 @@ public void Normal() hashset.Add(18); hashset.Add(17); hashset.Add(33); - Assert.That(IC.SetEq(hashset, 1, 5, 8, 10, 16, 17, 18, 33), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 1, 5, 8, 10, 16, 17, 18, 33 })); } [Test] @@ -236,7 +237,7 @@ public class CollectionOrSink [SetUp] - public void Init() { hashset = new HashSet(); } + public void Init() { hashset = []; } [Test] public void Choose() @@ -281,26 +282,24 @@ public void CountEtAl() }); } - [Test] public void AddAll() { hashset.Add(3); hashset.Add(4); hashset.Add(5); - HashSet hashset2 = new(); + HashSet hashset2 = []; hashset2.AddAll(hashset); - Assert.That(IC.SetEq(hashset2, 3, 4, 5), Is.True); + Assert.That(hashset2, Is.EquivalentTo(new[] { 3, 4, 5 })); hashset.Add(9); hashset.AddAll(hashset2); Assert.Multiple(() => { - Assert.That(IC.SetEq(hashset2, 3, 4, 5), Is.True); - Assert.That(IC.SetEq(hashset, 3, 4, 5, 9), Is.True); + Assert.That(hashset2, Is.EquivalentTo(new[] { 3, 4, 5 })); + Assert.That(hashset, Is.EquivalentTo(new[] { 3, 4, 5, 9 })); }); } - [TearDown] public void Dispose() { hashset = null; } } @@ -315,7 +314,7 @@ public class FindPredicate public void Init() { Debug.UseDeterministicHashing = true; - list = new HashSet(TenEqualityComparer.Default); + list = new HashSet(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -347,7 +346,7 @@ public class UniqueItems private HashSet list; [SetUp] - public void Init() { list = new HashSet(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list = null; } @@ -357,14 +356,15 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 1, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 1), SCG.KeyValuePair.Create(9, 1) })); + }); } } @@ -380,7 +380,7 @@ public class ArrayTest public void Init() { Debug.UseDeterministicHashing = true; - hashset = new HashSet(); + hashset = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -396,30 +396,10 @@ public void Dispose() hashset = null; } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(hashset.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(hashset.ToArray(), Is.Empty); hashset.Add(7); hashset.Add(3); hashset.Add(10); @@ -427,7 +407,7 @@ public void ToArray() int[] r = hashset.ToArray(); Array.Sort(r); - Assert.That(aeq(r, 3, 7, 10), Is.EqualTo("Alles klar")); + Assert.That(r, Is.EqualTo(new[] { 3, 7, 10 })); } @@ -436,23 +416,22 @@ public void CopyTo() { //Note: for small ints the itemequalityComparer is the identity! hashset.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); hashset.Add(6); hashset.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); hashset.Add(4); hashset.Add(9); hashset.CopyTo(a, 4); //TODO: make test independent on onterequalityComparer - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 9, 4, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 9, 4, 1007, 1008, 1009 })); hashset.Clear(); hashset.Add(7); hashset.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 9, 4, 1007, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 9, 4, 1007, 1008, 7 })); } - [Test] public void CopyToBad() { @@ -489,7 +468,7 @@ public class Collision [SetUp] public void Init() { - hashset = new HashSet(); + hashset = []; } @@ -524,7 +503,7 @@ public class Searching public void Init() { Debug.UseDeterministicHashing = true; - hashset = new HashSet(); + hashset = []; } @@ -636,7 +615,7 @@ public void Many() a[i] = 3 * i + 1; } - Assert.That(IC.SetEq(hashset, a), Is.True); + Assert.That(hashset, Is.EquivalentTo(a)); } @@ -678,14 +657,14 @@ public void RemoveAllCopies() Assert.That(hashset.ContainsCount(7), Is.EqualTo(1)); hashset.Add(5); hashset.Add(8); hashset.Add(5); hashset.RemoveAllCopies(8); - Assert.That(IC.Eq(hashset, 7, 5), Is.True); + Assert.That(hashset, Is.EqualTo(new[] { 7, 5 })); } [Test] public void ContainsAll() { - HashSet list2 = new(); + HashSet list2 = []; Assert.That(hashset.ContainsAll(list2), Is.True); list2.Add(4); @@ -704,17 +683,17 @@ public void ContainsAll() [Test] public void RetainAll() { - HashSet list2 = new(); + HashSet list2 = []; hashset.Add(4); hashset.Add(5); hashset.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); hashset.RetainAll(list2); - Assert.That(IC.SetEq(hashset, 4, 5), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 4, 5 })); hashset.Add(6); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); hashset.RetainAll(list2); - Assert.That(IC.SetEq(hashset), Is.True); + Assert.That(hashset, Is.Empty); } //Bug in RetainAll reported by Chris Fesler @@ -732,10 +711,10 @@ public void RetainAll2() _largeArrayTwo[i] = "" + (i + LARGE_ARRAY_MID); } - HashSet setOne = new(); + HashSet setOne = []; setOne.AddAll(_largeArrayOne); - HashSet setTwo = new(); + HashSet setTwo = []; setTwo.AddAll(_largeArrayTwo); setOne.RetainAll(setTwo); @@ -751,21 +730,21 @@ public void RetainAll2() [Test] public void RemoveAll() { - HashSet list2 = new(); + HashSet list2 = []; hashset.Add(4); hashset.Add(5); hashset.Add(6); list2.Add(5); list2.Add(7); list2.Add(4); hashset.RemoveAll(list2); - Assert.That(IC.Eq(hashset, 6), Is.True); + Assert.That(hashset, Is.EqualTo(new[] { 6 })); hashset.Add(5); hashset.Add(4); list2.Clear(); list2.Add(6); list2.Add(5); hashset.RemoveAll(list2); - Assert.That(IC.Eq(hashset, 4), Is.True); + Assert.That(hashset, Is.EqualTo(new[] { 4 })); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); hashset.RemoveAll(list2); - Assert.That(IC.Eq(hashset, 4), Is.True); + Assert.That(hashset, Is.EqualTo(new[] { 4 })); } @@ -777,35 +756,37 @@ public void Remove() { Assert.That(hashset.Remove(2), Is.False); Assert.That(hashset.Remove(4), Is.True); - Assert.That(IC.SetEq(hashset, 5, 6), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 5, 6 })); }); hashset.Add(7); hashset.Add(21); hashset.Add(37); hashset.Add(53); hashset.Add(69); hashset.Add(85); Assert.Multiple(() => { Assert.That(hashset.Remove(5), Is.True); - Assert.That(IC.SetEq(hashset, 6, 7, 21, 37, 53, 69, 85), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 6, 7, 21, 37, 53, 69, 85 })); Assert.That(hashset.Remove(165), Is.False); }); - Assert.That(IC.SetEq(hashset, 6, 7, 21, 37, 53, 69, 85), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 6, 7, 21, 37, 53, 69, 85 })); Assert.That(hashset.Remove(53), Is.True); - Assert.That(IC.SetEq(hashset, 6, 7, 21, 37, 69, 85), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 6, 7, 21, 37, 69, 85 })); Assert.That(hashset.Remove(37), Is.True); - Assert.That(IC.SetEq(hashset, 6, 7, 21, 69, 85), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 6, 7, 21, 69, 85 })); Assert.That(hashset.Remove(85), Is.True); - Assert.That(IC.SetEq(hashset, 6, 7, 21, 69), Is.True); + Assert.That(hashset, Is.EquivalentTo(new[] { 6, 7, 21, 69 })); } - [Test] public void Clear() { hashset.Add(7); hashset.Add(7); hashset.Clear(); - Assert.That(hashset.IsEmpty, Is.True); + Assert.Multiple(() => + { + Assert.That(hashset.IsEmpty, Is.True); + Assert.That(hashset, Is.Empty); + }); } - [TearDown] public void Dispose() { @@ -817,16 +798,16 @@ public void Dispose() [TestFixture] public class Combined { - private ICollection> lst; + private ICollection> lst; [SetUp] public void Init() { - lst = new HashSet>(new KeyValuePairEqualityComparer()); + lst = new HashSet>(new KeyValuePairEqualityComparer()); for (int i = 0; i < 10; i++) { - lst.Add(new System.Collections.Generic.KeyValuePair(i, i + 30)); + lst.Add(new SCG.KeyValuePair(i, i + 30)); } } @@ -838,7 +819,7 @@ public void Init() [Test] public void Find() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -846,7 +827,7 @@ public void Find() Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Find(ref p), Is.False); } @@ -938,7 +919,7 @@ public void UpdateOrAdd2() [Test] public void RemoveWithReturn() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { //System.Collections.Generic.KeyValuePair q = new System.Collections.Generic.KeyValuePair(); @@ -947,7 +928,7 @@ public void RemoveWithReturn() Assert.That(p.Key, Is.EqualTo(3)); Assert.That(p.Value, Is.EqualTo(33)); }); - p = new System.Collections.Generic.KeyValuePair(13, 78); + p = new SCG.KeyValuePair(13, 78); Assert.That(lst.Remove(p, out _), Is.False); } } @@ -1156,15 +1137,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new HashSet(); - dat = new HashSet(); - dut = new HashSet(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -1214,18 +1195,18 @@ public class MultiLevelUnOrderedOfOrdered [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); - dot = new LinkedList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new HashSet>(); - Dat = new HashSet>(); - Dut = new HashSet>(); - Dot = new HashSet>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } diff --git a/C5.Tests/Heaps/HeapTests.cs b/C5.Tests/Heaps/HeapTests.cs index 0cb3810e..9862f4cf 100644 --- a/C5.Tests/Heaps/HeapTests.cs +++ b/C5.Tests/Heaps/HeapTests.cs @@ -12,8 +12,8 @@ public class GenericTesters [Test] public void TestEvents() { - IntervalHeap factory() { return new IntervalHeap(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.PriorityQueueTester>().Test(factory); + IntervalHeap factory() { return new IntervalHeap(TenEqualityComparer.Instance); } + new Templates.Events.PriorityQueueTester>().Test(factory); } } @@ -28,7 +28,7 @@ public class Events public void Init() { queue = new IntervalHeap(); - events = new ArrayList>(); + events = []; } @@ -133,7 +133,7 @@ public class Formatting private IntervalHeap coll; private IFormatProvider rad16; [SetUp] - public void Init() { coll = new IntervalHeap(); rad16 = new RadixFormatProvider(16); } + public void Init() { coll = []; rad16 = new RadixFormatProvider(16); } [TearDown] public void Dispose() { coll = null; rad16 = null; } [Test] @@ -642,7 +642,7 @@ public void AddAll() int[] a = new int[length]; Random ran = new(6754); - LinkedList lst = new(); + LinkedList lst = []; for (int i = 0; i < length; i++) { lst.Add(a[i] = ran.Next()); diff --git a/C5.Tests/InterfacesTest.cs b/C5.Tests/InterfacesTest.cs index 91abba2a..c96d25c7 100644 --- a/C5.Tests/InterfacesTest.cs +++ b/C5.Tests/InterfacesTest.cs @@ -244,7 +244,7 @@ public void TryGuardedListAsSCIList1() { B b1_ = new(), b2_ = new(); C c1_ = new(), c2_ = new(); - ArrayList mylist = new(); + ArrayList mylist = []; mylist.AddAll([b1_, b2_, c1_]); System.Collections.IList list = new GuardedList(mylist); object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_; @@ -305,7 +305,7 @@ public void TryViewOfGuardedListAsSCIList1() { B b1_ = new(), b2_ = new(); C c1_ = new(), c2_ = new(); - ArrayList mylist = new(); + ArrayList mylist = []; mylist.AddAll([new B(), b1_, b2_, c1_, new B()]); System.Collections.IList list = new GuardedList(mylist).View(1, 3); object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_; @@ -447,7 +447,7 @@ public void TryHashedLinkedListViewAsSCIList() [Test] public void TryGuardedViewAsSCIList() { - ArrayList mylist = new(); + ArrayList mylist = []; TryListViewAsSCIList2(new GuardedList(mylist)); } } @@ -463,7 +463,7 @@ public void TryDictionary(IDictionary dict) Assert.That(dict.IsEmpty, Is.True); Assert.That(dict.IsReadOnly, Is.False); }); - System.Collections.Generic.KeyValuePair[] arr = []; + SCG.KeyValuePair[] arr = []; dict.CopyTo(arr, 0); dict["R"] = "A"; dict["S"] = "B"; diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index 7fffb4cb..11696931 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -14,8 +14,8 @@ public class GenericTesters [Test] public void TestEvents() { - HashedLinkedList factory() { return new HashedLinkedList(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.ListTester>().Test(factory); + HashedLinkedList factory() { return new HashedLinkedList(TenEqualityComparer.Instance); } + new Templates.Events.ListTester>().Test(factory); } [Test] @@ -45,7 +45,7 @@ public class Multiops [SetUp] public void Init() { - list = new HashedLinkedList(); + list = []; always = delegate { return true; }; never = delegate { return false; }; even = delegate (int i) { return i % 2 == 0; }; @@ -132,7 +132,7 @@ public class GetEnumerator [SetUp] - public void Init() { list = new HashedLinkedList(); } + public void Init() { list = []; } [Test] @@ -238,7 +238,7 @@ public class CollectionOrSink [SetUp] - public void Init() { list = new HashedLinkedList(); } + public void Init() { list = []; } [Test] public void NullEqualityComparerinConstructor1() @@ -290,15 +290,15 @@ public void AddAll() { list.Add(3); list.Add(4); list.Add(5); - HashedLinkedList list2 = new(); + HashedLinkedList list2 = []; list2.AddAll(list); - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); list.AddAll(list2); Assert.Multiple(() => { - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); - Assert.That(IC.Eq(list, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(list, Is.EqualTo(new[] { 3, 4, 5 })); }); } @@ -316,7 +316,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new HashedLinkedList(TenEqualityComparer.Default); + list = new HashedLinkedList(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -378,7 +378,7 @@ public class UniqueItems private HashedLinkedList list; [SetUp] - public void Init() { list = new HashedLinkedList(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -388,14 +388,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 1, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 1), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -410,7 +410,7 @@ public class ArrayTest [SetUp] public void Init() { - list = new HashedLinkedList(); + list = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -425,53 +425,32 @@ public void Dispose() list.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(list.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.Empty); list.Add(7); list.Add(8); - Assert.That(aeq(list.ToArray(), 7, 8), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.EqualTo(new[] { 7, 8 })); } - [Test] public void CopyTo() { list.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(6); list.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(4); list.Add(5); list.Add(9); list.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 1009 })); list.Clear(); list.Add(7); list.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 5, 9, 1008, 7 })); } [Test] @@ -521,7 +500,7 @@ public class Searching [SetUp] - public void Init() { list = new HashedLinkedList(); } + public void Init() { list = []; } [Test] @@ -603,7 +582,7 @@ public void RemoveAllCopies() }); list.Add(5); list.Add(8); list.RemoveAllCopies(8); - Assert.That(IC.Eq(list, 7, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7, 5 })); } @@ -617,7 +596,7 @@ public void FindAll() Assert.Multiple(() => { Assert.That(((HashedLinkedList)list.FindAll(f)).Check(), Is.True); - Assert.That(IC.Eq(list.FindAll(f), 8, 10), Is.True); + Assert.That(list.FindAll(f), Is.EqualTo(new[] { 8, 10 })); }); } @@ -625,7 +604,7 @@ public void FindAll() [Test] public void ContainsAll() { - HashedLinkedList list2 = new(); + HashedLinkedList list2 = []; Assert.That(list.ContainsAll(list2), Is.True); list2.Add(4); @@ -640,7 +619,7 @@ public void ContainsAll() [Test] public void RetainAll() { - HashedLinkedList list2 = new(); + HashedLinkedList list2 = []; list.Add(4); list.Add(5); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); @@ -648,7 +627,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -657,20 +636,20 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 6 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RetainAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list), Is.True); + Assert.That(list, Is.Empty); } [Test] public void RemoveAll() { - HashedLinkedList list2 = new(); + HashedLinkedList list2 = []; list.Add(4); list.Add(5); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); @@ -678,7 +657,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 6 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -687,13 +666,13 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RemoveAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4 })); } @@ -708,16 +687,16 @@ public void Remove() Assert.That(list.Remove(4), Is.True); }); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(5)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7 })); }); } @@ -750,7 +729,7 @@ public class Searching [SetUp] public void Init() { - dit = new HashedLinkedList(); + dit = []; } @@ -793,7 +772,7 @@ public class Removing [SetUp] public void Init() { - dit = new HashedLinkedList(); + dit = []; } [Test] @@ -803,15 +782,15 @@ public void RemoveAt() Assert.Multiple(() => { Assert.That(dit.RemoveAt(1), Is.EqualTo(7)); - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 5, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 5, 9, 1, 2 })); Assert.That(dit.RemoveAt(0), Is.EqualTo(5)); }); - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1, 2 })); Assert.That(dit.RemoveAt(2), Is.EqualTo(2)); - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1 })); } @@ -843,39 +822,39 @@ public void RemoveInterval() dit.RemoveInterval(3, 0); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 40, 50, 60 })); }); dit.RemoveInterval(3, 1); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 50, 60 })); }); dit.RemoveInterval(1, 3); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 60 })); }); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.Empty); }); dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40, 50, 60 })); }); dit.RemoveInterval(2, 2); Assert.Multiple(() => { - Assert.That(((HashedLinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40 })); }); } @@ -897,7 +876,7 @@ public class Searching [SetUp] - public void Init() { lst = new HashedLinkedList(); } + public void Init() { lst = []; } [TearDown] @@ -948,7 +927,7 @@ public void This() Assert.That(lst.First, Is.EqualTo(56)); lst.Add(7); lst.Add(77); lst.Add(777); lst.Add(7777); lst[0] = 45; lst[2] = 78; lst[4] = 101; - Assert.That(IC.Eq(lst, 45, 7, 78, 777, 101), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 45, 7, 78, 777, 101 })); } [Test] @@ -1202,22 +1181,22 @@ public void Dispose() public void Insert() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 4); - Assert.That(IC.Eq(lst, 7, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5 })); lst.Insert(3, 2); - Assert.That(IC.Eq(lst, 7, 4, 5, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5, 2 })); } [Test] public void InsertDuplicate() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); Assert.Throws(() => lst.Insert(1, 5)); } @@ -1226,9 +1205,9 @@ public void InsertDuplicate() public void InsertAllDuplicate1() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); try { lst.InsertAll(1, [1, 2, 3, 4]); @@ -1240,7 +1219,7 @@ public void InsertAllDuplicate1() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 1, 2, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 1, 2, 3 })); }); } @@ -1248,9 +1227,9 @@ public void InsertAllDuplicate1() public void InsertAllDuplicate2() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); try { lst.InsertAll(1, [5, 6, 5, 8]); @@ -1262,7 +1241,7 @@ public void InsertAllDuplicate2() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 5, 6, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 6, 3 })); }); } @@ -1317,7 +1296,7 @@ public void InsertFirstLast() lst.InsertLast(25); lst.InsertFirst(34); lst.InsertLast(55); - Assert.That(IC.Eq(lst, 34, 24, 14, 4, 5, 15, 25, 55), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 34, 24, 14, 4, 5, 15, 25, 55 })); } @@ -1332,19 +1311,19 @@ public void InsertFirst() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 3, 4, 5 })); }); lst.ViewOf(3).InsertFirst(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 4, 5 })); }); lst.ViewOf(5).InsertFirst(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 4, 9, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 4, 9, 5 })); }); } @@ -1370,19 +1349,19 @@ public void InsertAfter() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 7, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 7, 3, 4, 5 })); }); lst.LastViewOf(1).InsertLast(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 7, 3, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 7, 3, 4, 5 })); }); lst.LastViewOf(5).InsertLast(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 7, 3, 4, 5, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 7, 3, 4, 5, 9 })); }); } @@ -1409,21 +1388,21 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4 })); }); lst.RemoveAll(lst2); lst.InsertAll(4, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 3, 4, 7, 8, 9 })); }); lst.RemoveAll(lst2); lst.InsertAll(2, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 7, 8, 9, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 7, 8, 9, 3, 4 })); }); } @@ -1561,31 +1540,31 @@ public void Reverse() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(0, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 0).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); lst.View(5, 1).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); } @@ -1624,14 +1603,14 @@ public void Dispose() public void Sort() { lst.Add(5); lst.Add(6); lst.Add(55); lst.Add(7); lst.Add(3); - Assert.That(lst.IsSorted(new IC()), Is.False); - lst.Sort(new IC()); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.False); + lst.Sort(new IntegerComparer()); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True, "Check "); Assert.That(lst.IsSorted(), Is.True); - Assert.That(lst.IsSorted(new IC()), Is.True); - Assert.That(IC.Eq(lst, 3, 5, 6, 7, 55), Is.True); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } } @@ -1643,7 +1622,7 @@ public class ShuffleTests [SetUp] - public void Init() { lst = new HashedLinkedList(); } + public void Init() { lst = []; } [TearDown] @@ -1659,8 +1638,8 @@ public void Shuffle() lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); - Assert.That(IC.Eq(lst2, 3, 5, 6, 7), Is.True, "Contents " + i); + Sorting.IntroSort(lst2); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 6, 7 }), "Contents " + i); } } } @@ -1672,7 +1651,7 @@ public class AddingThenRemoving public void AddingThenRemovingTest1() { // bug20070911: - HashedLinkedList test = new(); + HashedLinkedList test = []; for (int i = 0; i < 33; i++) { test.Add(i); @@ -1685,7 +1664,7 @@ public void AddingThenRemovingTest1() Assert.That(test.IsEmpty, Is.True); for (int count = 0; count < 520; count++) { - HashedLinkedList hll = new(); + HashedLinkedList hll = []; for (int i = 1; i <= count; i++) { hll.Add(i); @@ -1703,7 +1682,7 @@ public void AddingThenRemovingTest1() public void AddingThenRemovingTest2() { // bug20070911: - HashedLinkedList test = new(); + HashedLinkedList test = []; for (int i = 0; i < 33; i++) { test.Add(i); @@ -1716,7 +1695,7 @@ public void AddingThenRemovingTest2() Assert.That(test.IsEmpty, Is.True); for (int count = 0; count < 520; count++) { - HashedLinkedList hll = new(); + HashedLinkedList hll = []; for (int i = 1; i <= count; i++) { hll.Add(i); @@ -1739,19 +1718,15 @@ public class Range { private IList lst; - [SetUp] public void Init() { lst = new HashedLinkedList(); } - [TearDown] public void Dispose() { lst.Dispose(); } - [Test] public void GetRange() { - //Assert.IsTrue(IC.eq(lst[0, 0))); for (int i = 0; i < 10; i++) { lst.Add(i); @@ -1759,14 +1734,13 @@ public void GetRange() Assert.Multiple(() => { - Assert.That(IC.Eq(lst[0, 3], 0, 1, 2), Is.True); - Assert.That(IC.Eq(lst[3, 3], 3, 4, 5), Is.True); - Assert.That(IC.Eq(lst[6, 3], 6, 7, 8), Is.True); - Assert.That(IC.Eq(lst[6, 4], 6, 7, 8, 9), Is.True); + Assert.That(lst[0, 3], Is.EqualTo(new[] { 0, 1, 2 })); + Assert.That(lst[3, 3], Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(lst[6, 3], Is.EqualTo(new[] { 6, 7, 8 })); + Assert.That(lst[6, 4], Is.EqualTo(new[] { 6, 7, 8, 9 })); }); } - [Test] public void Backwards() { @@ -1777,14 +1751,13 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[0, 3].Backwards(), 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[3, 3].Backwards(), 5, 4, 3), Is.True); - Assert.That(IC.Eq(lst[6, 4].Backwards(), 9, 8, 7, 6), Is.True); + Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); + Assert.That(lst[0, 3].Backwards(), Is.EqualTo(new[] { 2, 1, 0 })); + Assert.That(lst[3, 3].Backwards(), Is.EqualTo(new[] { 5, 4, 3 })); + Assert.That(lst[6, 4].Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6 })); }); } - [Test] public void DirectionAndCount() { @@ -1840,7 +1813,7 @@ public class Simple [SetUp] public void Init() { - list = new HashedLinkedList() { 0, 1, 2, 3 }; + list = [0, 1, 2, 3]; view = (HashedLinkedList)list.View(1, 2); } @@ -1876,8 +1849,8 @@ public void InsertPointer() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8), Is.True); - Assert.That(IC.Eq(view, 11, 1, 9, 7, 2, 10), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 11, 1, 9, 7, 2, 10, 3, 8 })); + Assert.That(view, Is.EqualTo(new[] { 11, 1, 9, 7, 2, 10 })); }); } @@ -1938,21 +1911,21 @@ public void ViewOf() Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.ViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.LastViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); } @@ -1975,10 +1948,10 @@ public void BadViewOf() [Test] public void ArrayStuff() { - Assert.That(IC.Eq(view.ToArray(), 1, 2), Is.True); + Assert.That(view.ToArray(), Is.EqualTo(new[] { 1, 2 })); int[] extarray = new int[5]; view.CopyTo(extarray, 2); - Assert.That(IC.Eq(extarray, 0, 0, 1, 2, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 0, 1, 2, 0 })); } [Test] @@ -1987,15 +1960,15 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2 })); }); view.InsertFirst(10); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 10, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 10, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 10, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 10, 1, 2 })); }); view.Clear(); Assert.Multiple(() => @@ -2005,8 +1978,8 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); - Assert.That(IC.Eq(view), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.False); @@ -2014,46 +1987,46 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 3), Is.True); - Assert.That(IC.Eq(view, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8 })); }); view.Add(12); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12 })); }); view./*ViewOf(12).*/InsertLast(15); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12, 15 })); }); view.ViewOf(12).InsertFirst(18); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15 })); }); - HashedLinkedList lst2 = new() { 90, 92 }; + HashedLinkedList lst2 = [90, 92]; view.AddAll(lst2); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92 })); }); view.InsertLast(66); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92, 66), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 66, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92, 66 })); }); } @@ -2063,7 +2036,7 @@ public void Bxxx() { Assert.Multiple(() => { - Assert.That(IC.Eq(view.Backwards(), 2, 1), Is.True); + Assert.That(view.Backwards(), Is.EqualTo(new[] { 2, 1 })); Assert.That(view.Underlying, Is.SameAs(list)); Assert.That(list.Underlying, Is.Null); Assert.That(view.Direction, Is.EqualTo(Direction.Forwards)); @@ -2083,7 +2056,7 @@ public void Contains() Assert.That(view.Contains(0), Is.False); }); - HashedLinkedList lst2 = new() { 2 }; + HashedLinkedList lst2 = [2]; Assert.That(view.ContainsAll(lst2), Is.True); lst2.Add(3); Assert.Multiple(() => @@ -2119,11 +2092,11 @@ public void FIFO() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 23, 24, 25 })); Assert.That(view.Remove(), Is.EqualTo(1)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24, 25 })); view.FIFO = false; Assert.Multiple(() => { @@ -2131,7 +2104,7 @@ public void FIFO() Assert.That(view.Remove(), Is.EqualTo(25)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24 })); } @@ -2156,7 +2129,7 @@ public void MapEtc() Assert.Multiple(() => { Assert.That(list2.Check(), Is.True); - Assert.That(IC.Eq(list2, 1, 5, 9), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 1, 5, 9 })); }); } @@ -2208,7 +2181,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 2, 36 })); }); IList list2 = new HashedLinkedList() { 40, 41 }; @@ -2216,7 +2189,7 @@ public void Insert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 40, 41, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 40, 41, 2, 36 })); }); } @@ -2225,13 +2198,13 @@ public void Insert() public void Sort() { view.Add(45); view.Add(47); view.Add(46); view.Add(48); - Assert.That(view.IsSorted(new IC()), Is.False); - view.Sort(new IC()); + Assert.That(view.IsSorted(new IntegerComparer()), Is.False); + view.Sort(new IntegerComparer()); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 45, 46, 47, 48, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2, 45, 46, 47, 48), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 45, 46, 47, 48, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 45, 46, 47, 48 })); }); } @@ -2242,41 +2215,41 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); Assert.That(view.Remove(1), Is.False); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); Assert.That(view.Remove(0), Is.False); }); check(); - Assert.That(IC.Eq(view, 2, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5), Is.True); - Assert.That(IC.Eq(list, 0, 2, 5, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5 })); + Assert.That(list, Is.EqualTo(new[] { 0, 2, 5, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 2, 5, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1 })); - HashedLinkedList l2 = new() { 1, 2, 2, 3, 1 }; + HashedLinkedList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); - Assert.That(IC.Eq(view, 5), Is.True); + Assert.That(view, Is.EqualTo(new[] { 5 })); view.RetainAll(l2); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(2); view.Add(4); view.Add(5); Assert.Multiple(() => { @@ -2285,7 +2258,7 @@ public void Remove() }); Assert.That(view.RemoveAt(0), Is.EqualTo(4)); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); view.Add(6); view.Add(78); Assert.Multiple(() => { @@ -2295,7 +2268,7 @@ public void Remove() view.Add(2); view.Add(5); view.Add(3); view.Add(1); view.RemoveInterval(1, 2); check(); - Assert.That(IC.Eq(view, 6, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 6, 1 })); } @@ -2310,12 +2283,12 @@ public void Reverse() view.View(3, 4).Reverse(); check(); - Assert.That(IC.Eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19), Is.True); + Assert.That(view, Is.EqualTo(new[] { 10, 11, 12, 16, 15, 14, 13, 17, 18, 19 })); view.Reverse(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10), Is.True); - Assert.That(IC.Eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 19, 18, 17, 13, 14, 15, 16, 12, 11, 10 })); + Assert.That(list, Is.EqualTo(new[] { 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3 })); }); } @@ -2325,21 +2298,21 @@ public void Slide() { view.Slide(1); check(); - Assert.That(IC.Eq(view, 2, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 3 })); view.Slide(-2); check(); - Assert.That(IC.Eq(view, 0, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1 })); view.Slide(0, 3); check(); - Assert.That(IC.Eq(view, 0, 1, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1, 2 })); view.Slide(2, 1); check(); - Assert.That(IC.Eq(view, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2 })); view.Slide(-1, 0); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(28); - Assert.That(IC.Eq(list, 0, 28, 1, 2, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } [Test] public void Iterate() @@ -2375,7 +2348,7 @@ public void Iterate() } //foreach (int cell in list) Console.Write(" " + cell); //Assert.IsTrue(list.Check()); - Assert.That(IC.Eq(list, 2, 4, 8, 668, 13, 6, 1, 667, 10, 666, 11), Is.True); + Assert.That(list, Is.EqualTo(new[] { 2, 4, 8, 668, 13, 6, 1, 667, 10, 666, 11 })); } @@ -2922,9 +2895,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3009,7 +2982,7 @@ public void WrongOrder() Assert.That(dut.SequencedEquals(dit), Is.True); }); dit.Add(7); - ((HashedLinkedList)dut).InsertFirst(7); + dut.InsertFirst(7); Assert.Multiple(() => { Assert.That(dit.SequencedEquals(dut), Is.False); @@ -3049,9 +3022,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3179,15 +3152,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new HashedLinkedList>(); - Dat = new HashedLinkedList>(); - Dut = new HashedLinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3240,15 +3213,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new HashedLinkedList>(); - Dat = new HashedLinkedList>(); - Dut = new HashedLinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3302,18 +3275,18 @@ public class MultiLevelUnOrderedOfOrdered [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); - dot = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new HashedLinkedList>(); - Dat = new HashedLinkedList>(); - Dut = new HashedLinkedList>(); - Dot = new HashedLinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3372,18 +3345,18 @@ public class MultiLevelOrderedOfOrdered [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); - dot = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); //{2,1} dat.Add(1); dat.Add(2); //{1,2} dut.Add(3); //{3} dot.Add(2); dot.Add(1); //{2,1} - Dit = new HashedLinkedList>(); - Dat = new HashedLinkedList>(); - Dut = new HashedLinkedList>(); - Dot = new HashedLinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index c4f36b45..d95e3c25 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -16,10 +16,10 @@ public class GenericTesters [Test] public void TestEvents() { - LinkedList factory() { return new LinkedList(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.ListTester>().Test(factory); - new C5.Tests.Templates.Events.QueueTester>().Test(factory); - new C5.Tests.Templates.Events.StackTester>().Test(factory); + LinkedList factory() { return new LinkedList(TenEqualityComparer.Instance); } + new Templates.Events.ListTester>().Test(factory); + new Templates.Events.QueueTester>().Test(factory); + new Templates.Events.StackTester>().Test(factory); } [Test] @@ -48,7 +48,7 @@ public class Multiops [SetUp] public void Init() { - list = new LinkedList(); + list = []; always = delegate { return true; }; never = delegate { return false; }; even = delegate (int i) { return i % 2 == 0; }; @@ -135,7 +135,7 @@ public class GetEnumerator [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] @@ -247,7 +247,7 @@ public class CollectionOrSink [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] public void NullEqualityComparerinConstructor1() @@ -293,15 +293,15 @@ public void AddAll() { list.Add(3); list.Add(4); list.Add(5); - LinkedList list2 = new(); + LinkedList list2 = []; list2.AddAll(list); - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); list.AddAll(list2); Assert.Multiple(() => { - Assert.That(IC.Eq(list2, 3, 4, 5), Is.True); - Assert.That(IC.Eq(list, 3, 4, 5, 3, 4, 5), Is.True); + Assert.That(list2, Is.EqualTo(new[] { 3, 4, 5 })); + Assert.That(list, Is.EqualTo(new[] { 3, 4, 5, 3, 4, 5 })); }); } @@ -319,7 +319,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new LinkedList(TenEqualityComparer.Default); + list = new LinkedList(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -381,7 +381,7 @@ public class UniqueItems private LinkedList list; [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -391,14 +391,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 2, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 2), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -413,7 +413,7 @@ public class ArrayTest [SetUp] public void Init() { - list = new LinkedList(); + list = []; a = new int[10]; for (int i = 0; i < 10; i++) { @@ -425,53 +425,32 @@ public void Init() [TearDown] public void Dispose() { list.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(list.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.Empty); list.Add(7); list.Add(7); - Assert.That(aeq(list.ToArray(), 7, 7), Is.EqualTo("Alles klar")); + Assert.That(list.ToArray(), Is.EqualTo(new[] { 7, 7 })); } - [Test] public void CopyTo() { list.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(6); list.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); list.Add(4); list.Add(4); list.Add(9); list.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009 })); list.Clear(); list.Add(7); list.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7 })); } [Test] @@ -504,7 +483,7 @@ public class Sync [SetUp] public void Init() { - list = new LinkedList(); + list = []; } [TearDown] @@ -526,7 +505,7 @@ public class Searching private LinkedList list; [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] public void Contains() @@ -595,7 +574,7 @@ public void RemoveAllCopies() Assert.That(list.ContainsCount(7), Is.EqualTo(1)); list.Add(5); list.Add(8); list.Add(5); list.RemoveAllCopies(8); - Assert.That(IC.Eq(list, 7, 5, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 7, 5, 5 })); } @@ -609,7 +588,7 @@ public void FindAll() Assert.Multiple(() => { Assert.That(((LinkedList)list.FindAll(f)).Check(), Is.True); - Assert.That(IC.Eq(list.FindAll(f), 8, 10, 8), Is.True); + Assert.That(list.FindAll(f), Is.EqualTo(new[] { 8, 10, 8 })); }); } @@ -617,7 +596,7 @@ public void FindAll() [Test] public void ContainsAll() { - LinkedList list2 = new(); + LinkedList list2 = []; Assert.That(list.ContainsAll(list2), Is.True); list2.Add(4); @@ -636,7 +615,7 @@ public void ContainsAll() [Test] public void RetainAll() { - LinkedList list2 = new(); + LinkedList list2 = []; list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4); @@ -644,7 +623,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -653,20 +632,20 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 5, 6 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RetainAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list), Is.True); + Assert.That(list, Is.Empty); } [Test] public void RemoveAll() { - LinkedList list2 = new(); + LinkedList list2 = []; list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6); list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4); @@ -674,7 +653,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 6 })); }); list.Add(5); list.Add(4); list.Add(6); list2.Clear(); @@ -683,13 +662,13 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4 })); }); list2.Clear(); list2.Add(7); list2.Add(8); list2.Add(9); list.RemoveAll(list2); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4 })); } @@ -706,16 +685,16 @@ public void Remove() Assert.That(list.Remove(4), Is.True); }); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 4, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 4, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 4), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 4 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(4)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 5, 4, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 5, 4, 7 })); }); list.FIFO = false; @@ -725,16 +704,16 @@ public void Remove() Assert.That(list.Check(), Is.True); Assert.That(list.Remove(4), Is.True); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5, 6), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5, 6 })); Assert.That(list.RemoveLast(), Is.EqualTo(6)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 4, 5), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 4, 5 })); list.Add(7); Assert.Multiple(() => { Assert.That(list.RemoveFirst(), Is.EqualTo(4)); Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 4, 5, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 4, 5, 7 })); }); } @@ -767,7 +746,7 @@ public class Searching [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; } @@ -812,7 +791,7 @@ public class Removing [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; } @@ -823,15 +802,15 @@ public void RemoveAt() Assert.Multiple(() => { Assert.That(dit.RemoveAt(1), Is.EqualTo(7)); - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 5, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 5, 9, 1, 2 })); Assert.That(dit.RemoveAt(0), Is.EqualTo(5)); }); - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1, 2), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1, 2 })); Assert.That(dit.RemoveAt(2), Is.EqualTo(2)); - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 9, 1), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 9, 1 })); } @@ -863,39 +842,39 @@ public void RemoveInterval() dit.RemoveInterval(3, 0); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 40, 50, 60 })); }); dit.RemoveInterval(3, 1); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 20, 30, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 20, 30, 50, 60 })); }); dit.RemoveInterval(1, 3); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 10, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 10, 60 })); }); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.Empty); }); dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60); dit.RemoveInterval(0, 2); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40, 50, 60), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40, 50, 60 })); }); dit.RemoveInterval(2, 2); Assert.Multiple(() => { - Assert.That(((LinkedList)dit).Check(), Is.True); - Assert.That(IC.Eq(dit, 30, 40), Is.True); + Assert.That(dit.Check(), Is.True); + Assert.That(dit, Is.EqualTo(new[] { 30, 40 })); }); } @@ -967,7 +946,7 @@ public void This() Assert.That(lst.First, Is.EqualTo(56)); lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7); lst[0] = 45; lst[2] = 78; lst[4] = 101; - Assert.That(IC.Eq(lst, 45, 7, 78, 7, 101), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 45, 7, 78, 7, 101 })); } [Test] @@ -1177,37 +1156,37 @@ public void Dispose() public void Insert() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 4); - Assert.That(IC.Eq(lst, 7, 4, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5 })); lst.Insert(3, 2); - Assert.That(IC.Eq(lst, 7, 4, 5, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 4, 5, 2 })); } [Test] public void InsertDuplicate() { lst.Insert(0, 5); - Assert.That(IC.Eq(lst, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 5 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5 })); lst.Insert(1, 5); - Assert.That(IC.Eq(lst, 7, 5, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 5 })); } [Test] public void InsertAllDuplicate1() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); lst.InsertAll(1, [1, 2, 3, 4]); Assert.Multiple(() => { - Assert.That(IC.Eq(lst, 7, 1, 2, 3, 4, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 1, 2, 3, 4, 3 })); Assert.That(lst.Check(), Is.True); }); } @@ -1215,14 +1194,14 @@ public void InsertAllDuplicate1() public void InsertAllDuplicate2() { lst.Insert(0, 3); - Assert.That(IC.Eq(lst, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3 })); lst.Insert(0, 7); - Assert.That(IC.Eq(lst, 7, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 3 })); lst.InsertAll(1, [5, 6, 5, 8]); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 5, 6, 5, 8, 3), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 5, 6, 5, 8, 3 })); }); } @@ -1277,7 +1256,7 @@ public void InsertFirstLast() lst.InsertLast(25); lst.InsertFirst(34); lst.InsertLast(55); - Assert.That(IC.Eq(lst, 34, 24, 14, 4, 5, 15, 25, 55), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 34, 24, 14, 4, 5, 15, 25, 55 })); } @@ -1292,19 +1271,19 @@ public void InsertFirst() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 3, 2, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 3, 2, 5 })); }); lst.ViewOf(3).InsertFirst(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 2, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 2, 5 })); }); lst.ViewOf(5).InsertFirst(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 2, 8, 3, 2, 9, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 2, 8, 3, 2, 9, 5 })); }); } @@ -1332,19 +1311,19 @@ public void InsertAfter() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 2, 3, 2, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 2, 3, 2, 7, 5 })); }); lst.LastViewOf(1).InsertLast(8); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 3, 2, 7, 5), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 3, 2, 7, 5 })); }); lst.LastViewOf(5).InsertLast(9); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 1, 8, 2, 3, 2, 7, 5, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 1, 8, 2, 3, 2, 7, 5, 9 })); }); } @@ -1374,19 +1353,19 @@ public void InsertAll() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4 })); }); lst.InsertAll(7, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 3, 4, 7, 8, 9 })); }); lst.InsertAll(5, lst2); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9 })); }); } @@ -1523,31 +1502,31 @@ public void Reverse() Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(0, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 0).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 2, 1, 0 })); }); lst.View(7, 3).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); lst.View(5, 1).Reverse(); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); - Assert.That(IC.Eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 7, 8, 9, 6, 5, 4, 3, 0, 1, 2 })); }); } @@ -1584,14 +1563,14 @@ public class SortingTests public void Sort() { lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3); - Assert.That(lst.IsSorted(new IC()), Is.False); - lst.Sort(new IC()); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.False); + lst.Sort(new IntegerComparer()); Assert.Multiple(() => { Assert.That(lst.Check(), Is.True); Assert.That(lst.IsSorted(), Is.True); - Assert.That(lst.IsSorted(new IC()), Is.True); - Assert.That(IC.Eq(lst, 3, 5, 5, 6, 7), Is.True); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.True); + Assert.That(lst, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -1600,7 +1579,7 @@ public void Sort() public void Stability() { IList> lst2 = new LinkedList>(); - SCG.IComparer> c = new KeyValuePairComparer(new IC()); + SCG.IComparer> c = new KeyValuePairComparer(new IntegerComparer()); lst2.Add(new SCG.KeyValuePair(5, "a")); lst2.Add(new SCG.KeyValuePair(5, "b")); @@ -1659,20 +1638,18 @@ public void Stability() }); } } + [TestFixture] public class ShuffleTests { private IList lst; - [SetUp] public void Init() { lst = new LinkedList(); } - [TearDown] public void Dispose() { lst.Dispose(); } - [Test] public void Shuffle() { @@ -1682,14 +1659,13 @@ public void Shuffle() lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); - Assert.That(IC.Eq(lst2, 3, 5, 5, 6, 7), Is.True, "Contents " + i); + Sorting.IntroSort(lst2); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 5, 6, 7 }), "Contents " + i); } } } } - namespace IStackQueue { [TestFixture] @@ -1699,7 +1675,7 @@ public class Stack [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] @@ -1735,7 +1711,7 @@ public class Queue [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] @@ -1773,19 +1749,15 @@ public class Range { private IList lst; - [SetUp] public void Init() { lst = new LinkedList(); } - [TearDown] public void Dispose() { lst.Dispose(); } - [Test] public void GetRange() { - //Assert.IsTrue(IC.eq(lst[0, 0))); for (int i = 0; i < 10; i++) { lst.Add(i); @@ -1793,9 +1765,9 @@ public void GetRange() Assert.Multiple(() => { - Assert.That(IC.Eq(lst[0, 3], 0, 1, 2), Is.True); - Assert.That(IC.Eq(lst[3, 4], 3, 4, 5, 6), Is.True); - Assert.That(IC.Eq(lst[6, 4], 6, 7, 8, 9), Is.True); + Assert.That(lst[0, 3], Is.EqualTo(new[] { 0, 1, 2 })); + Assert.That(lst[3, 4], Is.EqualTo(new[] { 3, 4, 5, 6 })); + Assert.That(lst[6, 4], Is.EqualTo(new[] { 6, 7, 8, 9 })); }); } @@ -1818,10 +1790,10 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[0, 4].Backwards(), 3, 2, 1, 0), Is.True); - Assert.That(IC.Eq(lst[3, 4].Backwards(), 6, 5, 4, 3), Is.True); - Assert.That(IC.Eq(lst[6, 4].Backwards(), 9, 8, 7, 6), Is.True); + Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); + Assert.That(lst[0, 4].Backwards(), Is.EqualTo(new[] { 3, 2, 1, 0 })); + Assert.That(lst[3, 4].Backwards(), Is.EqualTo(new[] { 6, 5, 4, 3 })); + Assert.That(lst[6, 4].Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6 })); }); } @@ -1883,7 +1855,7 @@ public class Simple [SetUp] public void Init() { - list = new LinkedList() { 0, 1, 2, 3 }; + list = [0, 1, 2, 3]; view = (LinkedList)list.View(1, 2); } @@ -1921,8 +1893,8 @@ public void InsertPointer() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8), Is.True); - Assert.That(IC.Eq(view, 11, 1, 9, 7, 2, 10), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 11, 1, 9, 7, 2, 10, 3, 8 })); + Assert.That(view, Is.EqualTo(new[] { 11, 1, 9, 7, 2, 10 })); }); } @@ -1984,21 +1956,21 @@ public void ViewOf() Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.ViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(2)); }); v = list.LastViewOf(2); Assert.Multiple(() => { Assert.That(v.Check(), Is.True); - Assert.That(IC.Eq(v, 2), Is.True); + Assert.That(v, Is.EqualTo(new[] { 2 })); Assert.That(v.Offset, Is.EqualTo(6)); }); } @@ -2020,10 +1992,10 @@ public void BadViewOf() [Test] public void ArrayStuff() { - Assert.That(IC.Eq(view.ToArray(), 1, 2), Is.True); + Assert.That(view.ToArray(), Is.EqualTo(new[] { 1, 2 })); int[] extarray = new int[5]; view.CopyTo(extarray, 2); - Assert.That(IC.Eq(extarray, 0, 0, 1, 2, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 0, 1, 2, 0 })); } @@ -2033,15 +2005,15 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2 })); }); view.InsertFirst(10); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 10, 1, 2, 3), Is.True); - Assert.That(IC.Eq(view, 10, 1, 2), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 10, 1, 2, 3 })); + Assert.That(view, Is.EqualTo(new[] { 10, 1, 2 })); }); view.Clear(); Assert.Multiple(() => @@ -2051,8 +2023,8 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); - Assert.That(IC.Eq(view), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.True); @@ -2060,45 +2032,45 @@ public void Add() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 3), Is.True); - Assert.That(IC.Eq(view, 8), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8 })); }); view.Add(12); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12 })); }); view./*ViewOf(12).*/InsertLast(15); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 12, 15 })); }); view.ViewOf(12).InsertFirst(18); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15 })); }); - LinkedList lst2 = new() { 90, 92 }; + LinkedList lst2 = [90, 92]; view.AddAll(lst2); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92 })); }); view.InsertLast(66); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3), Is.True); - Assert.That(IC.Eq(view, 8, 18, 12, 15, 90, 92, 66), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 8, 18, 12, 15, 90, 92, 66, 3 })); + Assert.That(view, Is.EqualTo(new[] { 8, 18, 12, 15, 90, 92, 66 })); }); } @@ -2108,7 +2080,7 @@ public void Bxxx() { Assert.Multiple(() => { - Assert.That(IC.Eq(view.Backwards(), 2, 1), Is.True); + Assert.That(view.Backwards(), Is.EqualTo(new[] { 2, 1 })); Assert.That(view.Underlying, Is.SameAs(list)); Assert.That(list.Underlying, Is.Null); Assert.That(view.Direction, Is.EqualTo(Direction.Forwards)); @@ -2128,7 +2100,7 @@ public void Contains() Assert.That(view.Contains(0), Is.False); }); - LinkedList lst2 = new() { 2 }; + LinkedList lst2 = [2]; Assert.That(view.ContainsAll(lst2), Is.True); lst2.Add(3); @@ -2165,11 +2137,11 @@ public void FIFO() check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 23, 24, 25 })); Assert.That(view.Remove(), Is.EqualTo(1)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24, 25), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24, 25 })); view.FIFO = false; Assert.Multiple(() => { @@ -2177,7 +2149,7 @@ public void FIFO() Assert.That(view.Remove(), Is.EqualTo(25)); }); check(); - Assert.That(IC.Eq(view, 2, 23, 24), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 23, 24 })); } @@ -2201,7 +2173,7 @@ public void MapEtc() Assert.Multiple(() => { Assert.That(list.Check(), Is.True); - Assert.That(IC.Eq(list, 1, 1, 5, 9), Is.True); + Assert.That(list, Is.EqualTo(new[] { 1, 1, 5, 9 })); }); } @@ -2253,7 +2225,7 @@ public void INsert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 2, 36 })); }); IList list2 = new LinkedList(); @@ -2263,7 +2235,7 @@ public void INsert() Assert.Multiple(() => { Assert.That(view.Check(), Is.True); - Assert.That(IC.Eq(view, 34, 35, 1, 34, 35, 1, 2, 36, 2, 36), Is.True); + Assert.That(view, Is.EqualTo(new[] { 34, 35, 1, 34, 35, 1, 2, 36, 2, 36 })); }); } @@ -2272,13 +2244,13 @@ public void INsert() public void Sort() { view.Add(45); view.Add(47); view.Add(46); view.Add(48); - Assert.That(view.IsSorted(new IC()), Is.False); - view.Sort(new IC()); + Assert.That(view.IsSorted(new IntegerComparer()), Is.False); + view.Sort(new IntegerComparer()); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(list, 0, 1, 2, 45, 46, 47, 48, 3), Is.True); - Assert.That(IC.Eq(view, 1, 2, 45, 46, 47, 48), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 45, 46, 47, 48, 3 })); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 45, 46, 47, 48 })); }); } @@ -2290,32 +2262,32 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5, 3, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 3, 3, 0 })); Assert.That(view.Remove(0), Is.True); }); check(); - Assert.That(IC.Eq(view, 1, 2, 5, 3, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 3, 3 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 5), Is.True); - Assert.That(IC.Eq(list, 0, 1, 2, 5, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5 })); + Assert.That(list, Is.EqualTo(new[] { 0, 1, 2, 5, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 1, 2, 5, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 5, 1, 5, 3, 1, 3, 0 })); view.FIFO = true; view.Clear(); view.Add(1); view.Add(2); @@ -2323,41 +2295,41 @@ public void Remove() view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 1, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 1, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(1), Is.True); }); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 3, 1, 3, 0 })); Assert.That(view.Remove(0), Is.True); }); check(); - Assert.That(IC.Eq(view, 2, 5, 3, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 3, 1, 3 })); view.RemoveAllCopies(3); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2, 5, 1), Is.True); - Assert.That(IC.Eq(list, 0, 2, 5, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1 })); + Assert.That(list, Is.EqualTo(new[] { 0, 2, 5, 1, 3 })); }); view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0); - Assert.That(IC.Eq(view, 2, 5, 1, 1, 5, 3, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 5, 1, 1, 5, 3, 1, 3, 0 })); - LinkedList l2 = new() { 1, 2, 2, 3, 1 }; + LinkedList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); - Assert.That(IC.Eq(view, 5, 5, 1, 3, 0), Is.True); + Assert.That(view, Is.EqualTo(new[] { 5, 5, 1, 3, 0 })); view.RetainAll(l2); check(); - Assert.That(IC.Eq(view, 1, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 1, 3 })); view.Add(2); view.Add(4); view.Add(5); Assert.Multiple(() => { @@ -2366,7 +2338,7 @@ public void Remove() Assert.That(view.RemoveAt(1), Is.EqualTo(2)); }); check(); - Assert.That(IC.Eq(view, 3, 4), Is.True); + Assert.That(view, Is.EqualTo(new[] { 3, 4 })); view.Add(8); Assert.Multiple(() => { @@ -2376,7 +2348,7 @@ public void Remove() view.Add(2); view.Add(5); view.Add(3); view.Add(1); view.RemoveInterval(1, 2); check(); - Assert.That(IC.Eq(view, 4, 3, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 4, 3, 1 })); } @@ -2391,12 +2363,12 @@ public void Reverse() view.View(3, 4).Reverse(); check(); - Assert.That(IC.Eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19), Is.True); + Assert.That(view, Is.EqualTo(new[] { 10, 11, 12, 16, 15, 14, 13, 17, 18, 19 })); view.Reverse(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10), Is.True); - Assert.That(IC.Eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 19, 18, 17, 13, 14, 15, 16, 12, 11, 10 })); + Assert.That(list, Is.EqualTo(new[] { 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3 })); }); } @@ -2406,24 +2378,24 @@ public void Slide() { view.Slide(1); check(); - Assert.That(IC.Eq(view, 2, 3), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2, 3 })); view.Slide(-2); check(); - Assert.That(IC.Eq(view, 0, 1), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1 })); view.Slide(0, 3); check(); - Assert.That(IC.Eq(view, 0, 1, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 0, 1, 2 })); view.Slide(2, 1); check(); Assert.Multiple(() => { - Assert.That(IC.Eq(view, 2), Is.True); + Assert.That(view, Is.EqualTo(new[] { 2 })); Assert.That(view.Slide(-1, 0), Is.EqualTo(view)); }); check(); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(28); - Assert.That(IC.Eq(list, 0, 28, 1, 2, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } [Test] public void Iterate() @@ -2456,7 +2428,7 @@ public void Iterate() } //foreach (int cell in list) Console.Write(" " + cell); //Assert.IsTrue(list.Check()); - Assert.That(IC.Eq(list, 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7), Is.True); + Assert.That(list, Is.EqualTo(new[] { 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7 })); } @@ -2675,7 +2647,7 @@ private int s(int i, int j) [Test] public void InsertAll() { - LinkedList list2 = new(); + LinkedList list2 = []; for (int i = 0; i < 5; i++) { list2.Add(100 + i); } Assert.That(list.Check(), Is.True, "list check before insertAll"); list.InsertAll(3, list2); @@ -2696,7 +2668,7 @@ public void InsertAll() [Test] public void AddAll() { - LinkedList list2 = new(); + LinkedList list2 = []; for (int i = 0; i < 5; i++) { list2.Add(100 + i); } Assert.That(list.Check(), Is.True, "list check before AddAll"); list.View(1, 2).AddAll(list2); @@ -2717,7 +2689,7 @@ public void AddAll() [Test] public void RemoveAll1() { - LinkedList list2 = new() { 1, 3, 4 }; + LinkedList list2 = [1, 3, 4]; for (int i = 0; i < 7; i++) { @@ -2738,7 +2710,7 @@ public void RemoveAll1() [Test] public void RemoveAll2() { - LinkedList list2 = new() { 1, 3, 4 }; + LinkedList list2 = [1, 3, 4]; Assert.That(list.Check(), Is.True, "list check before RemoveAll"); list.RemoveAll(list2); @@ -2809,7 +2781,7 @@ public void RemoveAll2() [Test] public void RetainAll() { - LinkedList list2 = new() { 2, 4, 5 }; + LinkedList list2 = [2, 4, 5]; Assert.That(list.Check(), Is.True, "list check before RetainAll"); list.RetainAll(list2); Assert.Multiple(() => @@ -2880,7 +2852,7 @@ public void RetainAll() [Test] public void RemoveAllCopies() { - LinkedList list2 = new() { 0, 2, 2, 2, 5, 2, 1 }; + LinkedList list2 = [0, 2, 2, 2, 5, 2, 1]; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7 - i; j++) @@ -3234,15 +3206,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new LinkedList(); + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3299,15 +3271,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new LinkedList(); + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3368,17 +3340,17 @@ public class MultiLevelUnOrderedOfOrdered public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dat = new LinkedList(); - dut = new LinkedList(); - dot = new LinkedList(); + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(2); dat.Add(1); dut.Add(3); dot.Add(1); dot.Add(2); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); - Dot = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3443,17 +3415,17 @@ public class MultiLevelOrderedOfOrdered public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dat = new LinkedList(); - dut = new LinkedList(); - dot = new LinkedList(); + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(2); dat.Add(1); dut.Add(3); dot.Add(1); dot.Add(2); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); - Dot = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3514,9 +3486,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3601,7 +3573,7 @@ public void WrongOrder() Assert.That(dut.SequencedEquals(dit), Is.True); }); dit.Add(7); - ((LinkedList)dut).InsertFirst(7); + dut.InsertFirst(7); Assert.Multiple(() => { Assert.That(dit.SequencedEquals(dut), Is.False); @@ -3641,9 +3613,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3771,15 +3743,15 @@ public class MultiLevelUnorderedOfUnOrdered [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3832,15 +3804,15 @@ public class MultiLevelOrderedOfUnOrdered [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; } @@ -3894,18 +3866,18 @@ public class MultiLevelUnOrderedOfOrdered [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); - dot = new LinkedList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); - Dot = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } @@ -3964,18 +3936,18 @@ public class MultiLevelOrderedOfOrdered [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); - dot = new LinkedList(); + dit = []; + dat = []; + dut = []; + dot = []; dit.Add(2); dit.Add(1); dat.Add(1); dat.Add(2); dut.Add(3); dot.Add(2); dot.Add(1); - Dit = new LinkedList>(); - Dat = new LinkedList>(); - Dut = new LinkedList>(); - Dot = new LinkedList>(); + Dit = []; + Dat = []; + Dut = []; + Dot = []; } diff --git a/C5.Tests/Sorting.cs b/C5.Tests/Sorting.cs index 33bb80c4..60f4e1ca 100644 --- a/C5.Tests/Sorting.cs +++ b/C5.Tests/Sorting.cs @@ -9,7 +9,7 @@ namespace C5.Tests.SortingTests [TestFixture] public class SortRandom { - private IC ic; + private IntegerComparer ic; private Random ran; private int[] a; private int length; @@ -18,7 +18,7 @@ public class SortRandom [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); ran = new Random(3456); length = 100000; a = new int[length]; @@ -32,7 +32,7 @@ public void Init() [Test] public void HeapSort() { - Sorting.HeapSort(a, 0, length, ic); + Sorting.HeapSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -43,7 +43,7 @@ public void HeapSort() [Test] public void IntroSort() { - Sorting.IntroSort(a, 0, length, ic); + Sorting.IntroSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -55,13 +55,13 @@ public void IntroSort() public void InsertionSort() { length = 1000; - Sorting.InsertionSort(a, 0, length, ic); + Sorting.InsertionSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); } - Sorting.InsertionSort(a, length, 2 * length, ic); + Sorting.InsertionSort(a, length, 2 * length, ic); for (int i = length + 1; i < 2 * length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -78,7 +78,7 @@ public void InsertionSort() [TestFixture] public class SortRandomDuplicates { - private IC ic; + private IntegerComparer ic; private Random ran; private int[] a; private int length; @@ -87,7 +87,7 @@ public class SortRandomDuplicates [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); ran = new Random(3456); length = 100000; a = new int[length]; @@ -101,7 +101,7 @@ public void Init() [Test] public void HeapSort() { - Sorting.HeapSort(a, 0, length, ic); + Sorting.HeapSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -112,7 +112,7 @@ public void HeapSort() [Test] public void IntroSort() { - Sorting.IntroSort(a, 0, length, ic); + Sorting.IntroSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -124,13 +124,13 @@ public void IntroSort() public void InsertionSort() { length = 1000; - Sorting.InsertionSort(a, 0, length, ic); + Sorting.InsertionSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); } - Sorting.InsertionSort(a, length, 2 * length, ic); + Sorting.InsertionSort(a, length, 2 * length, ic); for (int i = length + 1; i < 2 * length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -147,7 +147,7 @@ public void InsertionSort() [TestFixture] public class SortIncreasing { - private IC ic; + private IntegerComparer ic; private int[] a; private int length; @@ -155,7 +155,7 @@ public class SortIncreasing [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); length = 100000; a = new int[length]; for (int i = 0; i < length; i++) @@ -168,7 +168,7 @@ public void Init() [Test] public void HeapSort() { - Sorting.HeapSort(a, 0, length, ic); + Sorting.HeapSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -179,7 +179,7 @@ public void HeapSort() [Test] public void IntroSort() { - Sorting.IntroSort(a, 0, length, ic); + Sorting.IntroSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -191,13 +191,13 @@ public void IntroSort() public void InsertionSort() { length = 1000; - Sorting.InsertionSort(a, 0, length, ic); + Sorting.InsertionSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); } - Sorting.InsertionSort(a, length, 2 * length, ic); + Sorting.InsertionSort(a, length, 2 * length, ic); for (int i = length + 1; i < 2 * length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -214,7 +214,7 @@ public void InsertionSort() [TestFixture] public class SortDecreasing { - private IC ic; + private IntegerComparer ic; private int[] a; private int length; @@ -222,7 +222,7 @@ public class SortDecreasing [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); length = 100000; a = new int[length]; for (int i = 0; i < length; i++) @@ -235,7 +235,7 @@ public void Init() [Test] public void HeapSort() { - Sorting.HeapSort(a, 0, length, ic); + Sorting.HeapSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -246,7 +246,7 @@ public void HeapSort() [Test] public void IntroSort() { - Sorting.IntroSort(a, 0, length, ic); + Sorting.IntroSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); @@ -258,13 +258,13 @@ public void IntroSort() public void InsertionSort() { length = 1000; - Sorting.InsertionSort(a, 0, length, ic); + Sorting.InsertionSort(a, 0, length, ic); for (int i = 1; i < length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); } - Sorting.InsertionSort(a, length, 2 * length, ic); + Sorting.InsertionSort(a, length, 2 * length, ic); for (int i = length + 1; i < 2 * length; i++) { Assert.That(a[i - 1] <= a[i], Is.True, "Inversion at " + i); diff --git a/C5.Tests/SupportClasses.cs b/C5.Tests/SupportClasses.cs index d767163c..ec4b2514 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -7,24 +7,11 @@ namespace C5.Tests { - internal class SC : SCG.IComparer - { - public int Compare(string a, string b) - { - return a.CompareTo(b); - } - - public void appl(string s) - { - Console.WriteLine("--{0}", s); - } - } - internal class TenEqualityComparer : SCG.IEqualityComparer, SCG.IComparer { private TenEqualityComparer() { } - public static TenEqualityComparer Default => new(); + public static TenEqualityComparer Instance { get; } = new(); public int GetHashCode(int item) { return (item / 10).GetHashCode(); } @@ -33,95 +20,32 @@ private TenEqualityComparer() { } public int Compare(int a, int b) { return (a / 10).CompareTo(b / 10); } } - internal class IC : SCG.IComparer, IComparable, SCG.IComparer, IComparable + internal class IntegerComparer : SCG.IComparer, IComparable { public int Compare(int a, int b) => a > b ? 1 : a < b ? -1 : 0; - public int Compare(IC a, IC b) => a.I > b.I ? 1 : a.I < b.I ? -1 : 0; - - public int I { get; set; } + public int I { get; } - public IC() { } + public IntegerComparer() { } - public IC(int i) => I = i; + public IntegerComparer(int i) => I = i; public int CompareTo(int that) => I > that ? 1 : I < that ? -1 : 0; public bool Equals(int that) => I == that; - - public int CompareTo(IC? that) - { - if (that is null || I > that.I) - { - return 1; - } - else - { - return I < that.I ? -1 : 0; - } - } - - public bool Equals(IC that) => I == that.I; - - public static bool Eq(SCG.IEnumerable me, params int[] that) - { - int i = 0, maxind = that.Length - 1; - - foreach (int item in me) - { - if (i > maxind || item != that[i++]) - { - return false; - } - } - - return i == maxind + 1; - } - public static bool SetEq(ICollectionValue me, params int[] that) - { - int[] me2 = me.ToArray(); - - Array.Sort(me2); - - int i = 0, maxind = that.Length - 1; - - foreach (int item in me2) - { - if (i > maxind || item != that[i++]) - { - return false; - } - } - - return i == maxind + 1; - } - public static bool SetEq(ICollectionValue> me, params int[] that) - { - var first = new ArrayList>(); - first.AddAll(me); - var other = new ArrayList>(); - for (int i = 0; i < that.Length; i += 2) - { - other.Add(new SCG.KeyValuePair(that[i], that[i + 1])); - } - return other.UnsequencedEquals(first); - } } - internal class RevIC : SCG.IComparer + internal class ReverseIntegerComparer : SCG.IComparer { - public int Compare(int a, int b) - { - return a > b ? -1 : a < b ? 1 : 0; - } + public int Compare(int a, int b) => a.CompareTo(b) * -1; } - public class FunEnumerable : SCG.IEnumerable + public class FuncEnumerable : SCG.IEnumerable { private readonly int size; private readonly Func f; - public FunEnumerable(int size, Func f) + public FuncEnumerable(int size, Func f) { this.size = size; this.f = f; } @@ -134,7 +58,6 @@ public SCG.IEnumerator GetEnumerator() } } - #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() @@ -177,16 +100,11 @@ public override SCG.IEnumerator GetEnumerator() public override T Choose() { throw exception; } } - public class CollectionEventList + public class CollectionEventList(SCG.IEqualityComparer itemequalityComparer) { - private readonly ArrayList> happened; + private readonly ArrayList> happened = []; private EventType listenTo; - private readonly SCG.IEqualityComparer itemequalityComparer; - public CollectionEventList(SCG.IEqualityComparer itemequalityComparer) - { - happened = new ArrayList>(); - this.itemequalityComparer = itemequalityComparer; - } + public void Listen(ICollectionValue list, EventType listenTo) { this.listenTo = listenTo; @@ -442,58 +360,18 @@ public RadixFormatter(int radix) 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ]; - public string Format(string format, object arg, IFormatProvider formatProvider) + public string Format(string? format, object? arg, IFormatProvider? formatProvider) { - /*switch (Type.GetTypeCode(argToBeFormatted.GetType())) - { - case TypeCode.Boolean: - break; - case TypeCode.Byte: - break; - case TypeCode.Char: - break; - case TypeCode.DBNull: - break; - case TypeCode.DateTime: - break; - case TypeCode.Decimal: - break; - case TypeCode.Double: - break; - case TypeCode.Empty: - break; - case TypeCode.Int16: - break; - case TypeCode.Int32: - break; - case TypeCode.Int64: - break; - case TypeCode.Object: - break; - case TypeCode.SByte: - break; - case TypeCode.Single: - break; - case TypeCode.String: - break; - case TypeCode.UInt16: - break; - case TypeCode.UInt32: - break; - case TypeCode.UInt64: - break; - }*/ int intToBeFormatted; try { - intToBeFormatted = (int)arg; + intToBeFormatted = (int)arg!; } catch (Exception) { - if (arg is IFormattable) + if (arg is IFormattable formattable) { - return ((IFormattable)arg). - ToString(format, formatProvider); + return formattable.ToString(format, formatProvider); } else if (IsKeyValuePair(arg)) { @@ -550,7 +428,7 @@ private string formatInt(int intToBeFormatted) } // SCG.KeyValuePair is not showable, so we hack it now. - private bool IsKeyValuePair(object arg) + private static bool IsKeyValuePair(object arg) { if (arg != null) { @@ -565,12 +443,12 @@ private bool IsKeyValuePair(object arg) return false; } - private (object key, object value) GetKeyValuePair(object arg) + private static (object? key, object? value) GetKeyValuePair(object arg) { var type = arg.GetType(); - var key = type.GetProperty("Key").GetValue(arg, null); - var value = type.GetProperty("Value").GetValue(arg, null); + var key = type.GetProperty("Key")?.GetValue(arg, null); + var value = type.GetProperty("Value")?.GetValue(arg, null); return (key, value); } diff --git a/C5.Tests/Templates/Events.cs b/C5.Tests/Templates/Events.cs index 47c64c73..325dc2da 100644 --- a/C5.Tests/Templates/Events.cs +++ b/C5.Tests/Templates/Events.cs @@ -743,7 +743,7 @@ public void EnqueueDequeue() public class PriorityQueueTester : ExtensibleTester where U : IPriorityQueue { - public override System.Collections.Generic.IEnumerable GetSpecs() + public override SCG.IEnumerable GetSpecs() { return SpecsBasic; } @@ -843,7 +843,7 @@ public void WithHandles() } } - public class DictionaryTester : CollectionValueTester> where U : IDictionary + public class DictionaryTester : CollectionValueTester> where U : IDictionary { public override SCG.IEnumerable GetSpecs() { @@ -867,12 +867,12 @@ public void AddAndREmove() seen.Check([]); collection.Add(23, 45); seen.Check([ - new CollectionEvent>(EventType.Added, new ItemCountEventArgs>(new System.Collections.Generic.KeyValuePair(23,45), 1), collection), - new CollectionEvent>(EventType.Changed, new EventArgs(), collection)]); + new CollectionEvent>(EventType.Added, new ItemCountEventArgs>(new SCG.KeyValuePair(23,45), 1), collection), + new CollectionEvent>(EventType.Changed, new EventArgs(), collection)]); collection.Remove(25); seen.Check([ - new CollectionEvent>(EventType.Removed, new ItemCountEventArgs>(new System.Collections.Generic.KeyValuePair(23,45), 1), collection), - new CollectionEvent>(EventType.Changed, new EventArgs(), collection)]); + new CollectionEvent>(EventType.Removed, new ItemCountEventArgs>(new SCG.KeyValuePair(23,45), 1), collection), + new CollectionEvent>(EventType.Changed, new EventArgs(), collection)]); } diff --git a/C5.Tests/Templates/GenericCollectionTester.cs b/C5.Tests/Templates/GenericCollectionTester.cs index 09135105..e8981a51 100644 --- a/C5.Tests/Templates/GenericCollectionTester.cs +++ b/C5.Tests/Templates/GenericCollectionTester.cs @@ -55,7 +55,7 @@ public virtual void Test(Func factory) public abstract class GenericCollectionTester : GenericCollectionTester { - public override System.Collections.Generic.IEnumerable GetSpecs() + public override SCG.IEnumerable GetSpecs() { return [0]; } diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 0ddb53c4..07f58738 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -59,8 +59,8 @@ public class GenericTesters [Test] public void TestEvents() { - TreeBag factory() { return new TreeBag(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.SortedIndexedTester>().Test(factory); + TreeBag factory() { return new TreeBag(TenEqualityComparer.Instance); } + new Templates.Events.SortedIndexedTester>().Test(factory); } } @@ -103,7 +103,7 @@ public class Combined [SetUp] public void Init() { - lst = new TreeBag>(new KeyValuePairComparer(new IC())); + lst = new TreeBag>(new KeyValuePairComparer(new IntegerComparer())); for (int i = 0; i < 10; i++) { lst.Add(new SCG.KeyValuePair(i, i + 30)); @@ -191,7 +191,7 @@ public void UpdateOrAdd1() [Test] public void UpdateOrAdd2() { - ICollection coll = new TreeBag(); + var coll = new TreeBag(); // s1 and s2 are distinct objects but contain the same text: string s1 = "abc", s2 = ("def" + s1).Substring(3); Assert.Multiple(() => @@ -232,7 +232,7 @@ public class Simple [SetUp] public void Init() { - bag = new TreeBag(new SC()); + bag = new TreeBag(StringComparer.InvariantCulture); } @@ -360,7 +360,7 @@ public class FindOrAdd [SetUp] public void Init() { - bag = new TreeBag>(new KeyValuePairComparer(new IC())); + bag = new TreeBag>(new KeyValuePairComparer(new IntegerComparer())); } @@ -403,7 +403,7 @@ public class Enumerators [SetUp] public void Init() { - bag = new TreeBag(new SC()); + bag = new TreeBag(StringComparer.InvariantCulture); foreach (string s in new string[] { "A", "B", "A", "A", "B", "C", "D", "B" }) { bag.Add(s); @@ -468,7 +468,7 @@ public class Ranges [SetUp] public void Init() { - c = new IC(); + c = new IntegerComparer(); tree = new TreeBag(c); for (int i = 1; i <= 10; i++) { @@ -520,35 +520,35 @@ public void Remove() int[] all = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18, 20]; tree.RemoveRangeFrom(18); - Assert.That(IC.Eq(tree, [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16 })); tree.RemoveRangeFrom(28); - Assert.That(IC.Eq(tree, [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16 })); tree.RemoveRangeFrom(1); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); } tree.RemoveRangeTo(10); - Assert.That(IC.Eq(tree, [10, 10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 10, 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeTo(2); - Assert.That(IC.Eq(tree, [10, 10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 10, 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeTo(21); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); } tree.RemoveRangeFromTo(4, 8); - Assert.That(IC.Eq(tree, 1, 2, 2, 3, 8, 8, 9, 10, 10, 12, 14, 16, 18, 20), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 1, 2, 2, 3, 8, 8, 9, 10, 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeFromTo(14, 28); - Assert.That(IC.Eq(tree, 1, 2, 2, 3, 8, 8, 9, 10, 10, 12), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 1, 2, 2, 3, 8, 8, 9, 10, 10, 12 })); tree.RemoveRangeFromTo(0, 9); - Assert.That(IC.Eq(tree, 9, 10, 10, 12), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 9, 10, 10, 12 })); tree.RemoveRangeFromTo(0, 81); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); } @@ -559,31 +559,31 @@ public void Normal() Assert.Multiple(() => { - Assert.That(IC.Eq(tree, all), Is.True); - Assert.That(IC.Eq(tree.RangeAll(), all), Is.True); + Assert.That(tree, Is.EqualTo(all)); + Assert.That(tree.RangeAll(), Is.EqualTo(all)); Assert.That(tree.RangeAll(), Has.Count.EqualTo(20)); - Assert.That(IC.Eq(tree.RangeFrom(11), [12, 14, 16, 18, 20]), Is.True); + Assert.That(tree.RangeFrom(11), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); Assert.That(tree.RangeFrom(11), Has.Count.EqualTo(5)); - Assert.That(IC.Eq(tree.RangeFrom(12), [12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(1), all), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(0), all), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(21), []), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(20), [20]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(8), [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(7), [1, 2, 2, 3, 4, 4, 5, 6, 6]), Is.True); + Assert.That(tree.RangeFrom(12), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); + Assert.That(tree.RangeFrom(1), Is.EqualTo(all)); + Assert.That(tree.RangeFrom(0), Is.EqualTo(all)); + Assert.That(tree.RangeFrom(21), Is.Empty); + Assert.That(tree.RangeFrom(20), Is.EqualTo(new[] { 20 })); + Assert.That(tree.RangeTo(8), Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7 })); + Assert.That(tree.RangeTo(7), Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6 })); Assert.That(tree.RangeTo(7), Has.Count.EqualTo(9)); - Assert.That(IC.Eq(tree.RangeTo(1), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(0), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(3), [1, 2, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(20), [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(21), all), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(7, 12), [7, 8, 8, 9, 10, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 11), [6, 6, 7, 8, 8, 9, 10, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(1, 12), [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10]), Is.True); + Assert.That(tree.RangeTo(1), Is.Empty); + Assert.That(tree.RangeTo(0), Is.Empty); + Assert.That(tree.RangeTo(3), Is.EqualTo(new[] { 1, 2, 2 })); + Assert.That(tree.RangeTo(20), Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18 })); + Assert.That(tree.RangeTo(21), Is.EqualTo(all)); + Assert.That(tree.RangeFromTo(7, 12), Is.EqualTo(new[] { 7, 8, 8, 9, 10, 10 })); + Assert.That(tree.RangeFromTo(6, 11), Is.EqualTo(new[] { 6, 6, 7, 8, 8, 9, 10, 10 })); + Assert.That(tree.RangeFromTo(1, 12), Is.EqualTo(new[] { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10 })); Assert.That(tree.RangeFromTo(1, 12), Has.Count.EqualTo(15)); - Assert.That(IC.Eq(tree.RangeFromTo(2, 12), [2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 21), [6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 20), [6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18]), Is.True); + Assert.That(tree.RangeFromTo(2, 12), Is.EqualTo(new[] { 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10 })); + Assert.That(tree.RangeFromTo(6, 21), Is.EqualTo(new[] { 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18, 20 })); + Assert.That(tree.RangeFromTo(6, 20), Is.EqualTo(new[] { 6, 6, 7, 8, 8, 9, 10, 10, 12, 14, 16, 18 })); }); } @@ -596,31 +596,30 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(tree, all), Is.True); - Assert.That(IC.Eq(tree.RangeAll().Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(11).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(12).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(1).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(0).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(21).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(20).Backwards(), [20]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(8).Backwards(), [7, 6, 6, 5, 4, 4, 3, 2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(7).Backwards(), [6, 6, 5, 4, 4, 3, 2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(1).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(0).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(3).Backwards(), [2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(20).Backwards(), [18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(21).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(7, 12).Backwards(), [10, 10, 9, 8, 8, 7]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 11).Backwards(), [10, 10, 9, 8, 8, 7, 6, 6]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(0, 12).Backwards(), [10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(1, 12).Backwards(), [10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 21).Backwards(), [20, 18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 20).Backwards(), [18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6]), Is.True); + Assert.That(tree, Is.EqualTo(all)); + Assert.That(tree.RangeAll().Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(11).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(tree.RangeFrom(12).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(tree.RangeFrom(1).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(0).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(21).Backwards(), Is.Empty); + Assert.That(tree.RangeFrom(20).Backwards(), Is.EqualTo(new[] { 20 })); + Assert.That(tree.RangeTo(8).Backwards(), Is.EqualTo(new[] { 7, 6, 6, 5, 4, 4, 3, 2, 2, 1 })); + Assert.That(tree.RangeTo(7).Backwards(), Is.EqualTo(new[] { 6, 6, 5, 4, 4, 3, 2, 2, 1 })); + Assert.That(tree.RangeTo(1).Backwards(), Is.Empty); + Assert.That(tree.RangeTo(0).Backwards(), Is.Empty); + Assert.That(tree.RangeTo(3).Backwards(), Is.EqualTo(new[] { 2, 2, 1 })); + Assert.That(tree.RangeTo(20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1 })); + Assert.That(tree.RangeTo(21).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFromTo(7, 12).Backwards(), Is.EqualTo(new[] { 10, 10, 9, 8, 8, 7 })); + Assert.That(tree.RangeFromTo(6, 11).Backwards(), Is.EqualTo(new[] { 10, 10, 9, 8, 8, 7, 6, 6 })); + Assert.That(tree.RangeFromTo(0, 12).Backwards(), Is.EqualTo(new[] { 10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1 })); + Assert.That(tree.RangeFromTo(1, 12).Backwards(), Is.EqualTo(new[] { 10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1 })); + Assert.That(tree.RangeFromTo(6, 21).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6 })); + Assert.That(tree.RangeFromTo(6, 20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 10, 9, 8, 8, 7, 6, 6 })); }); } - [Test] public void Direction() { @@ -639,7 +638,6 @@ public void Direction() }); } - [TearDown] public void Dispose() { @@ -648,18 +646,15 @@ public void Dispose() } } - - [TestFixture] public class BagItf { private TreeBag tree; - [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); for (int i = 10; i < 20; i++) { tree.Add(i); @@ -667,7 +662,6 @@ public void Init() } } - [Test] public void Both() { @@ -682,7 +676,6 @@ public void Both() tree.RemoveAllCopies(7); } - [TearDown] public void Dispose() { @@ -690,21 +683,17 @@ public void Dispose() } } - - [TestFixture] public class Div { private TreeBag tree; - [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } - private void loadup() { for (int i = 10; i < 20; i++) @@ -751,7 +740,6 @@ public void BadChoose() Assert.Throws(() => tree.Choose()); } - [Test] public void NoDuplicates() { @@ -760,7 +748,6 @@ public void NoDuplicates() Assert.That(tree.AllowsDuplicates, Is.True); } - [Test] public void Add() { @@ -772,10 +759,9 @@ public void Add() }); Assert.That(tree.Add(18), Is.True); Assert.That(tree, Has.Count.EqualTo(4)); - Assert.That(IC.Eq(tree, 17, 17, 18, 18), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 17, 17, 18, 18 })); } - [TearDown] public void Dispose() { @@ -792,7 +778,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new TreeBag(TenEqualityComparer.Default); + list = new TreeBag(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -854,7 +840,7 @@ public class UniqueItems private TreeBag list; [SetUp] - public void Init() { list = new TreeBag(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -864,14 +850,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 2, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 2), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -882,7 +868,7 @@ public class UniqueItemCount private TreeBag list; [SetUp] - public void Init() { list = new TreeBag(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -995,7 +981,7 @@ public void Test_DeleteMinMax() public void Test_ByIndex() { int i; - list = new TreeBag(new IC()); + list = new TreeBag(new IntegerComparer()); for (i = 10; i < 20; i++) { list.Add(i); @@ -1078,7 +1064,7 @@ public class ArrayTest [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); a = new int[10]; for (int i = 0; i < 10; i++) { @@ -1090,54 +1076,33 @@ public void Init() [TearDown] public void Dispose() { tree.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(tree.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.Empty); tree.Add(4); tree.Add(7); tree.Add(4); - Assert.That(aeq(tree.ToArray(), 4, 4, 7), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 4, 7 })); } - [Test] public void CopyTo() { tree.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(6); tree.Add(6); tree.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 6, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 6, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(4); tree.Add(9); tree.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 1009 })); tree.Clear(); tree.Add(7); tree.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 7 })); } @@ -1173,7 +1138,7 @@ public class Remove [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); for (int i = 10; i < 20; i++) { tree.Add(i); @@ -1406,7 +1371,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } private void loadup() @@ -1557,7 +1522,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } private void loadup() @@ -1637,7 +1602,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } @@ -1801,7 +1766,7 @@ public class Enumerator [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1867,7 +1832,7 @@ public class RangeEnumerator [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1932,7 +1897,7 @@ public class Navigation [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeBag(ic); for (int i = 0; i <= 20; i++) { @@ -1947,30 +1912,25 @@ public void Init() } } - private bool twomodeleven(int i) { return i % 11 == 2; } - [Test] public void InternalEnum() { - Assert.That(IC.Eq(snap.FindAll(new Func(twomodeleven)), 13, 13, 35), Is.True); + Assert.That(snap.FindAll(new Func(twomodeleven)), Is.EqualTo(new[] { 13, 13, 35 })); } - public void MoreCut() { //TODO: Assert.Fail("more tests of Cut needed"); } - [Test] public void Cut() { - Assert.Multiple(() => { Assert.That(snap.Cut(new HigherOrder.CubeRoot(64), out int lo, out bool lv, out int hi, out bool hv), Is.False); @@ -1990,19 +1950,17 @@ public void Cut() }); } - [Test] public void Range() { Assert.Multiple(() => { - Assert.That(IC.Eq(snap.RangeFromTo(5, 16), 5, 7, 9, 11, 13, 13, 15), Is.True); - Assert.That(IC.Eq(snap.RangeFromTo(5, 17), 5, 7, 9, 11, 13, 13, 15), Is.True); - Assert.That(IC.Eq(snap.RangeFromTo(6, 16), 7, 9, 11, 13, 13, 15), Is.True); + Assert.That(snap.RangeFromTo(5, 16), Is.EqualTo(new[] { 5, 7, 9, 11, 13, 13, 15 })); + Assert.That(snap.RangeFromTo(5, 17), Is.EqualTo(new[] { 5, 7, 9, 11, 13, 13, 15 })); + Assert.That(snap.RangeFromTo(6, 16), Is.EqualTo(new[] { 7, 9, 11, 13, 13, 15 })); }); } - [Test] public void Contains() { @@ -2136,7 +2094,7 @@ public class Single [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeBag(ic); for (int i = 0; i < 10; i++) { @@ -2148,7 +2106,7 @@ public void Init() [Test] public void Bug20120422_1() { - var coll = new C5.TreeBag() { "C" }; + var coll = new TreeBag() { "C" }; _ = coll.Snapshot(); coll.Add("C"); Assert.That(coll.ContainsCount("C"), Is.EqualTo(2)); @@ -2157,7 +2115,7 @@ public void Bug20120422_1() [Test] public void Bug20120422_2() { - var coll = new C5.TreeBag + var coll = new TreeBag { "B", "A", @@ -2222,7 +2180,7 @@ public void EnumerationWithAdd() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); } @@ -2238,14 +2196,14 @@ public void Remove() Assert.Multiple(() => { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); tree.Remove(19); Assert.Multiple(() => { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); } @@ -2268,7 +2226,7 @@ public void RemoveNormal() { Assert.That(tree.Remove(-20), Is.False); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //decrease items case @@ -2277,13 +2235,13 @@ public void RemoveNormal() }); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); //snap.dump(); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //No demote case, with move_item Assert.That(tree.Remove(20), Is.True); Assert.That(tree.Check("T1"), Is.True); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Remove(20), Is.False); //plain case 2 @@ -2293,26 +2251,26 @@ public void RemoveNormal() Assert.That(tree.Remove(14), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //case 1b Assert.That(tree.Remove(25), Is.True); }); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //case 1c Assert.That(tree.Remove(29), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //1a (terminating) Assert.That(tree.Remove(10), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //2+1b Assert.That(tree.Remove(12), Is.True); @@ -2322,7 +2280,7 @@ public void RemoveNormal() Assert.That(tree.Remove(11), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //1a+1b Assert.That(tree.Remove(18), Is.True); @@ -2331,7 +2289,7 @@ public void RemoveNormal() }); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //2+1c for (int i = 0; i < 10; i++) @@ -2347,7 +2305,7 @@ public void RemoveNormal() Assert.That(tree.Remove(40), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); // Assert.That(tree.Remove(16), Is.True); @@ -2372,14 +2330,14 @@ public void RemoveNormal() Assert.That(tree.Remove(48), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); //Empty tree: Assert.That(tree.Remove(26), Is.False); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); } @@ -2392,21 +2350,21 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); tree.Add(10); Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); tree.Add(16); Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); @@ -2415,7 +2373,7 @@ public void Add() { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); //Promote+zigzig @@ -2424,7 +2382,7 @@ public void Add() { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); for (int i = 1; i < 4; i++) { @@ -2434,7 +2392,7 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); @@ -2443,7 +2401,7 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); } @@ -2460,7 +2418,7 @@ public void Clear() { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree, Is.Empty); }); } @@ -2498,7 +2456,7 @@ public class Multiple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeBag(ic); for (int i = 0; i < 10; i++) { @@ -2535,9 +2493,9 @@ public void First() Assert.Multiple(() => { - Assert.That(IC.Eq(snaps[3], snap3), Is.True, "Snap 3 was changed!"); - Assert.That(IC.Eq(snaps[7], snap7), Is.True, "Snap 7 was changed!"); - Assert.That(IC.Eq(tree, res), Is.True); + Assert.That(snaps[3], Is.EqualTo(snap3), "Snap 3 was changed!"); + Assert.That(snaps[7], Is.EqualTo(snap7), "Snap 7 was changed!"); + Assert.That(tree, Is.EqualTo(res)); Assert.That(tree.Check("B"), Is.True); Assert.That(snaps[3].Check("B"), Is.True); Assert.That(snaps[7].Check("B"), Is.True); @@ -2573,8 +2531,8 @@ public void CollectingTheMaster() Assert.Multiple(() => { - Assert.That(IC.Eq(snaps[3], snap3), Is.True, "Snap 3 was changed!"); - Assert.That(IC.Eq(snaps[7], snap7), Is.True, "Snap 7 was changed!"); + Assert.That(snaps[3], Is.EqualTo(snap3), "Snap 3 was changed!"); + Assert.That(snaps[7], Is.EqualTo(snap7), "Snap 7 was changed!"); Assert.That(snaps[3].Check("B"), Is.True); Assert.That(snaps[7].Check("B"), Is.True); }); @@ -2629,7 +2587,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeBag(ic); } @@ -2805,7 +2763,7 @@ public void FindAll() [Test] public void Map() { - Assert.That(tree.Map(new Func(themap), new SC()), Is.Empty); + Assert.That(tree.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); for (int i = 0; i < 14; i++) { tree.Add(i * i * i); @@ -2813,7 +2771,7 @@ public void Map() tree.Add(1); - IIndexedSorted res = tree.Map(new Func(themap), new SC()); + IIndexedSorted res = tree.Map(new Func(themap), StringComparer.InvariantCulture); Assert.Multiple(() => { @@ -2843,7 +2801,7 @@ public void BadMap() var exception = Assert.Throws(() => { - ISorted res = tree.Map(new Func(badmap), new SC()); + ISorted res = tree.Map(new Func(badmap), StringComparer.InvariantCulture); }); Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); @@ -2884,11 +2842,11 @@ public void CutInt() Assert.Multiple(() => { - Assert.That(tree.Cut(new IC(3), out int low, out bool lval, out int high, out bool hval), Is.False); + Assert.That(tree.Cut(new IntegerComparer(3), out int low, out bool lval, out int high, out bool hval), Is.False); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(4)); Assert.That(low, Is.EqualTo(2)); - Assert.That(tree.Cut(new IC(6), out low, out lval, out high, out hval), Is.True); + Assert.That(tree.Cut(new IntegerComparer(6), out low, out lval, out high, out hval), Is.True); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(8)); Assert.That(low, Is.EqualTo(4)); @@ -2981,13 +2939,13 @@ public class AddAll [SetUp] - public void Init() { tree = new TreeBag(new IC()); } + public void Init() { tree = new TreeBag(new IntegerComparer()); } [Test] public void EmptyEmpty() { - tree.AddAll(new FunEnumerable(0, new Func(sqr))); + tree.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } @@ -3001,7 +2959,7 @@ public void SomeEmpty() tree.Add(i); } - tree.AddAll(new FunEnumerable(0, new Func(sqr))); + tree.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(5)); Assert.That(tree.Check(), Is.True); } @@ -3010,7 +2968,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - tree.AddAll(new FunEnumerable(4, new Func(sqr))); + tree.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(4)); Assert.Multiple(() => { @@ -3033,12 +2991,12 @@ public void SomeSome() tree.Add(1); - tree.AddAll(new FunEnumerable(4, new Func(sqr))); + tree.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(9)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 1, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 1, 4, 5, 6, 7, 8, 9 })); }); } @@ -3052,29 +3010,22 @@ public void SomeSome() [TestFixture] public class AddSorted { - private int sqr(int i) { return i * i; } - - private int step(int i) { return i / 3; } - - - private int bad(int i) { return i * (5 - i); } - private TreeBag tree; - [SetUp] - public void Init() { tree = new TreeBag(new IC()); } - + public void Init() + { + tree = new TreeBag(new IntegerComparer()); + } [Test] public void EmptyEmpty() { - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(0, i => i * i)); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } - [Test] public void SomeEmpty() { @@ -3083,19 +3034,19 @@ public void SomeEmpty() tree.Add(i); } - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(0, i => i * i)); Assert.That(tree, Has.Count.EqualTo(5)); Assert.That(tree.Check(), Is.True); } - [Test] public void EmptySome() { - tree.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(tree, Has.Count.EqualTo(4)); + tree.AddSorted(new FuncEnumerable(4, i => i * i)); + Assert.Multiple(() => { + Assert.That(tree, Has.Count.EqualTo(4)); Assert.That(tree.Check(), Is.True); Assert.That(tree[0], Is.EqualTo(0)); Assert.That(tree[1], Is.EqualTo(1)); @@ -3107,11 +3058,11 @@ public void EmptySome() [Test] public void EmptySome2() { - tree.AddSorted(new FunEnumerable(4, new Func(step))); - //tree.dump(); - Assert.That(tree, Has.Count.EqualTo(4)); + tree.AddSorted(new FuncEnumerable(4, i => i / 3)); + Assert.Multiple(() => { + Assert.That(tree, Has.Count.EqualTo(4)); Assert.That(tree.Check(), Is.True); Assert.That(tree[0], Is.EqualTo(0)); Assert.That(tree[1], Is.EqualTo(0)); @@ -3120,7 +3071,6 @@ public void EmptySome2() }); } - [Test] public void SomeSome() { @@ -3130,42 +3080,39 @@ public void SomeSome() } tree.Add(1); + tree.AddSorted(new FuncEnumerable(4, i => i * i)); - tree.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(tree, Has.Count.EqualTo(9)); Assert.Multiple(() => { + Assert.That(tree, Has.Count.EqualTo(9)); Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 1, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 1, 4, 5, 6, 7, 8, 9 })); }); } - [Test] public void EmptyBad() { - var exception = Assert.Throws(() => tree.AddSorted(new FunEnumerable(9, new Func(bad)))); + static int bad(int i) { return i * (5 - i); } + + var exception = Assert.Throws(() => tree.AddSorted(new FuncEnumerable(9, bad))); Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); } - [TearDown] public void Dispose() { tree.Dispose(); } } - - [TestFixture] public class Rest { private TreeBag tree, tree2; - [SetUp] public void Init() { - tree = new TreeBag(new IC()); - tree2 = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); + tree2 = new TreeBag(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -3188,28 +3135,28 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 4, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 4, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(3, 7)); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(13, 17)); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(3, 17)); Assert.That(tree, Has.Count.EqualTo(7)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); }); for (int i = 0; i < 10; i++) { @@ -3221,7 +3168,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -3234,28 +3181,28 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4, 6, 8), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4, 6, 8 })); }); tree.RetainAll(tree2.RangeFromTo(1, 17)); Assert.That(tree, Has.Count.EqualTo(3)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4, 6, 8), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4, 6, 8 })); }); tree.RetainAll(tree2.RangeFromTo(3, 5)); Assert.That(tree, Has.Count.EqualTo(1)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4 })); }); tree.RetainAll(tree2.RangeFromTo(7, 17)); Assert.That(tree, Is.Empty); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -3267,7 +3214,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -3279,7 +3226,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -3309,21 +3256,21 @@ public void RemoveInterval() { Assert.That(tree.Check(), Is.True); Assert.That(tree, Has.Count.EqualTo(7)); - Assert.That(IC.Eq(tree, 0, 1, 2, 6, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 6, 7, 8, 9 })); }); tree.RemoveInterval(2, 3); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); Assert.That(tree, Has.Count.EqualTo(4)); - Assert.That(IC.Eq(tree, 0, 1, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 8, 9 })); }); tree.RemoveInterval(0, 4); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); Assert.That(tree, Is.Empty); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -3354,30 +3301,30 @@ public void GetRange() { Assert.Multiple(() => { - Assert.That(IC.Eq(tree[3, 0]), Is.True); - Assert.That(IC.Eq(tree[3, 1], 3), Is.True); - Assert.That(IC.Eq(tree[3, 2], 3, 4), Is.True); - Assert.That(IC.Eq(tree[3, 3], 3, 4, 4), Is.True); - Assert.That(IC.Eq(tree[3, 4], 3, 4, 4, 5), Is.True); - Assert.That(IC.Eq(tree[4, 0]), Is.True); - Assert.That(IC.Eq(tree[4, 1], 4), Is.True); - Assert.That(IC.Eq(tree[4, 2], 4, 4), Is.True); - Assert.That(IC.Eq(tree[4, 3], 4, 4, 5), Is.True); - Assert.That(IC.Eq(tree[4, 4], 4, 4, 5, 6), Is.True); - Assert.That(IC.Eq(tree[5, 0]), Is.True); - Assert.That(IC.Eq(tree[5, 1], 4), Is.True); - Assert.That(IC.Eq(tree[5, 2], 4, 5), Is.True); - Assert.That(IC.Eq(tree[5, 3], 4, 5, 6), Is.True); - Assert.That(IC.Eq(tree[5, 4], 4, 5, 6, 7), Is.True); - Assert.That(IC.Eq(tree[5, 6], 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(tree[3, 0], Is.Empty); + Assert.That(tree[3, 1], Is.EqualTo(new[] { 3 })); + Assert.That(tree[3, 2], Is.EqualTo(new[] { 3, 4 })); + Assert.That(tree[3, 3], Is.EqualTo(new[] { 3, 4, 4 })); + Assert.That(tree[3, 4], Is.EqualTo(new[] { 3, 4, 4, 5 })); + Assert.That(tree[4, 0], Is.Empty); + Assert.That(tree[4, 1], Is.EqualTo(new[] { 4 })); + Assert.That(tree[4, 2], Is.EqualTo(new[] { 4, 4 })); + Assert.That(tree[4, 3], Is.EqualTo(new[] { 4, 4, 5 })); + Assert.That(tree[4, 4], Is.EqualTo(new[] { 4, 4, 5, 6 })); + Assert.That(tree[5, 0], Is.Empty); + Assert.That(tree[5, 1], Is.EqualTo(new[] { 4 })); + Assert.That(tree[5, 2], Is.EqualTo(new[] { 4, 5 })); + Assert.That(tree[5, 3], Is.EqualTo(new[] { 4, 5, 6 })); + Assert.That(tree[5, 4], Is.EqualTo(new[] { 4, 5, 6, 7 })); + Assert.That(tree[5, 6], Is.EqualTo(new[] { 4, 5, 6, 7, 8, 9 })); }); } [Test] public void GetRangeBug20090616() { - C5.TreeBag tree = new() { - 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 3.0, 4.0 }; + TreeBag tree = [ + 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 3.0, 4.0 ]; for (int start = 0; start <= tree.Count - 2; start++) { double[] range = tree[start, 2].ToArray(); @@ -3394,29 +3341,29 @@ public void GetRangeBackwards() { Assert.Multiple(() => { - Assert.That(IC.Eq(tree[3, 0].Backwards()), Is.True); - Assert.That(IC.Eq(tree[3, 1].Backwards(), 3), Is.True); - Assert.That(IC.Eq(tree[3, 2].Backwards(), 4, 3), Is.True); - Assert.That(IC.Eq(tree[3, 3].Backwards(), 4, 4, 3), Is.True); - Assert.That(IC.Eq(tree[3, 4].Backwards(), 5, 4, 4, 3), Is.True); - Assert.That(IC.Eq(tree[4, 0].Backwards()), Is.True); - Assert.That(IC.Eq(tree[4, 1].Backwards(), 4), Is.True); - Assert.That(IC.Eq(tree[4, 2].Backwards(), 4, 4), Is.True); - Assert.That(IC.Eq(tree[4, 3].Backwards(), 5, 4, 4), Is.True); - Assert.That(IC.Eq(tree[4, 4].Backwards(), 6, 5, 4, 4), Is.True); - Assert.That(IC.Eq(tree[5, 0].Backwards()), Is.True); - Assert.That(IC.Eq(tree[5, 1].Backwards(), 4), Is.True); - Assert.That(IC.Eq(tree[5, 2].Backwards(), 5, 4), Is.True); - Assert.That(IC.Eq(tree[5, 3].Backwards(), 6, 5, 4), Is.True); - Assert.That(IC.Eq(tree[5, 4].Backwards(), 7, 6, 5, 4), Is.True); + Assert.That(tree[3, 0].Backwards(), Is.Empty); + Assert.That(tree[3, 1].Backwards(), Is.EqualTo(new[] { 3 })); + Assert.That(tree[3, 2].Backwards(), Is.EqualTo(new[] { 4, 3 })); + Assert.That(tree[3, 3].Backwards(), Is.EqualTo(new[] { 4, 4, 3 })); + Assert.That(tree[3, 4].Backwards(), Is.EqualTo(new[] { 5, 4, 4, 3 })); + Assert.That(tree[4, 0].Backwards(), Is.Empty); + Assert.That(tree[4, 1].Backwards(), Is.EqualTo(new[] { 4 })); + Assert.That(tree[4, 2].Backwards(), Is.EqualTo(new[] { 4, 4 })); + Assert.That(tree[4, 3].Backwards(), Is.EqualTo(new[] { 5, 4, 4 })); + Assert.That(tree[4, 4].Backwards(), Is.EqualTo(new[] { 6, 5, 4, 4 })); + Assert.That(tree[5, 0].Backwards(), Is.Empty); + Assert.That(tree[5, 1].Backwards(), Is.EqualTo(new[] { 4 })); + Assert.That(tree[5, 2].Backwards(), Is.EqualTo(new[] { 5, 4 })); + Assert.That(tree[5, 3].Backwards(), Is.EqualTo(new[] { 6, 5, 4 })); + Assert.That(tree[5, 4].Backwards(), Is.EqualTo(new[] { 7, 6, 5, 4 })); }); } [Test] public void GetRangeBackwardsBug20090616() { - C5.TreeBag tree = new() { - 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 3.0, 4.0 }; + TreeBag tree = [ + 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 3.0, 4.0 ]; for (int start = 0; start <= tree.Count - 2; start++) { double[] range = tree[start, 2].Backwards().ToArray(); @@ -3477,7 +3424,7 @@ public void Init() { dit = new TreeBag(SCG.Comparer.Default, EqualityComparer.Default); dat = new TreeBag(SCG.Comparer.Default, EqualityComparer.Default); - dut = new TreeBag(new RevIC(), EqualityComparer.Default); + dut = new TreeBag(new ReverseIntegerComparer(), EqualityComparer.Default); } @@ -3591,7 +3538,7 @@ public void Init() { dit = new TreeBag(SCG.Comparer.Default, EqualityComparer.Default); dat = new TreeBag(SCG.Comparer.Default, EqualityComparer.Default); - dut = new TreeBag(new RevIC(), EqualityComparer.Default); + dut = new TreeBag(new ReverseIntegerComparer(), EqualityComparer.Default); } diff --git a/C5.Tests/Trees/Dictionary.cs b/C5.Tests/Trees/Dictionary.cs index 50f39811..4a9cab07 100644 --- a/C5.Tests/Trees/Dictionary.cs +++ b/C5.Tests/Trees/Dictionary.cs @@ -47,7 +47,7 @@ public class RBDict [SetUp] - public void Init() { dict = new TreeDictionary(new SC()); } + public void Init() { dict = new TreeDictionary(StringComparer.InvariantCulture); } [TearDown] @@ -63,7 +63,7 @@ public void NullEqualityComparerinConstructor1() public void Choose() { dict.Add("YES", "NO"); - Assert.That(dict.Choose(), Is.EqualTo(new System.Collections.Generic.KeyValuePair("YES", "NO"))); + Assert.That(dict.Choose(), Is.EqualTo(new SCG.KeyValuePair("YES", "NO"))); } [Test] @@ -99,7 +99,7 @@ public void Pred2() dict.Add("E", "3"); Assert.Multiple(() => { - Assert.That(dict.TryPredecessor("B", out System.Collections.Generic.KeyValuePair res), Is.True); + Assert.That(dict.TryPredecessor("B", out SCG.KeyValuePair res), Is.True); Assert.That(res.Value, Is.EqualTo("1")); Assert.That(dict.TryPredecessor("C", out res), Is.True); Assert.That(res.Value, Is.EqualTo("1")); @@ -229,7 +229,7 @@ public class GuardedSortedDictionaryTest [SetUp] public void Init() { - ISortedDictionary dict = new TreeDictionary(new SC()) + ISortedDictionary dict = new TreeDictionary(StringComparer.InvariantCulture) { { "A", "1" }, { "C", "2" }, @@ -262,7 +262,7 @@ public void Pred2() { Assert.Multiple(() => { - Assert.That(dict.TryPredecessor("B", out System.Collections.Generic.KeyValuePair res), Is.True); + Assert.That(dict.TryPredecessor("B", out SCG.KeyValuePair res), Is.True); Assert.That(res.Value, Is.EqualTo("1")); Assert.That(dict.TryPredecessor("C", out res), Is.True); Assert.That(res.Value, Is.EqualTo("1")); @@ -360,7 +360,7 @@ public class Enumerators [SetUp] public void Init() { - dict = new TreeDictionary(new SC()) + dict = new TreeDictionary(StringComparer.InvariantCulture) { ["S"] = "A", ["T"] = "B", @@ -480,12 +480,12 @@ public void NormalUse() Assert.Multiple(() => { Assert.That(dictEnum.MoveNext(), Is.True); - Assert.That(new System.Collections.Generic.KeyValuePair("R", "C"), Is.EqualTo(dictEnum.Current)); + Assert.That(new SCG.KeyValuePair("R", "C"), Is.EqualTo(dictEnum.Current)); }); Assert.That(dictEnum.MoveNext(), Is.True); - Assert.That(new System.Collections.Generic.KeyValuePair("S", "A"), Is.EqualTo(dictEnum.Current)); + Assert.That(new SCG.KeyValuePair("S", "A"), Is.EqualTo(dictEnum.Current)); Assert.That(dictEnum.MoveNext(), Is.True); - Assert.That(new System.Collections.Generic.KeyValuePair("T", "B"), Is.EqualTo(dictEnum.Current)); + Assert.That(new SCG.KeyValuePair("T", "B"), Is.EqualTo(dictEnum.Current)); Assert.That(dictEnum.MoveNext(), Is.False); } } @@ -504,7 +504,7 @@ public class Simple [SetUp] public void Init() { - dict = new TreeDictionary(new SC()) + dict = new TreeDictionary(StringComparer.InvariantCulture) { ["S"] = "A", ["T"] = "B", diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index 7ea79bc1..4a3a27fa 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -13,8 +13,8 @@ public class GenericTesters [Test] public void TestEvents() { - TreeSet factory() { return new TreeSet(TenEqualityComparer.Default); } - new C5.Tests.Templates.Events.SortedIndexedTester>().Test(factory); + TreeSet factory() { return new TreeSet(TenEqualityComparer.Instance); } + new Templates.Events.SortedIndexedTester>().Test(factory); } } @@ -57,7 +57,7 @@ public class Combined [SetUp] public void Init() { - lst = new TreeSet>(new KeyValuePairComparer(new IC())); + lst = new TreeSet>(new KeyValuePairComparer(new IntegerComparer())); for (int i = 0; i < 10; i++) { lst.Add(new SCG.KeyValuePair(i, i + 30)); @@ -188,7 +188,7 @@ public class Ranges [SetUp] public void Init() { - c = new IC(); + c = new IntegerComparer(); tree = new TreeSet(c); for (int i = 1; i <= 10; i++) { @@ -240,35 +240,35 @@ public void Remove() int[] all = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]; tree.RemoveRangeFrom(18); - Assert.That(IC.Eq(tree, [2, 4, 6, 8, 10, 12, 14, 16]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16 })); tree.RemoveRangeFrom(28); - Assert.That(IC.Eq(tree, [2, 4, 6, 8, 10, 12, 14, 16]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16 })); tree.RemoveRangeFrom(2); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); } tree.RemoveRangeTo(10); - Assert.That(IC.Eq(tree, [10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeTo(2); - Assert.That(IC.Eq(tree, [10, 12, 14, 16, 18, 20]), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeTo(21); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); } tree.RemoveRangeFromTo(4, 8); - Assert.That(IC.Eq(tree, 2, 8, 10, 12, 14, 16, 18, 20), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 2, 8, 10, 12, 14, 16, 18, 20 })); tree.RemoveRangeFromTo(14, 28); - Assert.That(IC.Eq(tree, 2, 8, 10, 12), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 2, 8, 10, 12 })); tree.RemoveRangeFromTo(0, 9); - Assert.That(IC.Eq(tree, 10, 12), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 10, 12 })); tree.RemoveRangeFromTo(0, 81); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); } [Test] @@ -278,35 +278,34 @@ public void Normal() Assert.Multiple(() => { - Assert.That(IC.Eq(tree, all), Is.True); - Assert.That(IC.Eq(tree.RangeAll(), all), Is.True); + Assert.That(tree, Is.EqualTo(all)); + Assert.That(tree.RangeAll(), Is.EqualTo(all)); Assert.That(tree.RangeAll(), Has.Count.EqualTo(10)); - Assert.That(IC.Eq(tree.RangeFrom(11), [12, 14, 16, 18, 20]), Is.True); + Assert.That(tree.RangeFrom(11), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); Assert.That(tree.RangeFrom(11), Has.Count.EqualTo(5)); - Assert.That(IC.Eq(tree.RangeFrom(12), [12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(2), all), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(1), all), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(21), []), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(20), [20]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(8), [2, 4, 6]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(7), [2, 4, 6]), Is.True); + Assert.That(tree.RangeFrom(12), Is.EqualTo(new[] { 12, 14, 16, 18, 20 })); + Assert.That(tree.RangeFrom(2), Is.EqualTo(all)); + Assert.That(tree.RangeFrom(1), Is.EqualTo(all)); + Assert.That(tree.RangeFrom(21), Is.Empty); + Assert.That(tree.RangeFrom(20), Is.EqualTo(new[] { 20 })); + Assert.That(tree.RangeTo(8), Is.EqualTo(new[] { 2, 4, 6 })); + Assert.That(tree.RangeTo(7), Is.EqualTo(new[] { 2, 4, 6 })); Assert.That(tree.RangeTo(7), Has.Count.EqualTo(3)); - Assert.That(IC.Eq(tree.RangeTo(2), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(1), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(3), [2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(20), [2, 4, 6, 8, 10, 12, 14, 16, 18]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(21), all), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(7, 12), [8, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 11), [6, 8, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(1, 12), [2, 4, 6, 8, 10]), Is.True); + Assert.That(tree.RangeTo(2), Is.Empty); + Assert.That(tree.RangeTo(1), Is.Empty); + Assert.That(tree.RangeTo(3), Is.EqualTo(new[] { 2 })); + Assert.That(tree.RangeTo(20), Is.EqualTo(new[] { 2, 4, 6, 8, 10, 12, 14, 16, 18 })); + Assert.That(tree.RangeTo(21), Is.EqualTo(all)); + Assert.That(tree.RangeFromTo(7, 12), Is.EqualTo(new[] { 8, 10 })); + Assert.That(tree.RangeFromTo(6, 11), Is.EqualTo(new[] { 6, 8, 10 })); + Assert.That(tree.RangeFromTo(1, 12), Is.EqualTo(new[] { 2, 4, 6, 8, 10 })); Assert.That(tree.RangeFromTo(1, 12), Has.Count.EqualTo(5)); - Assert.That(IC.Eq(tree.RangeFromTo(2, 12), [2, 4, 6, 8, 10]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 21), [6, 8, 10, 12, 14, 16, 18, 20]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 20), [6, 8, 10, 12, 14, 16, 18]), Is.True); + Assert.That(tree.RangeFromTo(2, 12), Is.EqualTo(new[] { 2, 4, 6, 8, 10 })); + Assert.That(tree.RangeFromTo(6, 21), Is.EqualTo(new[] { 6, 8, 10, 12, 14, 16, 18, 20 })); + Assert.That(tree.RangeFromTo(6, 20), Is.EqualTo(new[] { 6, 8, 10, 12, 14, 16, 18 })); }); } - [Test] public void Backwards() { @@ -315,27 +314,27 @@ public void Backwards() Assert.Multiple(() => { - Assert.That(IC.Eq(tree, all), Is.True); - Assert.That(IC.Eq(tree.RangeAll().Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(11).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(12).Backwards(), [20, 18, 16, 14, 12]), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(2).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(1).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(21).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeFrom(20).Backwards(), [20]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(8).Backwards(), [6, 4, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(7).Backwards(), [6, 4, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(2).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(1).Backwards(), []), Is.True); - Assert.That(IC.Eq(tree.RangeTo(3).Backwards(), [2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(20).Backwards(), [18, 16, 14, 12, 10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeTo(21).Backwards(), lla), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(7, 12).Backwards(), [10, 8]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 11).Backwards(), [10, 8, 6]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(1, 12).Backwards(), [10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(2, 12).Backwards(), [10, 8, 6, 4, 2]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 21).Backwards(), [20, 18, 16, 14, 12, 10, 8, 6]), Is.True); - Assert.That(IC.Eq(tree.RangeFromTo(6, 20).Backwards(), [18, 16, 14, 12, 10, 8, 6]), Is.True); + Assert.That(tree, Is.EqualTo(all)); + Assert.That(tree.RangeAll().Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(11).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(tree.RangeFrom(12).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12 })); + Assert.That(tree.RangeFrom(2).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(1).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFrom(21).Backwards(), Is.Empty); + Assert.That(tree.RangeFrom(20).Backwards(), Is.EqualTo(new[] { 20 })); + Assert.That(tree.RangeTo(8).Backwards(), Is.EqualTo(new[] { 6, 4, 2 })); + Assert.That(tree.RangeTo(7).Backwards(), Is.EqualTo(new[] { 6, 4, 2 })); + Assert.That(tree.RangeTo(2).Backwards(), Is.Empty); + Assert.That(tree.RangeTo(1).Backwards(), Is.Empty); + Assert.That(tree.RangeTo(3).Backwards(), Is.EqualTo(new[] { 2 })); + Assert.That(tree.RangeTo(20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 8, 6, 4, 2 })); + Assert.That(tree.RangeTo(21).Backwards(), Is.EqualTo(lla)); + Assert.That(tree.RangeFromTo(7, 12).Backwards(), Is.EqualTo(new[] { 10, 8 })); + Assert.That(tree.RangeFromTo(6, 11).Backwards(), Is.EqualTo(new[] { 10, 8, 6 })); + Assert.That(tree.RangeFromTo(1, 12).Backwards(), Is.EqualTo(new[] { 10, 8, 6, 4, 2 })); + Assert.That(tree.RangeFromTo(2, 12).Backwards(), Is.EqualTo(new[] { 10, 8, 6, 4, 2 })); + Assert.That(tree.RangeFromTo(6, 21).Backwards(), Is.EqualTo(new[] { 20, 18, 16, 14, 12, 10, 8, 6 })); + Assert.That(tree.RangeFromTo(6, 20).Backwards(), Is.EqualTo(new[] { 18, 16, 14, 12, 10, 8, 6 })); }); } @@ -375,7 +374,7 @@ public class BagItf [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); for (int i = 10; i < 20; i++) { tree.Add(i); @@ -415,7 +414,7 @@ public class Div [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } @@ -508,7 +507,7 @@ public class FindOrAdd [SetUp] public void Init() { - bag = new TreeSet>(new KeyValuePairComparer(new IC())); + bag = new TreeSet>(new KeyValuePairComparer(new IntegerComparer())); } @@ -545,7 +544,7 @@ public class FindPredicate [SetUp] public void Init() { - list = new TreeSet(TenEqualityComparer.Default); + list = new TreeSet(TenEqualityComparer.Instance); pred = delegate (int i) { return i % 5 == 0; }; } @@ -607,7 +606,7 @@ public class UniqueItems private TreeSet list; [SetUp] - public void Init() { list = new TreeSet(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -617,14 +616,14 @@ public void Test() { Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems()), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities()), Is.True); + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); }); list.AddAll([7, 9, 7]); Assert.Multiple(() => { - Assert.That(IC.SetEq(list.UniqueItems(), 7, 9), Is.True); - Assert.That(IC.SetEq(list.ItemMultiplicities(), 7, 1, 9, 1), Is.True); + Assert.That(list.UniqueItems(), Is.EquivalentTo(new[] { 7, 9 })); + Assert.That(list.ItemMultiplicities(), Is.EquivalentTo(new[] { SCG.KeyValuePair.Create(7, 1), SCG.KeyValuePair.Create(9, 1) })); }); } } @@ -635,11 +634,10 @@ public class ArrayTest private TreeSet tree; private int[] a; - [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); a = new int[10]; for (int i = 0; i < 10; i++) { @@ -647,58 +645,36 @@ public void Init() } } - [TearDown] public void Dispose() { tree.Dispose(); } - - private string aeq(int[] a, params int[] b) - { - if (a.Length != b.Length) - { - return "Lengths differ: " + a.Length + " != " + b.Length; - } - - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) - { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); - } - } - return "Alles klar"; - } - - [Test] public void ToArray() { - Assert.That(aeq(tree.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.Empty); tree.Add(7); tree.Add(4); - Assert.That(aeq(tree.ToArray(), 4, 7), Is.EqualTo("Alles klar")); + Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); } - [Test] public void CopyTo() { tree.CopyTo(a, 1); - Assert.That(aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(6); tree.CopyTo(a, 2); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009 })); tree.Add(4); tree.Add(9); tree.CopyTo(a, 4); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 1009), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 1009 })); tree.Clear(); tree.Add(7); tree.CopyTo(a, 9); - Assert.That(aeq(a, 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7), Is.EqualTo("Alles klar")); + Assert.That(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); } - [Test] public void CopyToBad() { @@ -728,7 +704,7 @@ public class Remove [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); for (int i = 10; i < 20; i++) { tree.Add(i); @@ -938,7 +914,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } @@ -1199,7 +1175,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } private void loadup() @@ -1268,7 +1244,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } private void populate() @@ -1422,7 +1398,7 @@ public class Enumerator [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1485,7 +1461,7 @@ public class RangeEnumerator [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -1550,7 +1526,7 @@ public class Navigation [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeSet(ic); for (int i = 0; i <= 20; i++) { @@ -1564,26 +1540,22 @@ public void Init() } } - private bool twomodeleven(int i) { return i % 11 == 2; } - [Test] public void InternalEnum() { - Assert.That(IC.Eq(snap.FindAll(new Func(twomodeleven)), 13, 35), Is.True); + Assert.That(snap.FindAll(new Func(twomodeleven)), Is.EqualTo(new[] { 13, 35 })); } - public void MoreCut() { } [Test] public void Cut() { - Assert.Multiple(() => { Assert.That(snap.Cut(new HigherOrder.CubeRoot(64), out int lo, out bool lv, out int hi, out bool hv), Is.False); @@ -1609,9 +1581,9 @@ public void Range() { Assert.Multiple(() => { - Assert.That(IC.Eq(snap.RangeFromTo(5, 16), 5, 7, 9, 11, 13, 15), Is.True); - Assert.That(IC.Eq(snap.RangeFromTo(5, 17), 5, 7, 9, 11, 13, 15), Is.True); - Assert.That(IC.Eq(snap.RangeFromTo(6, 16), 7, 9, 11, 13, 15), Is.True); + Assert.That(snap.RangeFromTo(5, 16), Is.EqualTo(new[] { 5, 7, 9, 11, 13, 15 })); + Assert.That(snap.RangeFromTo(5, 17), Is.EqualTo(new[] { 5, 7, 9, 11, 13, 15 })); + Assert.That(snap.RangeFromTo(6, 16), Is.EqualTo(new[] { 7, 9, 11, 13, 15 })); }); //Assert.AreEqual(snap.RangeFromTo(6, 16).Count, 5); } @@ -1807,7 +1779,7 @@ public class Single [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeSet(ic); for (int i = 0; i < 10; i++) { @@ -1830,7 +1802,7 @@ public void EnumerationWithAdd() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); } @@ -1846,14 +1818,14 @@ public void Remove() Assert.Multiple(() => { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); tree.Remove(19); Assert.Multiple(() => { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); } @@ -1875,14 +1847,14 @@ public void RemoveNormal() { Assert.That(tree.Remove(-20), Is.False); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //No demote case, with move_item Assert.That(tree.Remove(20), Is.True); Assert.That(tree.Check("T1"), Is.True); }); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Remove(20), Is.False); //plain case 2 @@ -1892,26 +1864,26 @@ public void RemoveNormal() Assert.That(tree.Remove(14), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //case 1b Assert.That(tree.Remove(25), Is.True); }); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //case 1c Assert.That(tree.Remove(29), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //1a (terminating) Assert.That(tree.Remove(10), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //2+1b Assert.That(tree.Remove(12), Is.True); @@ -1921,7 +1893,7 @@ public void RemoveNormal() Assert.That(tree.Remove(11), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //1a+1b Assert.That(tree.Remove(18), Is.True); @@ -1930,7 +1902,7 @@ public void RemoveNormal() }); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); //2+1c for (int i = 0; i < 10; i++) @@ -1946,7 +1918,7 @@ public void RemoveNormal() Assert.That(tree.Remove(40), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); // Assert.That(tree.Remove(16), Is.True); @@ -1971,14 +1943,14 @@ public void RemoveNormal() Assert.That(tree.Remove(48), Is.True); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); //Empty tree: Assert.That(tree.Remove(26), Is.False); Assert.That(tree.Check("Normal test 1"), Is.True, "Bad tree"); Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); } @@ -1991,21 +1963,21 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); tree.Add(10); Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); tree.Add(16); Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); @@ -2015,7 +1987,7 @@ public void Add() { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); }); for (int i = 1; i < 4; i++) { @@ -2025,7 +1997,7 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); @@ -2034,12 +2006,11 @@ public void Add() Assert.Multiple(() => { Assert.That(snap.Check("M"), Is.True, "Bad snap!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); }); } - [Test] public void Clear() { @@ -2051,7 +2022,7 @@ public void Clear() { Assert.That(snap.Check("Snap"), Is.True, "Bad snap!"); Assert.That(tree.Check("Tree"), Is.True, "Bad tree!"); - Assert.That(IC.Eq(snap, orig), Is.True, "Snap was changed!"); + Assert.That(snap, Is.EqualTo(orig), "Snap was changed!"); Assert.That(tree, Is.Empty); }); } @@ -2097,7 +2068,7 @@ public class Multiple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeSet(ic); for (int i = 0; i < 10; i++) { @@ -2133,9 +2104,9 @@ public void First() Assert.Multiple(() => { - Assert.That(IC.Eq(snaps[3], snap3), Is.True, "Snap 3 was changed!"); - Assert.That(IC.Eq(snaps[7], snap7), Is.True, "Snap 7 was changed!"); - Assert.That(IC.Eq(tree, res), Is.True); + Assert.That(snaps[3], Is.EqualTo(snap3), "Snap 3 was changed!"); + Assert.That(snaps[7], Is.EqualTo(snap7), "Snap 7 was changed!"); + Assert.That(tree, Is.EqualTo(res)); Assert.That(tree.Check("B"), Is.True); Assert.That(snaps[3].Check("B"), Is.True); Assert.That(snaps[7].Check("B"), Is.True); @@ -2171,8 +2142,8 @@ public void CollectingTheMaster() Assert.Multiple(() => { - Assert.That(IC.Eq(snaps[3], snap3), Is.True, "Snap 3 was changed!"); - Assert.That(IC.Eq(snaps[7], snap7), Is.True, "Snap 7 was changed!"); + Assert.That(snaps[3], Is.EqualTo(snap3), "Snap 3 was changed!"); + Assert.That(snaps[7], Is.EqualTo(snap7), "Snap 7 was changed!"); Assert.That(snaps[3].Check("B"), Is.True); Assert.That(snaps[7].Check("B"), Is.True); }); @@ -2227,7 +2198,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeSet(ic); } @@ -2399,13 +2370,13 @@ public void FindAll() [Test] public void Map() { - Assert.That(tree.Map(new Func(themap), new SC()), Is.Empty); + Assert.That(tree.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); for (int i = 0; i < 11; i++) { tree.Add(i * i * i); } - IIndexedSorted res = tree.Map(new Func(themap), new SC()); + IIndexedSorted res = tree.Map(new Func(themap), StringComparer.InvariantCulture); Assert.Multiple(() => { @@ -2432,7 +2403,7 @@ public void BadMap() var exception = Assert.Throws(() => { - ISorted res = tree.Map(new Func(badmap), new SC()); + ISorted res = tree.Map(new Func(badmap), StringComparer.InvariantCulture); }); Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); } @@ -2469,11 +2440,11 @@ public void CutInt() Assert.Multiple(() => { - Assert.That(tree.Cut(new IC(3), out int low, out bool lval, out int high, out bool hval), Is.False); + Assert.That(tree.Cut(new IntegerComparer(3), out int low, out bool lval, out int high, out bool hval), Is.False); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(4)); Assert.That(low, Is.EqualTo(2)); - Assert.That(tree.Cut(new IC(6), out low, out lval, out high, out hval), Is.True); + Assert.That(tree.Cut(new IntegerComparer(6), out low, out lval, out high, out hval), Is.True); Assert.That(lval && hval, Is.True); Assert.That(high, Is.EqualTo(8)); Assert.That(low, Is.EqualTo(4)); @@ -2565,13 +2536,13 @@ public class AddAll [SetUp] - public void Init() { tree = new TreeSet(new IC()); } + public void Init() { tree = new TreeSet(new IntegerComparer()); } [Test] public void EmptyEmpty() { - tree.AddAll(new FunEnumerable(0, new Func(sqr))); + tree.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } @@ -2585,7 +2556,7 @@ public void SomeEmpty() tree.Add(i); } - tree.AddAll(new FunEnumerable(0, new Func(sqr))); + tree.AddAll(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(5)); Assert.That(tree.Check(), Is.True); } @@ -2594,7 +2565,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - tree.AddAll(new FunEnumerable(4, new Func(sqr))); + tree.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(4)); Assert.Multiple(() => { @@ -2615,12 +2586,12 @@ public void SomeSome() tree.Add(i); } - tree.AddAll(new FunEnumerable(4, new Func(sqr))); + tree.AddAll(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 4, 5, 6, 7, 8, 9 })); }); } @@ -2643,13 +2614,13 @@ public class AddSorted [SetUp] - public void Init() { tree = new TreeSet(new IC()); } + public void Init() { tree = new TreeSet(new IntegerComparer()); } [Test] public void EmptyEmpty() { - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } @@ -2664,7 +2635,7 @@ public void SomeEmpty() tree.Add(i); } - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(0, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(5)); Assert.That(tree.Check(), Is.True); } @@ -2674,7 +2645,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - tree.AddSorted(new FunEnumerable(4, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(4)); Assert.Multiple(() => { @@ -2696,19 +2667,19 @@ public void SomeSome() tree.Add(i); } - tree.AddSorted(new FunEnumerable(4, new Func(sqr))); + tree.AddSorted(new FuncEnumerable(4, new Func(sqr))); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 4, 5, 6, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 4, 5, 6, 7, 8, 9 })); }); } [Test] public void EmptyBad() { - var exception = Assert.Throws(() => tree.AddSorted(new FunEnumerable(9, new Func(bad)))); + var exception = Assert.Throws(() => tree.AddSorted(new FuncEnumerable(9, new Func(bad)))); Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); } @@ -2726,8 +2697,8 @@ public class Rest [SetUp] public void Init() { - tree = new TreeSet(new IC()); - tree2 = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); + tree2 = new TreeSet(new IntegerComparer()); for (int i = 0; i < 10; i++) { tree.Add(i); @@ -2748,28 +2719,28 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(3, 7)); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(13, 17)); Assert.That(tree, Has.Count.EqualTo(8)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); }); tree.RemoveAll(tree2.RangeFromTo(3, 17)); Assert.That(tree, Has.Count.EqualTo(7)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 0, 1, 2, 3, 5, 7, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); }); for (int i = 0; i < 10; i++) { @@ -2781,7 +2752,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2794,28 +2765,28 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4, 6, 8), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4, 6, 8 })); }); tree.RetainAll(tree2.RangeFromTo(1, 17)); Assert.That(tree, Has.Count.EqualTo(3)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4, 6, 8), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4, 6, 8 })); }); tree.RetainAll(tree2.RangeFromTo(3, 5)); Assert.That(tree, Has.Count.EqualTo(1)); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree, 4), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 4 })); }); tree.RetainAll(tree2.RangeFromTo(7, 17)); Assert.That(tree, Is.Empty); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -2827,7 +2798,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); for (int i = 0; i < 10; i++) { @@ -2839,7 +2810,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2869,21 +2840,21 @@ public void RemoveInterval() { Assert.That(tree.Check(), Is.True); Assert.That(tree, Has.Count.EqualTo(6)); - Assert.That(IC.Eq(tree, 0, 1, 2, 7, 8, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 2, 7, 8, 9 })); }); tree.RemoveInterval(2, 3); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); Assert.That(tree, Has.Count.EqualTo(3)); - Assert.That(IC.Eq(tree, 0, 1, 9), Is.True); + Assert.That(tree, Is.EqualTo(new[] { 0, 1, 9 })); }); tree.RemoveInterval(0, 3); Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); Assert.That(tree, Is.Empty); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2913,9 +2884,9 @@ public void RemoveRangeBad3() public void GetRange() { SCG.IEnumerable e = tree[3, 3]; - Assert.That(IC.Eq(e, 3, 4, 5), Is.True); + Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); e = tree[3, 0]; - Assert.That(IC.Eq(e), Is.True); + Assert.That(e, Is.Empty); } [Test] @@ -3018,7 +2989,7 @@ public void SafeUnSafe() [SetUp] - public void Init() { tree = new TreeSet(new IC()); } + public void Init() { tree = new TreeSet(new IntegerComparer()); } private void unsafe1() @@ -3105,7 +3076,7 @@ public class ConcurrentQueries [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); for (int i = 0; i < sz; i++) { tree.Add(i); @@ -3189,7 +3160,7 @@ public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new TreeSet(new RevIC(), EqualityComparer.Default); + dut = new TreeSet(new ReverseIntegerComparer(), EqualityComparer.Default); } @@ -3302,7 +3273,7 @@ public void Init() { dit = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); dat = new TreeSet(SCG.Comparer.Default, EqualityComparer.Default); - dut = new TreeSet(new RevIC(), EqualityComparer.Default); + dut = new TreeSet(new ReverseIntegerComparer(), EqualityComparer.Default); } diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index 2f5ca709..8561bfca 100644 --- a/C5.Tests/WrappersTest.cs +++ b/C5.Tests/WrappersTest.cs @@ -19,7 +19,7 @@ public class IList_ [SetUp] public void Init() { - list = new ArrayList(TenEqualityComparer.Default); + list = new ArrayList(TenEqualityComparer.Instance); guarded = new GuardedList(list); seen = new CollectionEventList(System.Collections.Generic.EqualityComparer.Default); } @@ -491,7 +491,7 @@ public class StackQueue [SetUp] public void Init() { - list = new ArrayList(TenEqualityComparer.Default); + list = new ArrayList(TenEqualityComparer.Instance); guarded = new GuardedList(list); seen = new CollectionEventList(System.Collections.Generic.EqualityComparer.Default); } @@ -582,7 +582,7 @@ public void NoExc() Assert.Multiple(() => { Assert.That(wrapped[1], Is.EqualTo(6)); - Assert.That(IC.Eq(wrapped[1, 2], 6, 5), Is.True); + Assert.That(wrapped[1, 2], Is.EqualTo(new[] { 6, 5 })); }); // bool is4(int i) { return i == 4; } @@ -611,7 +611,7 @@ public void NoExc() wrapped.CopyTo(extarray, 1); Assert.Multiple(() => { - Assert.That(IC.Eq(extarray, 0, 4, 6, 5, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 4, 6, 5, 0 })); Assert.That(wrapped, Has.Count.EqualTo(3)); }); Assert.Multiple(() => @@ -621,7 +621,7 @@ public void NoExc() Assert.That(wrapped.DuplicatesByCounting, Is.EqualTo(false)); Assert.That(wrapped.EqualityComparer, Is.EqualTo(System.Collections.Generic.EqualityComparer.Default)); Assert.That(wrapped.Exists(is4), Is.EqualTo(true)); - Assert.That(IC.Eq(wrapped.Filter(is4), 4), Is.True); + Assert.That(wrapped.Filter(is4), Is.EqualTo(new[] { 4 })); }); int j = 5; Assert.Multiple(() => @@ -650,7 +650,7 @@ public void NoExc() Assert.That(wrapped.ListenableEvents, Is.EqualTo(EventType.None)); }); string i2s(int i) { return string.Format("T{0}", i); } - Assert.That(wrapped.Map(i2s).ToString(), Is.EqualTo("[ 0:T4, 1:T6, 2:T5 ]")); + Assert.That(wrapped.Map(i2s).ToString(), Is.EqualTo("[ 0:T4, 1:T6, 2:T5 ]")); Assert.That(wrapped.Offset, Is.EqualTo(0)); wrapped.Reverse(); Assert.That(wrapped.ToString(), Is.EqualTo("[ 0:5, 1:6, 2:4 ]")); @@ -662,14 +662,14 @@ public void NoExc() Assert.Multiple(() => { Assert.That(wrapped.ToString(), Is.EqualTo("[ 0:4, 1:5, 2:6 ]")); - Assert.That(IC.Eq(wrapped.ToArray(), 4, 5, 6), Is.True); + Assert.That(wrapped.ToArray(), Is.EquivalentTo(new[] { 4, 5, 6 })); Assert.That(wrapped.ToString("L4", null), Is.EqualTo("[ ... ]")); Assert.That(wrapped.Underlying, Is.EqualTo(null)); - Assert.That(IC.SetEq(wrapped.UniqueItems(), 4, 5, 6), Is.True); + Assert.That(wrapped.UniqueItems(), Is.EquivalentTo(new[] { 4, 5, 6 })); Assert.That(wrapped.UnsequencedEquals(other), Is.True); }); wrapped.Shuffle(); - Assert.That(IC.SetEq(wrapped.UniqueItems(), 4, 5, 6), Is.True); + Assert.That(wrapped.UniqueItems(), Is.EquivalentTo(new[] { 4, 5, 6 })); } [Test] @@ -730,11 +730,9 @@ public void View() WrappedArray wrapped = (WrappedArray)outerwrapped.View(1, 3); Assert.Multiple(() => { - // Assert.That(wrapped[1], Is.EqualTo(6)); - Assert.That(IC.Eq(wrapped[1, 2], 6, 5), Is.True); + Assert.That(wrapped[1, 2], Is.EqualTo(new[] { 6, 5 })); }); - // bool is4(int i) { return i == 4; } Assert.Multiple(() => @@ -761,7 +759,7 @@ public void View() wrapped.CopyTo(extarray, 1); Assert.Multiple(() => { - Assert.That(IC.Eq(extarray, 0, 4, 6, 5, 0), Is.True); + Assert.That(extarray, Is.EqualTo(new[] { 0, 4, 6, 5, 0 })); Assert.That(wrapped, Has.Count.EqualTo(3)); }); Assert.Multiple(() => @@ -771,7 +769,7 @@ public void View() Assert.That(wrapped.DuplicatesByCounting, Is.EqualTo(false)); Assert.That(wrapped.EqualityComparer, Is.EqualTo(System.Collections.Generic.EqualityComparer.Default)); Assert.That(wrapped.Exists(is4), Is.EqualTo(true)); - Assert.That(IC.Eq(wrapped.Filter(is4), 4), Is.True); + Assert.That(wrapped.Filter(is4), Is.EqualTo(new[] { 4 })); }); int j = 5; Assert.Multiple(() => @@ -800,7 +798,7 @@ public void View() Assert.That(wrapped.ListenableEvents, Is.EqualTo(EventType.None)); }); string i2s(int i) { return string.Format("T{0}", i); } - Assert.That(wrapped.Map(i2s).ToString(), Is.EqualTo("[ 0:T4, 1:T6, 2:T5 ]")); + Assert.That(wrapped.Map(i2s).ToString(), Is.EqualTo("[ 0:T4, 1:T6, 2:T5 ]")); Assert.That(wrapped.Offset, Is.EqualTo(1)); wrapped.Reverse(); Assert.That(wrapped.ToString(), Is.EqualTo("[ 0:5, 1:6, 2:4 ]")); @@ -812,23 +810,21 @@ public void View() Assert.Multiple(() => { Assert.That(wrapped.ToString(), Is.EqualTo("[ 0:4, 1:5, 2:6 ]")); - Assert.That(IC.Eq(wrapped.ToArray(), 4, 5, 6), Is.True); + Assert.That(wrapped.ToArray(), Is.EqualTo(new[] { 4, 5, 6 })); Assert.That(wrapped.ToString("L4", null), Is.EqualTo("[ ... ]")); - // TODO: Below line removed as NUnit 3.0 test fails trying to enumerate... - // Assert.AreEqual(outerwrapped, wrapped.Underlying); - Assert.That(IC.SetEq(wrapped.UniqueItems(), 4, 5, 6), Is.True); + Assert.That(outerwrapped, Is.EqualTo(wrapped.Underlying)); + Assert.That(wrapped.UniqueItems(), Is.EquivalentTo(new[] { 4, 5, 6 })); Assert.That(wrapped.UnsequencedEquals(other), Is.True); - // Assert.That(wrapped.TrySlide(1), Is.True); - Assert.That(IC.Eq(wrapped, 5, 6, 7), Is.True); + Assert.That(wrapped.ToArray(), Is.EqualTo(new[] { 5, 6, 7 })); Assert.That(wrapped.TrySlide(-1, 2), Is.True); - Assert.That(IC.Eq(wrapped, 4, 5), Is.True); + Assert.That(wrapped.ToArray(), Is.EqualTo(new[] { 4, 5 })); Assert.That(wrapped.TrySlide(-2), Is.False); - Assert.That(IC.Eq(wrapped.Span(outerwrapped.ViewOf(7)), 4, 5, 6, 7), Is.True); + Assert.That(wrapped.Span(outerwrapped.ViewOf(7)), Is.EquivalentTo(new[] { 4, 5, 6, 7 })); }); // wrapped.Shuffle(); - Assert.That(IC.SetEq(wrapped.UniqueItems(), 4, 5), Is.True); + Assert.That(wrapped.UniqueItems(), Is.EquivalentTo(new[] { 4, 5 })); Assert.That(wrapped.IsValid, Is.True); wrapped.Dispose(); Assert.That(wrapped.IsValid, Is.False); diff --git a/C5.UserGuideExamples/AnagramHashBag.cs b/C5.UserGuideExamples/AnagramHashBag.cs index 0f882634..ca7253f5 100644 --- a/C5.UserGuideExamples/AnagramHashBag.cs +++ b/C5.UserGuideExamples/AnagramHashBag.cs @@ -118,7 +118,7 @@ private static SCG.IEnumerable FirstAnagramOnly(SCG.IEnumerable if (!classes.Find(ref anagram, out var anagramClass)) { - classes[anagram] = anagramClass = new TreeSet(); + classes[anagram] = anagramClass = []; } anagramClass.Add(s); diff --git a/C5.UserGuideExamples/AnagramTreeBag.cs b/C5.UserGuideExamples/AnagramTreeBag.cs index 88cd39c7..630a14fd 100644 --- a/C5.UserGuideExamples/AnagramTreeBag.cs +++ b/C5.UserGuideExamples/AnagramTreeBag.cs @@ -118,7 +118,7 @@ public static SCG.IEnumerable FirstAnagramOnly(SCG.IEnumerable s if (!classes.Find(ref anagram, out var anagramClass)) { - classes[anagram] = anagramClass = new TreeSet(); + classes[anagram] = anagramClass = []; } anagramClass.Add(s); diff --git a/C5.UserGuideExamples/Anagrams.cs b/C5.UserGuideExamples/Anagrams.cs index c8316173..a5cdcad0 100644 --- a/C5.UserGuideExamples/Anagrams.cs +++ b/C5.UserGuideExamples/Anagrams.cs @@ -125,7 +125,7 @@ private static SCG.IEnumerable FirstAnagramOnly(SCG.IEnumerable if (!classes.Find(ref anagram, out TreeSet anagramClass)) { - classes[anagram] = anagramClass = new TreeSet(); + classes[anagram] = anagramClass = []; } anagramClass.Add(s); diff --git a/C5.UserGuideExamples/BipartiteMatching.cs b/C5.UserGuideExamples/BipartiteMatching.cs index 889600c3..da481399 100644 --- a/C5.UserGuideExamples/BipartiteMatching.cs +++ b/C5.UserGuideExamples/BipartiteMatching.cs @@ -104,7 +104,7 @@ public BipartiteMatching(SCG.IEnumerable<(TLeftLabel, TRightLabel)> graph) HashSet ledges = newrnodes; if (!edges.FindOrAdd(edge.Item1, ref ledges)) { - newrnodes = new HashSet(); + newrnodes = []; } ledges.Add(rnode); } @@ -150,7 +150,7 @@ private void Compute() { Debug.Print("Start outer"); _foundAugmentingPath = false; - _endPoints = new HashSet(); + _endPoints = []; foreach (var rightNode in _rightNodes) { rightNode.BackRef = null; @@ -163,7 +163,7 @@ private void Compute() while (!_foundAugmentingPath && _endPoints.Count > 0) { var oldLayer = _endPoints; - _endPoints = new HashSet(); + _endPoints = []; foreach (var rb in oldLayer) { Search(rb.Match, rb.Origin); diff --git a/C5.UserGuideExamples/CollectionSanity.cs b/C5.UserGuideExamples/CollectionSanity.cs index 8de70d16..541cb376 100644 --- a/C5.UserGuideExamples/CollectionSanity.cs +++ b/C5.UserGuideExamples/CollectionSanity.cs @@ -16,12 +16,12 @@ public static void Main() col2.AddAll([7, 9, 13]); col3.AddAll([9, 7, 13]); - HashSet> hs1 = new() - { + HashSet> hs1 = + [ col1, col2, col3 - }; + ]; Console.WriteLine("hs1 is sane: {0}", EqualityComparerSanity>(hs1)); } diff --git a/C5.UserGuideExamples/CommonWords.cs b/C5.UserGuideExamples/CommonWords.cs index 0d26f985..dfc01d0b 100644 --- a/C5.UserGuideExamples/CommonWords.cs +++ b/C5.UserGuideExamples/CommonWords.cs @@ -40,7 +40,7 @@ private static void PrintMostCommon(int maxWords, string filename) var frequency = wordbag.ItemMultiplicities().ToArray(); Sorting.IntroSort(frequency, 0, frequency.Length, // Lexicographic ordering: decreasing frequency, then increasing string - ComparerFactory>.CreateComparer( + ComparerFactory>.CreateComparer( (p1, p2) => { int major = p2.Value.CompareTo(p1.Value); diff --git a/C5.UserGuideExamples/EventPatterns.cs b/C5.UserGuideExamples/EventPatterns.cs index 5f0ae534..10fccfe2 100644 --- a/C5.UserGuideExamples/EventPatterns.cs +++ b/C5.UserGuideExamples/EventPatterns.cs @@ -166,29 +166,16 @@ public static void UpdateEvent() } // Example class where objects may be equal yet display differently -internal class Teacher : IEquatable +internal class Teacher(string name, string subject) : IEquatable { - public string Name { get; } - public string Subject { get; } + public string Name { get; } = name; + public string Subject { get; } = subject; - public Teacher(string name, string subject) - { - Name = name; - Subject = subject; - } + public bool Equals(Teacher? that) => Subject == that?.Subject; - public bool Equals(Teacher that) - { - return Subject == that.Subject; - } + public override int GetHashCode() => Subject.GetHashCode(); - public override int GetHashCode() - { - return Subject.GetHashCode(); - } + public override string ToString() => $"{Name} [{Subject}]"; - public override string ToString() - { - return $"{Name} [{Subject}]"; - } + public override bool Equals(object? obj) => Equals(obj as Teacher); } diff --git a/C5.UserGuideExamples/Extensions.cs b/C5.UserGuideExamples/Extensions.cs index ee14c188..fec65e38 100644 --- a/C5.UserGuideExamples/Extensions.cs +++ b/C5.UserGuideExamples/Extensions.cs @@ -14,13 +14,10 @@ public static int Added(this ICollection coll, int x) public static SCG.IEnumerable Where(this ICollection coll, Expression> predicate) { - Console.WriteLine("hallo"); - // Func p = pred.Compile(); var p = predicate.Compile(); foreach (T item in coll) { - // if (p(item)) - if ((bool)p.DynamicInvoke(item)) + if (p(item)) { yield return item; } @@ -29,11 +26,7 @@ public static SCG.IEnumerable Where(this ICollection coll, Expression - { - new("Ole"), - new("Hans") - }; + HashSet hs = [new("Ole"), new("Hans")]; foreach (NamedPerson q in (from p in hs where p.Name.Length == 4 select p)) { @@ -42,14 +35,9 @@ private static void Main() } } -internal class NamedPerson +internal class NamedPerson(string name) { - public string Name { get; } - - public NamedPerson(string name) - { - Name = name; - } + public string Name { get; } = name; public override string ToString() { diff --git a/C5.UserGuideExamples/FileIndex.cs b/C5.UserGuideExamples/FileIndex.cs index e53530ff..9b648375 100644 --- a/C5.UserGuideExamples/FileIndex.cs +++ b/C5.UserGuideExamples/FileIndex.cs @@ -38,7 +38,7 @@ private static IDictionary> IndexFile(string filename) { if (!index.Contains(s)) { - index[s] = new TreeSet(); + index[s] = []; } index[s].Add(lineNumber); } diff --git a/C5.UserGuideExamples/GNfaToDfa.cs b/C5.UserGuideExamples/GNfaToDfa.cs index 1bc1028a..856fd48c 100644 --- a/C5.UserGuideExamples/GNfaToDfa.cs +++ b/C5.UserGuideExamples/GNfaToDfa.cs @@ -101,7 +101,7 @@ public Nfa(int startState, int exitState) Trans = new HashDictionary>(); if (!startState.Equals(exitState)) { - Trans.Add(exitState, new ArrayList()); + Trans.Add(exitState, []); } } @@ -114,13 +114,13 @@ public void AddTrans(int s1, string lab, int s2) } else { - s1Trans = new ArrayList(); + s1Trans = []; Trans.Add(s1, s1Trans); } s1Trans.Add(new Transition(lab, s2)); } - public void AddTrans(System.Collections.Generic.KeyValuePair> tr) + public void AddTrans(SCG.KeyValuePair> tr) { // Assumption: if tr is in trans, it maps to an empty list (end state) Trans.Remove(tr.Key); @@ -142,7 +142,7 @@ public override string ToString() private static IDictionary, IDictionary>> CompositeDfaTrans(int s0, IDictionary> trans) { - var S0 = EpsilonClose(new HashSet { s0 }, trans); + var S0 = EpsilonClose([s0], trans); var worklist = new CircularQueue>(); worklist.Enqueue(S0); @@ -173,7 +173,7 @@ private static IDictionary, IDictionary>> Comp } else // No transitions on lab yet { - toState = new HashSet(); + toState = []; STrans.Add(tr.Lab, toState); } toState.Add(tr.Target); @@ -274,7 +274,7 @@ private static HashSet AcceptStates(ICollectionValue> states, public Dfa ToDfa() { var cDfaTrans = CompositeDfaTrans(Start, Trans); - var cDfaStart = EpsilonClose(new HashSet { Start }, Trans); + var cDfaStart = EpsilonClose([Start], Trans); var cDfaStates = cDfaTrans.Keys; var renamer = MkRenamer(cDfaStates); var simpleDfaTrans = Rename(renamer, cDfaTrans); diff --git a/C5.UserGuideExamples/Graph.cs b/C5.UserGuideExamples/Graph.cs index 41af878e..ffd6b5fe 100644 --- a/C5.UserGuideExamples/Graph.cs +++ b/C5.UserGuideExamples/Graph.cs @@ -63,7 +63,7 @@ internal interface IGraphVertex where W : IComparable { V Value { get; } IGraph Graph { get; } - ICollectionValue> Adjacent { get; } + ICollectionValue> Adjacent { get; } } internal class Vertex @@ -104,7 +104,7 @@ internal interface IGraph where W : IComparable /// /// /// - ICollectionValue> Adjacent(V vertex); + ICollectionValue> Adjacent(V vertex); /// /// The collection of all edges in the graph. The return value is a snapshot @@ -179,7 +179,7 @@ internal interface IGraph where W : IComparable /// /// A collection of (vertex,component) pairs, where the first part of the /// pair is some vertex in the component. - ICollectionValue>> Components(); + ICollectionValue>> Components(); /// /// Traverse the connected component containing the start vertex, @@ -207,27 +207,27 @@ internal interface IGraph where W : IComparable /// /// True if BFS, false if DFS /// - /// - /// - void TraverseVertices(bool bfs, Action> act, Action beforecomponent, Action aftercomponent); + /// + /// + void TraverseVertices(bool bfs, Action> act, Action beforeComponent, Action afterComponent); /// /// A more advanced Depth First Search traversal. /// /// The vertex to start the search at - /// Action to perform when a vertex is first encountered. - /// Action to perform when all edges out of a vertex has been handles. - /// Action to perform as an edge is traversed. - /// Action to perform when an edge is traversed back. - /// Action to perform when an edge (a backedge)is seen, but not followed. - void DepthFirstSearch(V start, Action beforevertex, Action aftervertex, - Action> onfollow, Action> onfollowed, Action> onnotfollowed); + /// Action to perform when a vertex is first encountered. + /// Action to perform when all edges out of a vertex has been handles. + /// Action to perform as an edge is traversed. + /// Action to perform when an edge is traversed back. + /// Action to perform when an edge (a backedge)is seen, but not followed. + void DepthFirstSearch(V start, Action beforeVertex, Action afterVertex, + Action> onFollow, Action> onFollowed, Action> onNotFollowed); //TODO: perhaps we should avoid exporting this? /// /// Traverse the part of the graph reachable from start in order of least distance /// from start according to the weight function. Perform act on the edges of the - /// traversal as they are recognised. + /// traversal as they are recognized. /// /// /// @@ -277,7 +277,7 @@ void DepthFirstSearch(V start, Action beforevertex, Action aftervertex, /// /// This is intended for implementations of the very simple factor 2 approximation - /// algorithms for the travelling salesman problem for Euclidic weight/distance + /// algorithms for the traveling salesman problem for Euclidean weight/distance /// functions, i.e. distances that satisfy the triangle inequality. (We do not do 3/2) /// /// @@ -286,7 +286,7 @@ void DepthFirstSearch(V start, Action beforevertex, Action aftervertex, /// /// Pretty-print the graph to the console (for debugging purposes). /// - void Print(System.IO.TextWriter output); + void Print(TextWriter output); } /// @@ -296,16 +296,16 @@ void DepthFirstSearch(V start, Action beforevertex, Action aftervertex, /// /// The type of a vertex. /// The type of data associated with edges. -internal struct Edge +internal readonly struct Edge { - private static readonly SCG.IEqualityComparer vequalityComparer = EqualityComparer.Default; + private static readonly SCG.IEqualityComparer vEqualityComparer = EqualityComparer.Default; public V Start { get; } public V End { get; } public E EdgeData { get; } public Edge(V start, V end, E edgedata) { - if (vequalityComparer.Equals(start, end)) + if (vEqualityComparer.Equals(start, end)) { throw new ArgumentException("Illegal: start and end are equal"); } @@ -325,11 +325,11 @@ public override string ToString() return string.Format("(start='{0}', end='{1}', edgedata='{2}')", Start, End, EdgeData); ; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is Edge other) { - return vequalityComparer.Equals(Start, other.Start) && vequalityComparer.Equals(End, other.End); + return vEqualityComparer.Equals(Start, other.Start) && vEqualityComparer.Equals(End, other.End); } return false; } @@ -357,8 +357,8 @@ public class UnorderedEqualityComparer : SCG.IEqualityComparer> /// public bool Equals(Edge i1, Edge i2) { - return (vequalityComparer.Equals(i1.Start, i2.Start) && vequalityComparer.Equals(i1.End, i2.End)) || - (vequalityComparer.Equals(i1.End, i2.Start) && vequalityComparer.Equals(i1.Start, i2.End)); + return (vEqualityComparer.Equals(i1.Start, i2.Start) && vEqualityComparer.Equals(i1.End, i2.End)) || + (vEqualityComparer.Equals(i1.End, i2.Start) && vEqualityComparer.Equals(i1.Start, i2.End)); } /// @@ -445,29 +445,48 @@ Or simply a HashedArrayList to get both? /// /// /// -internal class HashGraph : IGraph where W : IComparable -{ - private readonly HashDictionary> _graph; +/// +/// Create an initially empty graph. +/// +/// +[method: UsedBy("testTSP")] - public IWeight Weight { get; } +/* + For a dense graph, we would use data fields: - /// - /// Create an initially empty graph. - /// - /// - [UsedBy("testTSP")] - public HashGraph(IWeight weight) - { - Weight = weight; - EdgeCount = 0; - _graph = new HashDictionary>(); - } + E'[,] or E'[][] for the matrix. Possibly E'[][] for a triangular one! + Here E' = struct{E edgedata, bool present} or class{E edgedata}, or if E is a class just E. + Thus E' is E! for value types. Or we could have two matrices: E[][] and bool[][]. + + HashDictionary to map vertex ids to indices. + ArrayList for the map the other way. + Or simply a HashedArrayList to get both? + + PresentList, FreeList or similar, if we do not want to compact the indices in the matrix on each delete. + If we compact, we always do a delete on the vertex<->index map by a replace and a removelast: + vimap[ind]=vimap[vimap.Count]; vimap.RemoveLast(); //also reorder matrix! + + +*/ + +/// +/// An implementation of IGraph≤V,E,W≥ based on an adjacency list representation using hash dictionaries. +/// As a consequence, this will be most efficient for sparse graphs. +/// +/// +/// +/// +internal class HashGraph(IWeight weight) : IGraph where W : IComparable +{ + private readonly HashDictionary> _graph = []; + + public IWeight Weight { get; } = weight; /// /// Constructing a graph with no isolated vertices given a collection of edges. /// /// - [UsedBy()] + [UsedBy] public HashGraph(IWeight weight, SCG.IEnumerable> edges) : this(weight) { foreach (var edge in edges) @@ -481,7 +500,7 @@ public HashGraph(IWeight weight, SCG.IEnumerable> edges) : this V start = edge.Start, end = edge.End; if (!_graph.Find(ref start, out HashDictionary edgeset)) { - _graph.Add(edge.Start, edgeset = new HashDictionary()); + _graph.Add(edge.Start, edgeset = []); } if (!edgeset.UpdateOrAdd(edge.End, edge.EdgeData)) @@ -491,7 +510,7 @@ public HashGraph(IWeight weight, SCG.IEnumerable> edges) : this if (!_graph.Find(ref end, out edgeset)) { - _graph.Add(edge.End, edgeset = new HashDictionary()); + _graph.Add(edge.End, edgeset = []); } edgeset.UpdateOrAdd(edge.Start, edge.EdgeData); @@ -510,7 +529,7 @@ public HashGraph(IWeight weight, SCG.IEnumerable vertices, SCG.IEnumera { foreach (var v in vertices) { - _graph.Add(v, new HashDictionary()); + _graph.Add(v, []); } foreach (var edge in edges) @@ -546,16 +565,16 @@ public HashGraph(IWeight weight, SCG.IEnumerable vertices, SCG.IEnumera public int VertexCount => _graph.Count; [UsedBy("testCOMP")] - public int EdgeCount { get; private set; } + public int EdgeCount { get; private set; } = 0; public ICollectionValue Vertices() { return new GuardedCollectionValue(_graph.Keys); } - public ICollectionValue> Adjacent(V vertex) + public ICollectionValue> Adjacent(V vertex) { - return new GuardedCollectionValue>(_graph[vertex]); + return new GuardedCollectionValue>(_graph[vertex]); } private class EdgesValue : CollectionValueBase> @@ -612,7 +631,7 @@ public bool AddVertex(V v) return false; } - _graph.Add(v, new HashDictionary()); + _graph.Add(v, []); return true; } @@ -629,7 +648,7 @@ public bool AddEdge(V start, V end, E edgedata) } else { - _graph[start] = edgeset = new HashDictionary(); + _graph[start] = edgeset = []; edgeset[end] = edgedata; retval = true; } @@ -639,7 +658,7 @@ public bool AddEdge(V start, V end, E edgedata) } else { - _graph[end] = edgeset = new HashDictionary(); + _graph[end] = edgeset = []; edgeset[start] = edgedata; } if (retval) @@ -703,7 +722,7 @@ public IGraph SubGraph(ICollectionValue vs) { if (!(vs is HashSet vertexset)) { - vertexset = new HashSet(); + vertexset = []; vertexset.AddAll(vs); } @@ -724,9 +743,9 @@ public int ComponentCount } } - public ICollectionValue>> Components() + public ICollectionValue>> Components() { - ArrayList>> retval = new(); + ArrayList>> retval = []; HashGraph component; ArrayList vertices = null; void edgeaction(Edge e) @@ -736,7 +755,7 @@ void edgeaction(Edge e) void beforecomponent(V v) { - vertices = new ArrayList() { v }; + vertices = [v]; } void aftercomponent(V v) @@ -746,13 +765,13 @@ void aftercomponent(V v) foreach (V start in vertices) { //component.graph[start] = graph[start].Clone(); - HashDictionary edgeset = component._graph[start] = new HashDictionary(); - foreach (System.Collections.Generic.KeyValuePair adjacent in _graph[start]) + HashDictionary edgeset = component._graph[start] = []; + foreach (SCG.KeyValuePair adjacent in _graph[start]) { edgeset[adjacent.Key] = adjacent.Value; } } - retval.Add(new System.Collections.Generic.KeyValuePair>(v, component)); + retval.Add(new SCG.KeyValuePair>(v, component)); } TraverseVertices(false, edgeaction, beforecomponent, aftercomponent); return retval; @@ -788,7 +807,7 @@ public void TraverseVertices(bool bfs, V start, Action> act) if (_graph.Find(ref v, out HashDictionary adjacent)) { - foreach (System.Collections.Generic.KeyValuePair p in adjacent) + foreach (SCG.KeyValuePair p in adjacent) { var end = p.Key; if (!seen.FindOrAdd(ref end)) @@ -839,7 +858,7 @@ void visit(V v, V parent, bool atRoot) before(v); if (_graph.Find(ref v, out HashDictionary adjacent)) { - foreach (System.Collections.Generic.KeyValuePair p in adjacent) + foreach (SCG.KeyValuePair p in adjacent) { V end = p.Key; Edge e = new(v, end, p.Value); @@ -900,7 +919,7 @@ public void PriorityFirstTraverse(bool accumulated, V start, EdgeAction } if (_graph.Find(ref current, out HashDictionary adjacentnodes)) { - foreach (System.Collections.Generic.KeyValuePair adjacent in adjacentnodes) + foreach (SCG.KeyValuePair adjacent in adjacentnodes) { V end = adjacent.Key; E edgedata = adjacent.Value; @@ -1035,7 +1054,7 @@ public ICollectionValue> ApproximateMWPM() else { bool first = true; - foreach (System.Collections.Generic.KeyValuePair p in clone._graph[current]) + foreach (SCG.KeyValuePair p in clone._graph[current]) { W thisweight = Weight.Weight(p.Value); if (first || bestweight.CompareTo(thisweight) > 0) @@ -1103,7 +1122,7 @@ public IList EulerTour() HashedArrayList adjacent = default; foreach (var p in _graph) { - adjacent = new HashedArrayList(); + adjacent = []; adjacent.AddAll(p.Value.Keys); start = p.Key; edges.Add(start, adjacent); @@ -1169,11 +1188,11 @@ public IList EulerTour() /// The purpose of this struct is to be able to create and add new, /// synthetic vertices to a graph. /// - private struct Vplus : IEquatable + private readonly struct Vplus : IEquatable { private static readonly SCG.IEqualityComparer _vequalityComparer = EqualityComparer.Default; - public V Vertex { get; } + public V? Vertex { get; } public int Id { get; } internal Vplus(V v) { Vertex = v; Id = 0; } @@ -1304,7 +1323,7 @@ void onfollow(Edge e) return tour; } - public void Print(System.IO.TextWriter output) + public void Print(TextWriter output) { output.WriteLine("Graph has {0} vertices, {1} edges, {2} components", _graph.Count, EdgeCount, ComponentCount); foreach (SCG.KeyValuePair> p in _graph) @@ -1356,6 +1375,7 @@ internal class DoubleWeight : IWeight /// /// Attribute used for marking which examples use a particular graph method /// +[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)] internal class UsedByAttribute : Attribute { private readonly string[] tests; @@ -1363,7 +1383,7 @@ internal class UsedByAttribute : Attribute public override string ToString() { - System.Text.StringBuilder sb = new(); + StringBuilder sb = new(); for (int i = 0; i < tests.Length; i++) { if (i > 0) @@ -1462,10 +1482,7 @@ private static SCG.IEnumerable> Forest(int treeCount, int heig /// An enumerable with the edges private static SCG.IEnumerable> Wheel(bool complete, int n) { - if (n < 3) - { - throw new ArgumentOutOfRangeException("n must be at least 3"); - } + ArgumentOutOfRangeException.ThrowIfLessThan(n, 3); var center = "C"; var perimeter = new string[n]; @@ -1521,7 +1538,7 @@ public static void TestCOMP() IGraph g = new HashGraph(new CountWeight(), Forest(2, 2)); Console.WriteLine("Forest has: Vertices: {0}, Edges: {1}, Components: {2}", g.VertexCount, g.EdgeCount, g.ComponentCount); //g.Print(Console.Out); - foreach (System.Collections.Generic.KeyValuePair> comp in g.Components()) + foreach (SCG.KeyValuePair> comp in g.Components()) { Console.WriteLine("Component of {0}:", comp.Key); comp.Value.Print(Console.Out); @@ -1742,7 +1759,7 @@ public static void TestDFS() g.AddEdge("C", "G", 0); g.AddEdge("F", "G", 0); - HashDictionary index = new(); + HashDictionary index = []; int[] leastIndexReachableFrom = new int[g.VertexCount]; int nextindex = 0; int outgoingFromRoot = 0; diff --git a/C5.UserGuideExamples/HashCodes.cs b/C5.UserGuideExamples/HashCodes.cs index 62c5e7ba..081df7df 100644 --- a/C5.UserGuideExamples/HashCodes.cs +++ b/C5.UserGuideExamples/HashCodes.cs @@ -40,7 +40,7 @@ public static void Main(string[] args) public static HashSet MakeRandom(int count, SCG.IEqualityComparer eqc) { - var res = eqc == null ? new HashSet() : new HashSet(eqc); + var res = eqc == null ? [] : new HashSet(eqc); for (var i = 0; i < count; i++) { diff --git a/C5.UserGuideExamples/IndexedObjects.cs b/C5.UserGuideExamples/IndexedObjects.cs index 935970d4..bca97734 100644 --- a/C5.UserGuideExamples/IndexedObjects.cs +++ b/C5.UserGuideExamples/IndexedObjects.cs @@ -109,7 +109,7 @@ public class IndexMaker : IndexMaker public IndexMaker(string name, Func fun) : base(name) { _fun = fun; - _dictionary = new TreeDictionary>(); + _dictionary = []; } public override bool Add(T item) diff --git a/C5.UserGuideExamples/IndexedObjects2.cs b/C5.UserGuideExamples/IndexedObjects2.cs index dc8b6c81..b2b8c908 100644 --- a/C5.UserGuideExamples/IndexedObjects2.cs +++ b/C5.UserGuideExamples/IndexedObjects2.cs @@ -81,7 +81,7 @@ public class HashIndex : IIndex where T : class public HashIndex(Func toKey) { _toKey = toKey; - _dictionary = new HashDictionary>(); + _dictionary = []; } public void Add(T item) @@ -122,7 +122,7 @@ public class TreeIndex : IIndex where T : class public TreeIndex(Func toKey) { _toKey = toKey; - _dictionary = new TreeDictionary>(); + _dictionary = []; } public void Add(T item) diff --git a/C5.UserGuideExamples/JobQueue.cs b/C5.UserGuideExamples/JobQueue.cs index e320247b..7c87d9b1 100644 --- a/C5.UserGuideExamples/JobQueue.cs +++ b/C5.UserGuideExamples/JobQueue.cs @@ -48,7 +48,7 @@ public JobQueue() { _jobQueue = new IntervalHeap(); _jobs = new HashDictionary>(); - _userJobs = new HashBag(); + _userJobs = []; } public Rid Submit(Ip ip, int time) @@ -94,22 +94,15 @@ public void Cancel(Rid rid) } } -internal class Job : IComparable +internal class Job(Rid rid, Ip ip, int time) : IComparable { - public Rid Rid { get; } - public Ip Ip { get; } - public int Time { get; } + public Rid Rid { get; } = rid; + public Ip Ip { get; } = ip; + public int Time { get; } = time; - public Job(Rid rid, Ip ip, int time) + public int CompareTo(Job? that) { - Rid = rid; - Ip = ip; - Time = time; - } - - public int CompareTo(Job that) - { - return Time - that.Time; + return Time.CompareTo(that!.Time); } public override string ToString() @@ -134,22 +127,11 @@ public override string ToString() } } -internal class Ip +internal class Ip(string ipString) { - public string IpString { get; } - - public Ip(string ipString) - { - IpString = ipString; - } + public string IpString { get; } = ipString; - public override int GetHashCode() - { - return IpString.GetHashCode(); - } + public override bool Equals(object? that) => IpString.Equals(that); - public override bool Equals(object that) - { - return IpString.Equals(that); - } + public override int GetHashCode() => IpString.GetHashCode(); } diff --git a/C5.UserGuideExamples/KeywordRecognition.cs b/C5.UserGuideExamples/KeywordRecognition.cs index fcf50f27..c061b2f3 100644 --- a/C5.UserGuideExamples/KeywordRecognition.cs +++ b/C5.UserGuideExamples/KeywordRecognition.cs @@ -56,9 +56,9 @@ static KeywordRecognition() { _keywords1 = new HashSet(); _keywords1.AddAll(_keywordArray); - _keywords2 = new TreeSet(new SC()); + _keywords2 = new TreeSet(StringComparer.InvariantCulture); _keywords2.AddAll(_keywordArray); - _keywords3 = new SortedArray(new SC()); + _keywords3 = new SortedArray(StringComparer.InvariantCulture); _keywords3.AddAll(_keywordArray); _keywords4 = new SCG.Dictionary(); diff --git a/C5.UserGuideExamples/Locking.cs b/C5.UserGuideExamples/Locking.cs index 009b1fd3..64c41f0a 100644 --- a/C5.UserGuideExamples/Locking.cs +++ b/C5.UserGuideExamples/Locking.cs @@ -7,7 +7,7 @@ namespace C5.UserGuideExamples { internal class Locking { - private static ArrayList _collection = new(); + private static ArrayList _collection = []; private static readonly int _count = 1000; public static void Main() @@ -16,15 +16,15 @@ public static void Main() RunTwoThreads(delegate { AddAndRemove(15000); }); Console.WriteLine($"Collection has {_collection.Count} items, should be 0"); - _collection = new ArrayList(); + _collection = []; Console.WriteLine("Adding and removing with locking:"); RunTwoThreads(delegate { SafeAddAndRemove(15000); }); Console.WriteLine($"Collection has {_collection.Count} items, should be 0"); Console.WriteLine("Moving items without locking:"); ArrayList from, to; - from = new ArrayList(); - to = new ArrayList(); + from = []; + to = []; for (var i = 0; i < _count; i++) { @@ -41,8 +41,8 @@ public static void Main() Console.WriteLine($"Collection has {to.Count} items, should be {_count}"); Console.WriteLine("Moving items with locking:"); - from = new ArrayList(); - to = new ArrayList(); + from = []; + to = []; for (var i = 0; i < _count; i++) { diff --git a/C5.UserGuideExamples/MultiDictionary.cs b/C5.UserGuideExamples/MultiDictionary.cs index c64b5d15..035d12c2 100644 --- a/C5.UserGuideExamples/MultiDictionary.cs +++ b/C5.UserGuideExamples/MultiDictionary.cs @@ -90,7 +90,7 @@ public class MultiHashDictionary : HashDictionary> get { int count = 0; - foreach (System.Collections.Generic.KeyValuePair> entry in this) + foreach (SCG.KeyValuePair> entry in this) { if (entry.Value != null) { @@ -248,10 +248,10 @@ MultiHashDictionary> mdict mdict.Remove(20, "twenty"); Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); - HashSet zwei = new() - { + HashSet zwei = + [ "zwei" - }; + ]; mdict[2] = zwei; mdict[-2] = zwei; Console.WriteLine(mdict); @@ -259,7 +259,7 @@ MultiHashDictionary> mdict zwei.Add("kaksi"); Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); - HashSet empty = new(); + HashSet empty = []; mdict[0] = empty; Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); @@ -308,7 +308,7 @@ private void ClearedCount(object sender, ClearedEventArgs args) public MultiHashDictionary() { ItemsAdded += - delegate (object sender, ItemCountEventArgs>> args) + delegate (object sender, ItemCountEventArgs>> args) { ICollection values = args.Item.Value; if (values != null) @@ -320,7 +320,7 @@ public MultiHashDictionary() } }; ItemsRemoved += - delegate (object sender, ItemCountEventArgs>> args) + delegate (object sender, ItemCountEventArgs>> args) { ICollection values = args.Item.Value; if (values != null) diff --git a/C5.UserGuideExamples/MultiDictionary2.cs b/C5.UserGuideExamples/MultiDictionary2.cs index 06fc1342..048c4b6a 100644 --- a/C5.UserGuideExamples/MultiDictionary2.cs +++ b/C5.UserGuideExamples/MultiDictionary2.cs @@ -31,10 +31,10 @@ public static void Main() mdict.Remove(20, "twenty"); Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); - Inner zwei = new() - { + Inner zwei = + [ "zwei" - }; + ]; mdict[2] = zwei; mdict[-2] = zwei; Console.WriteLine(mdict); @@ -42,7 +42,7 @@ public static void Main() zwei.Add("kaksi"); Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); - Inner empty = new(); + Inner empty = []; mdict[0] = empty; Console.WriteLine(mdict); Console.WriteLine("mdict.Count is {0}", mdict.Count); @@ -91,7 +91,7 @@ public class MultiHashDictionary : HashDictionary> get { int count = 0; - foreach (System.Collections.Generic.KeyValuePair> entry in this) + foreach (SCG.KeyValuePair> entry in this) if (entry.Value != null) count += entry.Value.Count; return count; @@ -218,7 +218,7 @@ private void ClearedCount(object sender, ClearedEventArgs args) public MultiHashDictionary() { ItemsAdded += - delegate (object sender, ItemCountEventArgs>> args) + delegate (object sender, ItemCountEventArgs>> args) { ICollection values = args.Item.Value; if (values != null) @@ -230,7 +230,7 @@ public MultiHashDictionary() } }; ItemsRemoved += - delegate (object sender, ItemCountEventArgs>> args) + delegate (object sender, ItemCountEventArgs>> args) { ICollection values = args.Item.Value; if (values != null) diff --git a/C5.UserGuideExamples/PointLocation.cs b/C5.UserGuideExamples/PointLocation.cs index 00d46946..5ce507d9 100644 --- a/C5.UserGuideExamples/PointLocation.cs +++ b/C5.UserGuideExamples/PointLocation.cs @@ -138,20 +138,20 @@ public class PointLocator { private TreeDictionary>> htree; - private readonly TreeDictionary>, LinkedList>>> endpoints; + private readonly TreeDictionary>, LinkedList>>> endpoints; private bool built = false; public PointLocator() { //htree = new TreeDictionary>>(dc); - endpoints = new TreeDictionary>, LinkedList>>>(); + endpoints = []; } public PointLocator(SCG.IEnumerable> edges) { //htree = new TreeDictionary>>(dc); - endpoints = new TreeDictionary>, LinkedList>>>(); + endpoints = []; foreach (Edge edge in edges) { add(edge); @@ -167,15 +167,15 @@ private void add(Edge edge) if (!endpoints.Contains(edge.Xs)) { - endpoints.Add(edge.Xs, new System.Collections.Generic.KeyValuePair>, LinkedList>>(new LinkedList>(), new LinkedList>())); + endpoints.Add(edge.Xs, new SCG.KeyValuePair>, LinkedList>>([], [])); } - System.Collections.Generic.KeyValuePair>, LinkedList>> kv; + SCG.KeyValuePair>, LinkedList>> kv; kv = endpoints[edge.Xs]; kv.Key.Add(edge); if (!endpoints.Contains(edge.Xe)) { - endpoints.Add(edge.Xe, new System.Collections.Generic.KeyValuePair>, LinkedList>>(new LinkedList>(), new LinkedList>())); + endpoints.Add(edge.Xe, new SCG.KeyValuePair>, LinkedList>>([], [])); } kv = endpoints[edge.Xe]; @@ -208,13 +208,13 @@ public void AddAll(SCG.IEnumerable> edges) public void Build() { //htree.Clear(); - htree = new TreeDictionary>>(); + htree = []; - TreeSet> vtree = new(); + TreeSet> vtree = []; - htree[double.NegativeInfinity] = (ISorted>)(vtree.Snapshot()); + htree[double.NegativeInfinity] = vtree.Snapshot(); - foreach (System.Collections.Generic.KeyValuePair>, LinkedList>>> p in endpoints) + foreach (SCG.KeyValuePair>, LinkedList>>> p in endpoints) { foreach (Edge e in p.Value.Value) { @@ -235,7 +235,7 @@ public void Build() Debug.Assert(chk, "edge was not added!", "" + e); } - htree[p.Key] = (ISorted>)(vtree.Snapshot()); + htree[p.Key] = vtree.Snapshot(); } built = true; @@ -261,7 +261,7 @@ public bool Place(double x, double y, out T cell) throw new InvalidOperationException("PointLocator must be built first"); } - System.Collections.Generic.KeyValuePair>> p = htree.WeakPredecessor(x); + SCG.KeyValuePair>> p = htree.WeakPredecessor(x); //if (DoubleComparer.StaticCompare(cell.key,x)==0) //Just note it, we have thrown away the vertical edges! @@ -293,7 +293,7 @@ public void Place(double x, double y, out T upper, out bool hval, out T lower, o throw new InvalidOperationException("PointLocator must be built first"); } - System.Collections.Generic.KeyValuePair>> p = htree.WeakPredecessor(x); + SCG.KeyValuePair>> p = htree.WeakPredecessor(x); //if (DoubleComparer.StaticCompare(cell.key,x)==0) //Just note it, we have thrown away the vertical edges! diff --git a/C5.UserGuideExamples/RandomSelection.cs b/C5.UserGuideExamples/RandomSelection.cs index 0ead4f86..2df30c32 100644 --- a/C5.UserGuideExamples/RandomSelection.cs +++ b/C5.UserGuideExamples/RandomSelection.cs @@ -9,7 +9,7 @@ internal class RandomSelection { public static void Main() { - ArrayList list = new(); + ArrayList list = []; list.AddAll([2, 3, 5, 7, 11, 13, 17, 19]); var copy1 = new ArrayList(); copy1.AddAll(list); diff --git a/C5.UserGuideExamples/SortingPermutation.cs b/C5.UserGuideExamples/SortingPermutation.cs index 241ab7df..032a1ca3 100644 --- a/C5.UserGuideExamples/SortingPermutation.cs +++ b/C5.UserGuideExamples/SortingPermutation.cs @@ -54,7 +54,7 @@ public static ArrayList GetPermutation2(IList lst) where T : IComparable { var i = 0; - var zipList = lst.Map(x => new System.Collections.Generic.KeyValuePair(x, i++)); + var zipList = lst.Map(x => new SCG.KeyValuePair(x, i++)); zipList.Sort(new KeyValuePairKeyComparer()); var res = new ArrayList(lst.Count); @@ -66,10 +66,10 @@ public static ArrayList GetPermutation2(IList lst) return res; } - private class KeyValuePairKeyComparer : SCG.IComparer> + private class KeyValuePairKeyComparer : SCG.IComparer> where T : IComparable { - public int Compare(System.Collections.Generic.KeyValuePair p1, System.Collections.Generic.KeyValuePair p2) + public int Compare(SCG.KeyValuePair p1, SCG.KeyValuePair p2) { return p1.Key.CompareTo(p2.Key); } diff --git a/C5.UserGuideExamples/UnionFind.cs b/C5.UserGuideExamples/UnionFind.cs index dcb29cad..1ea5891b 100644 --- a/C5.UserGuideExamples/UnionFind.cs +++ b/C5.UserGuideExamples/UnionFind.cs @@ -59,7 +59,7 @@ public static void Main() public class Eqclass { - private static readonly HashDictionary> dict = new(); + private static readonly HashDictionary> dict = []; private Eqclass _link; private int _rank; diff --git a/C5/Arrays/ArrayList.cs b/C5/Arrays/ArrayList.cs index 54479a87..5a58b816 100644 --- a/C5/Arrays/ArrayList.cs +++ b/C5/Arrays/ArrayList.cs @@ -841,7 +841,7 @@ public virtual IList Map(Func mapper) ArrayList res = new(size); - return Map(mapper, res); + return Map(mapper, res); } /// @@ -859,7 +859,7 @@ public virtual IList Map(Func mapper, SCG.IEqualityComparer iteme ArrayList res = new(size, itemequalityComparer); - return Map(mapper, res); + return Map(mapper, res); } private ArrayList Map(Func mapper, ArrayList res) @@ -1184,7 +1184,7 @@ public virtual void Sort(SCG.IComparer comparer) return; } - Sorting.IntroSort(array, offsetField, size, comparer); + Sorting.IntroSort(array, offsetField, size, comparer); DisposeOverlappingViews(false); (underlying ?? this).RaiseCollectionChanged(); @@ -1841,7 +1841,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { HashBag hashbag = new(itemEqualityComparer); hashbag.AddAll(this); @@ -2225,12 +2225,12 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S #region System.Collections.Generic.IList Members - void System.Collections.Generic.IList.RemoveAt(int index) + void SCG.IList.RemoveAt(int index) { RemoveAt(index); } - void System.Collections.Generic.ICollection.Add(T item) + void SCG.ICollection.Add(T item) { Add(item); } @@ -2264,12 +2264,12 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) object? System.Collections.IList.this[int index] { get => this[index]!; - set + set { if (value is null && default(T) is not null) throw new ArgumentNullException(nameof(value)); if (value is not T) throw new ArgumentException("Wrong type", nameof(value)); - this[index] = (T)value; + this[index] = (T)value; } } diff --git a/C5/Arrays/HashedArrayList.cs b/C5/Arrays/HashedArrayList.cs index 2fed561d..ef37e46d 100644 --- a/C5/Arrays/HashedArrayList.cs +++ b/C5/Arrays/HashedArrayList.cs @@ -304,7 +304,7 @@ protected override void ModifyCheck(int stamp) /// The index of first occurrence private int IndexOfInner(T item) { - System.Collections.Generic.KeyValuePair p = new(item, default); + SCG.KeyValuePair p = new(item, default); if (itemIndex.Find(ref p) && p.Value >= offsetField && p.Value < offsetField + size) { return p.Value - offsetField; @@ -334,7 +334,7 @@ private int LastIndexOfInner(T item) /// Item to insert protected override void InsertProtected(int i, T item) { - System.Collections.Generic.KeyValuePair p = new(item, offsetField + i); + SCG.KeyValuePair p = new(item, offsetField + i); if (itemIndex.FindOrAdd(ref p)) { throw new DuplicateNotAllowedException("Item already in indexed list: " + item); @@ -382,7 +382,7 @@ private T RemoveAtInternal(int i) } array[UnderlyingSize] = default; - itemIndex.Remove(new System.Collections.Generic.KeyValuePair(retval, default)); + itemIndex.Remove(new SCG.KeyValuePair(retval, default)); ReIndex(i); return retval; } @@ -396,7 +396,7 @@ private void ReIndex(int start, int end) { for (int j = start; j < end; j++) { - itemIndex.UpdateOrAdd(new System.Collections.Generic.KeyValuePair(array[j], j)); + itemIndex.UpdateOrAdd(new SCG.KeyValuePair(array[j], j)); } } #endregion @@ -785,7 +785,7 @@ public virtual T this[int index] index += offsetField; T item = array[index]; - System.Collections.Generic.KeyValuePair p = new(value, index); + SCG.KeyValuePair p = new(value, index); if (itemEqualityComparer.Equals(value, item)) { array[index] = value; @@ -793,7 +793,7 @@ public virtual T this[int index] } else if (!itemIndex.FindOrAdd(ref p)) { - itemIndex.Remove(new System.Collections.Generic.KeyValuePair(item, default)); + itemIndex.Remove(new SCG.KeyValuePair(item, default)); array[index] = value; } else @@ -897,7 +897,7 @@ public virtual void InsertAll(int index, SCG.IEnumerable items) foreach (T item in items) { - System.Collections.Generic.KeyValuePair p = new(item, i); + SCG.KeyValuePair p = new(item, i); if (itemIndex.FindOrAdd(ref p)) { throw new DuplicateNotAllowedException("Item already in indexed list"); @@ -1017,7 +1017,7 @@ public virtual IList Map(Func mapper) HashedArrayList res = new(size); - return Map(mapper, res); + return Map(mapper, res); } /// @@ -1037,7 +1037,7 @@ public virtual IList Map(Func mapper, SCG.IEqualityComparer iteme HashedArrayList res = new(size, itemequalityComparer); - return Map(mapper, res); + return Map(mapper, res); } private HashedArrayList Map(Func mapper, HashedArrayList res) @@ -1049,7 +1049,7 @@ private HashedArrayList Map(Func mapper, HashedArrayList res) { V mappeditem = mapper(array[offsetField + i]); ModifyCheck(stamp); - System.Collections.Generic.KeyValuePair p = new(mappeditem, i); + SCG.KeyValuePair p = new(mappeditem, i); if (res.itemIndex.FindOrAdd(ref p)) { throw new ArgumentException("Mapped item already in indexed list"); @@ -1228,7 +1228,7 @@ public virtual IList Slide(int offset, int size) { if (!TrySlide(offset, size)) { - throw new ArgumentOutOfRangeException(nameof(offset)); + throw new ArgumentOutOfRangeException(nameof(offset), $"{nameof(offset)} and {nameof(size)} combination is out of range"); } return this; @@ -1367,7 +1367,7 @@ public virtual void Sort(SCG.IComparer comparer) return; } - Sorting.IntroSort(array, offsetField, size, comparer); + Sorting.IntroSort(array, offsetField, size, comparer); DisposeOverlappingViews(false); ReIndex(offsetField, offsetField + size); (underlying ?? this).RaiseCollectionChanged(); @@ -1572,7 +1572,7 @@ public virtual bool Update(T item, out T olditem) { olditem = array[offsetField + i]; array[offsetField + i] = item; - itemIndex.Update(new System.Collections.Generic.KeyValuePair(item, offsetField + i)); + itemIndex.Update(new SCG.KeyValuePair(item, offsetField + i)); (underlying ?? this).RaiseForUpdate(item, olditem); return true; } @@ -1880,7 +1880,7 @@ public virtual void RetainAll(SCG.IEnumerable items) int j = offsetField; int removed = 0; int i = offsetField, end = offsetField + size; - System.Collections.Generic.KeyValuePair p = new(); + SCG.KeyValuePair p = new(); while (i < end) { T item; @@ -2036,7 +2036,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { return new MultiplicityOne(this); @@ -2168,7 +2168,7 @@ public override bool Check() public virtual bool Add(T item) { UpdateCheck(); - System.Collections.Generic.KeyValuePair p = new(item, size + offsetField); + SCG.KeyValuePair p = new(item, size + offsetField); if (itemIndex.FindOrAdd(ref p)) { return false; @@ -2209,7 +2209,7 @@ public virtual void AddAll(SCG.IEnumerable items) { foreach (T item in items) { - System.Collections.Generic.KeyValuePair p = new(item, i); + SCG.KeyValuePair p = new(item, i); if (itemIndex.FindOrAdd(ref p)) { continue; @@ -2368,12 +2368,12 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S #region System.Collections.Generic.IList Members - void System.Collections.Generic.IList.RemoveAt(int index) + void SCG.IList.RemoveAt(int index) { RemoveAt(index); } - void System.Collections.Generic.ICollection.Add(T item) + void SCG.ICollection.Add(T item) { Add(item); } @@ -2391,7 +2391,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) { if (index < 0 || index + Count > arr.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(arr), $"{nameof(arr)} and {nameof(index)} combination is out of range"); } foreach (T item in this) diff --git a/C5/Arrays/SortedArray.cs b/C5/Arrays/SortedArray.cs index 33e23c31..993faeeb 100644 --- a/C5/Arrays/SortedArray.cs +++ b/C5/Arrays/SortedArray.cs @@ -1095,7 +1095,7 @@ public int ContainsCount(T item) /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { return new MultiplicityOne(this); } @@ -1210,7 +1210,7 @@ public void AddAll(SCG.IEnumerable items) newarr[size + toadd++] = item; } - Sorting.IntroSort(newarr, size, toadd, _comparer); + Sorting.IntroSort(newarr, size, toadd, _comparer); int j = 0, i = 0, numAdded = 0; T lastitem = default; diff --git a/C5/BaseClasses/ArrayBase.cs b/C5/BaseClasses/ArrayBase.cs index d5590e51..17961358 100644 --- a/C5/BaseClasses/ArrayBase.cs +++ b/C5/BaseClasses/ArrayBase.cs @@ -308,7 +308,7 @@ public override IDirectedCollectionValue Backwards() } - IDirectedEnumerable C5.IDirectedEnumerable.Backwards() + IDirectedEnumerable IDirectedEnumerable.Backwards() { return Backwards(); } diff --git a/C5/BaseClasses/CollectionBase.cs b/C5/BaseClasses/CollectionBase.cs index badc8a78..a93b8b23 100644 --- a/C5/BaseClasses/CollectionBase.cs +++ b/C5/BaseClasses/CollectionBase.cs @@ -2,6 +2,7 @@ // See https://github.com/sestoft/C5/blob/master/LICENSE for licensing details. using System; +using SCG = System.Collections.Generic; namespace C5; @@ -30,7 +31,7 @@ public abstract class CollectionBase : CollectionValueBase /// /// The item equalityComparer of the collection /// - protected readonly System.Collections.Generic.IEqualityComparer itemEqualityComparer; + protected readonly SCG.IEqualityComparer itemEqualityComparer; private int iUnSequencedHashCode, iUnSequencedHashCodeStamp = -1; #endregion @@ -38,10 +39,10 @@ public abstract class CollectionBase : CollectionValueBase /// /// /// - /// - protected CollectionBase(System.Collections.Generic.IEqualityComparer itemequalityComparer) + /// + protected CollectionBase(SCG.IEqualityComparer itemEqualityComparer) { - this.itemEqualityComparer = itemequalityComparer ?? throw new NullReferenceException("Item EqualityComparer cannot be null."); + this.itemEqualityComparer = itemEqualityComparer ?? throw new NullReferenceException("Item EqualityComparer cannot be null."); } #region Util @@ -57,7 +58,7 @@ protected void CheckRange(int start, int count) { if (start < 0 || count < 0 || start + count > size) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } } @@ -66,9 +67,9 @@ protected void CheckRange(int start, int count) /// Compute the unsequenced hash code of a collection /// /// The collection to compute hash code for - /// The item equalitySCG.Comparer + /// The item equalitySCG.Comparer /// The hash code - public static int ComputeHashCode(ICollectionValue items, System.Collections.Generic.IEqualityComparer itemequalityComparer) + public static int ComputeHashCode(ICollectionValue items, SCG.IEqualityComparer itemEqualityComparer) { int h = 0; @@ -78,7 +79,7 @@ public static int ComputeHashCode(ICollectionValue items, System.Collections. //Two products is too few foreach (T item in items) { - uint h1 = (uint)itemequalityComparer.GetHashCode(item); + uint h1 = (uint)itemEqualityComparer.GetHashCode(item); h += (int)((h1 * 1529784657 + 1) ^ (h1 * 2912831877) ^ (h1 * 1118771817 + 2)); } @@ -115,7 +116,7 @@ unsequenced hashcode with this hashfunction. The pair was found with code like /// The second collection /// The item equalityComparer to use for comparison /// True if equal - public static bool StaticEquals(ICollection collection1, ICollection collection2, System.Collections.Generic.IEqualityComparer itemequalityComparer) + public static bool StaticEquals(ICollection collection1, ICollection collection2, SCG.IEqualityComparer itemequalityComparer) { if (ReferenceEquals(collection1, collection2)) { @@ -146,7 +147,7 @@ public static bool StaticEquals(ICollection collection1, ICollection colle { if (collection1 is ISorted stit && collection2 is ISorted stat && stit.Comparer == stat.Comparer) { - using System.Collections.Generic.IEnumerator dat = collection2.GetEnumerator(), dit = collection1.GetEnumerator(); + using SCG.IEnumerator dat = collection2.GetEnumerator(), dit = collection1.GetEnumerator(); while (dit.MoveNext()) { dat.MoveNext(); @@ -318,7 +319,7 @@ protected virtual void UpdateCheck() /// /// /// - public virtual System.Collections.Generic.IEqualityComparer EqualityComparer => itemEqualityComparer; + public virtual SCG.IEqualityComparer EqualityComparer => itemEqualityComparer; /// /// @@ -333,6 +334,6 @@ protected virtual void UpdateCheck() /// Create an enumerator for this collection. /// /// The enumerator - public abstract override System.Collections.Generic.IEnumerator GetEnumerator(); + public abstract override SCG.IEnumerator GetEnumerator(); #endregion } \ No newline at end of file diff --git a/C5/BaseClasses/CollectionValueBase.cs b/C5/BaseClasses/CollectionValueBase.cs index 0f94a168..cc4bea8f 100644 --- a/C5/BaseClasses/CollectionValueBase.cs +++ b/C5/BaseClasses/CollectionValueBase.cs @@ -2,6 +2,7 @@ // See https://github.com/sestoft/C5/blob/master/LICENSE for licensing details. using System; +using System.Drawing; namespace C5; @@ -455,7 +456,7 @@ public virtual void CopyTo(T[] array, int index) { if (index < 0 || index + Count > array.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(array), $"{nameof(array)} and {nameof(index)} combination is out of range"); } foreach (T item in this) @@ -603,7 +604,7 @@ public virtual System.Collections.Generic.IEnumerable Filter(Func pr /// public virtual bool Show(System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider? formatProvider) { - return Showing.ShowCollectionValue(this, stringbuilder, ref rest, formatProvider!); + return Showing.ShowCollectionValue(this, stringbuilder, ref rest, formatProvider!); } #endregion diff --git a/C5/BaseClasses/DictionaryBase.cs b/C5/BaseClasses/DictionaryBase.cs index ed65b2ff..bc866a0d 100644 --- a/C5/BaseClasses/DictionaryBase.cs +++ b/C5/BaseClasses/DictionaryBase.cs @@ -354,7 +354,7 @@ internal ValuesCollection(ICollection> pairs) public override V Choose() { return pairs.Choose().Value; } - public override System.Collections.Generic.IEnumerator GetEnumerator() + public override IEnumerator GetEnumerator() { //Updatecheck is performed by the pairs enumerator foreach (KeyValuePair p in pairs) @@ -380,7 +380,7 @@ internal KeysCollection(ICollection> pairs) public override K Choose() { return pairs.Choose().Key; } - public override System.Collections.Generic.IEnumerator GetEnumerator() + public override IEnumerator GetEnumerator() { foreach (KeyValuePair p in pairs) { @@ -484,7 +484,7 @@ public virtual V this[K key] /// Create an enumerator for the collection of entries of the dictionary /// /// The enumerator - public override System.Collections.Generic.IEnumerator> GetEnumerator() + public override IEnumerator> GetEnumerator() { return pairs.GetEnumerator(); } diff --git a/C5/Comparers/KeyValuePairComparer.cs b/C5/Comparers/KeyValuePairComparer.cs index d773f0f5..40883ecf 100644 --- a/C5/Comparers/KeyValuePairComparer.cs +++ b/C5/Comparers/KeyValuePairComparer.cs @@ -7,16 +7,16 @@ namespace C5; /// Default comparer for dictionary entries in a sorted dictionary. /// Entry comparisons only look at keys and uses an externally defined comparer for that. /// -public class KeyValuePairComparer : IComparer> +public class KeyValuePairComparer : IComparer> { - private readonly System.Collections.Generic.IComparer comparer; + private readonly IComparer comparer; /// /// Create an entry comparer for a item comparer of the keys /// /// Comparer of keys - public KeyValuePairComparer(System.Collections.Generic.IComparer comparer) + public KeyValuePairComparer(IComparer comparer) { this.comparer = comparer ?? throw new NullReferenceException(); } @@ -28,7 +28,7 @@ public KeyValuePairComparer(System.Collections.Generic.IComparer comparer) /// First entry /// Second entry /// The result of comparing the keys - public int Compare(System.Collections.Generic.KeyValuePair entry1, System.Collections.Generic.KeyValuePair entry2) + public int Compare(KeyValuePair entry1, KeyValuePair entry2) { return comparer.Compare(entry1.Key, entry2.Key); } diff --git a/C5/Dictionaries/SortedDictionaryBase.cs b/C5/Dictionaries/SortedDictionaryBase.cs index 676dbbe2..df82d8ba 100644 --- a/C5/Dictionaries/SortedDictionaryBase.cs +++ b/C5/Dictionaries/SortedDictionaryBase.cs @@ -523,6 +523,6 @@ public override IDirectedCollectionValue Backwards() /// public override bool Show(System.Text.StringBuilder stringbuilder, ref int rest, IFormatProvider? formatProvider) { - return Showing.ShowDictionary(this, stringbuilder, ref rest, formatProvider); + return Showing.ShowDictionary(this, stringbuilder, ref rest, formatProvider); } } \ No newline at end of file diff --git a/C5/Hashing/HashBag.cs b/C5/Hashing/HashBag.cs index 6b3f8984..bcba56d5 100644 --- a/C5/Hashing/HashBag.cs +++ b/C5/Hashing/HashBag.cs @@ -12,7 +12,7 @@ namespace C5; public class HashBag : CollectionBase, ICollection { #region Fields - private HashSet> dict; + private HashSet> dict; #endregion #region Events @@ -38,7 +38,7 @@ public HashBag() : this(EqualityComparer.Default) { } public HashBag(SCG.IEqualityComparer itemequalityComparer) : base(itemequalityComparer) { - dict = new HashSet>(new KeyValuePairEqualityComparer(itemequalityComparer)); + dict = new HashSet>(new KeyValuePairEqualityComparer(itemequalityComparer)); } /// @@ -49,7 +49,7 @@ public HashBag(SCG.IEqualityComparer itemequalityComparer) public HashBag(int capacity, SCG.IEqualityComparer itemequalityComparer) : base(itemequalityComparer) { - dict = new HashSet>(capacity, new KeyValuePairEqualityComparer(itemequalityComparer)); + dict = new HashSet>(capacity, new KeyValuePairEqualityComparer(itemequalityComparer)); } @@ -62,7 +62,7 @@ public HashBag(int capacity, SCG.IEqualityComparer itemequalityComparer) public HashBag(int capacity, double fill, SCG.IEqualityComparer itemequalityComparer) : base(itemequalityComparer) { - dict = new HashSet>(capacity, fill, new KeyValuePairEqualityComparer(itemequalityComparer)); + dict = new HashSet>(capacity, fill, new KeyValuePairEqualityComparer(itemequalityComparer)); } #endregion @@ -82,7 +82,7 @@ public HashBag(int capacity, double fill, SCG.IEqualityComparer itemequalityC /// True if bag contains item public virtual bool Contains(T item) { - return dict.Contains(new System.Collections.Generic.KeyValuePair(item, 0)); + return dict.Contains(new SCG.KeyValuePair(item, 0)); } @@ -95,7 +95,7 @@ public virtual bool Contains(T item) /// True if bag contains item public virtual bool Find(ref T item) { - System.Collections.Generic.KeyValuePair p = new(item, 0); + SCG.KeyValuePair p = new(item, 0); if (dict.Find(ref p)) { @@ -448,7 +448,7 @@ public override T[] ToArray() T[] res = new T[size]; int ind = 0; - foreach (System.Collections.Generic.KeyValuePair p in dict) + foreach (SCG.KeyValuePair p in dict) { for (int i = 0; i < p.Value; i++) { @@ -467,7 +467,7 @@ public override T[] ToArray() /// The count public virtual int ContainsCount(T item) { - System.Collections.Generic.KeyValuePair p = new(item, 0); + SCG.KeyValuePair p = new(item, 0); if (dict.Find(ref p)) { @@ -487,9 +487,9 @@ public virtual int ContainsCount(T item) /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { - return new GuardedCollectionValue>(dict); + return new GuardedCollectionValue>(dict); } /// @@ -500,7 +500,7 @@ public virtual void RemoveAllCopies(T item) { UpdateCheck(); - System.Collections.Generic.KeyValuePair p = new(item, 0); + SCG.KeyValuePair p = new(item, 0); if (dict.Find(ref p)) { @@ -534,10 +534,10 @@ public override void CopyTo(T[] array, int index) { if (index < 0 || index + Count > array.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(array), $"{nameof(array)} and {nameof(index)} combination is out of range"); } - foreach (System.Collections.Generic.KeyValuePair p in dict) + foreach (var p in dict) { for (int j = 0; j < p.Value; j++) { @@ -674,7 +674,7 @@ public override SCG.IEnumerator GetEnumerator() int left; int mystamp = stamp; - foreach (System.Collections.Generic.KeyValuePair p in dict) + foreach (SCG.KeyValuePair p in dict) { left = p.Value; while (left > 0) @@ -701,7 +701,7 @@ public virtual bool Check() bool retval = dict.Check(); int count = 0; - foreach (System.Collections.Generic.KeyValuePair p in dict) + foreach (SCG.KeyValuePair p in dict) { count += p.Value; } diff --git a/C5/Hashing/HashSet.cs b/C5/Hashing/HashSet.cs index 2ef165b2..664333fa 100644 --- a/C5/Hashing/HashSet.cs +++ b/C5/Hashing/HashSet.cs @@ -646,7 +646,7 @@ public override T[] ToArray() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { return new MultiplicityOne(this); } @@ -869,7 +869,7 @@ public virtual bool Check() /// Histogram data. public ISortedDictionary BucketCostDistribution() { - TreeDictionary res = new(); + TreeDictionary res = []; for (int i = 0, s = table.Length; i < s; i++) { int count = 0; diff --git a/C5/Interfaces/ICollection.cs b/C5/Interfaces/ICollection.cs index 46f23297..f28ed916 100644 --- a/C5/Interfaces/ICollection.cs +++ b/C5/Interfaces/ICollection.cs @@ -101,7 +101,7 @@ public interface ICollection : IExtensible, SCG.ICollection /// /// /// - ICollectionValue> ItemMultiplicities(); + ICollectionValue> ItemMultiplicities(); /// /// Check whether this collection contains all the values in another collection. diff --git a/C5/Interfaces/IDictionary.cs b/C5/Interfaces/IDictionary.cs index a2e52ac3..e7649afb 100644 --- a/C5/Interfaces/IDictionary.cs +++ b/C5/Interfaces/IDictionary.cs @@ -68,7 +68,7 @@ public interface IDictionary : ICollectionValue> /// /// If the input contains duplicate keys or a key already present in this dictionary. /// - void AddAll(IEnumerable> entries) + void AddAll(IEnumerable> entries) where U : K where W : V ; diff --git a/C5/Interfaces/IExtensible.cs b/C5/Interfaces/IExtensible.cs index 10833edb..6d2110c1 100644 --- a/C5/Interfaces/IExtensible.cs +++ b/C5/Interfaces/IExtensible.cs @@ -32,7 +32,7 @@ public interface IExtensible : ICollectionValue /// /// The equalityComparer used by this collection to check equality of items. /// Or null (????) if collection does not check equality at all or uses a comparer. - System.Collections.Generic.IEqualityComparer EqualityComparer { get; } + IEqualityComparer EqualityComparer { get; } //ItemEqualityTypeEnum ItemEqualityType {get ;} diff --git a/C5/Interfaces/IList.cs b/C5/Interfaces/IList.cs index 71196426..b7ef5ec7 100644 --- a/C5/Interfaces/IList.cs +++ b/C5/Interfaces/IList.cs @@ -199,7 +199,7 @@ public interface IList : IIndexed, IDisposable, System.Collections.Generic /// The delegate defining the map. /// The equalityComparer to use for the new list /// The new list. - IList Map(Func mapper, System.Collections.Generic.IEqualityComparer equalityComparer); + IList Map(Func mapper, IEqualityComparer equalityComparer); /// /// Remove one item from the list: from the front if FIFO @@ -331,7 +331,7 @@ public interface IList : IIndexed, IDisposable, System.Collections.Generic /// /// The comparer defining the sorting order. /// True if the list is sorted, else false. - bool IsSorted(System.Collections.Generic.IComparer comparer); + bool IsSorted(IComparer comparer); /// /// Sort the items of the list according to the default sorting order @@ -348,7 +348,7 @@ public interface IList : IIndexed, IDisposable, System.Collections.Generic /// /// /// The comparer defining the sorting order. - void Sort(System.Collections.Generic.IComparer comparer); + void Sort(IComparer comparer); /// diff --git a/C5/Interfaces/ISorted.cs b/C5/Interfaces/ISorted.cs index ebeb5f24..3aa30f20 100644 --- a/C5/Interfaces/ISorted.cs +++ b/C5/Interfaces/ISorted.cs @@ -75,7 +75,7 @@ public interface ISorted : ISequenced /// The comparer object supplied at creation time for this sorted collection. /// /// The comparer - System.Collections.Generic.IComparer Comparer { get; } + IComparer Comparer { get; } /// /// Find the strict predecessor of item in the sorted collection, diff --git a/C5/Interfaces/ISortedDictionary.cs b/C5/Interfaces/ISortedDictionary.cs index 9b71e822..181b6a3b 100644 --- a/C5/Interfaces/ISortedDictionary.cs +++ b/C5/Interfaces/ISortedDictionary.cs @@ -159,7 +159,7 @@ public interface ISortedDictionary : IDictionary /// on this collection. /// True if the cut function is zero somewhere /// on this collection. - bool Cut(IComparable cutFunction, out SCG.KeyValuePair lowEntry, out bool lowIsValid, out System.Collections.Generic.KeyValuePair highEntry, out bool highIsValid); + bool Cut(IComparable cutFunction, out SCG.KeyValuePair lowEntry, out bool lowIsValid, out SCG.KeyValuePair highEntry, out bool highIsValid); /// /// Query this sorted collection for items greater than or equal to a supplied value. diff --git a/C5/LinkedLists/HashedLinkedList.cs b/C5/LinkedLists/HashedLinkedList.cs index 0a96c5ea..c41a4232 100644 --- a/C5/LinkedLists/HashedLinkedList.cs +++ b/C5/LinkedLists/HashedLinkedList.cs @@ -970,8 +970,8 @@ internal ViewHandler(HashedLinkedList list) { if (leftEnds == null || rightEnds == null) { - leftEnds = new ArrayList(); - rightEnds = new ArrayList(); + leftEnds = []; + rightEnds = []; } leftEnds.Add(new Position(v, true)); rightEnds.Add(new Position(v, false)); @@ -1507,8 +1507,8 @@ public IList Map(Func mapper) { Validitycheck(); - HashedLinkedList retval = new(); - return Map(mapper, retval); + HashedLinkedList retval = []; + return Map(mapper, retval); } /// @@ -1524,7 +1524,7 @@ public IList Map(Func mapper, SCG.IEqualityComparer equalityCompa Validitycheck(); HashedLinkedList retval = new(equalityComparer); - return Map(mapper, retval); + return Map(mapper, retval); } private IList Map(Func mapper, HashedLinkedList retval) @@ -1760,7 +1760,7 @@ public IList Slide(int offset, int size) { if (!TrySlide(offset, size)) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(offset), $"{nameof(offset)} and {nameof(size)} combination is out of range"); } return this; @@ -1886,7 +1886,7 @@ public virtual void Reverse() if (_positions != null) { positions = _positions.ToArray(); - Sorting.IntroSort(positions, 0, positions.Length, PositionComparer.Default); + Sorting.IntroSort(positions, 0, positions.Length, PositionComparer.Default); poshigh = positions.Length - 1; } } @@ -2221,7 +2221,7 @@ public virtual void Shuffle(Random rnd) } DisposeOverlappingViews(false); - ArrayList a = new(); + ArrayList a = []; a.AddAll(this); a.Shuffle(rnd); Node cursor = startsentinel!.next!; @@ -2870,7 +2870,7 @@ public IList FindAll(Func filter) { Validitycheck(); int stamp = this.stamp; - HashedLinkedList retval = new(); + HashedLinkedList retval = []; Node cursor = startsentinel!.next!; Node mcursor = retval.startsentinel!; double tagdelta = int.MaxValue / (size + 1.0); @@ -2930,7 +2930,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { return new MultiplicityOne(this); @@ -3383,12 +3383,12 @@ public virtual bool Check() #region System.Collections.Generic.IList Members - void System.Collections.Generic.IList.RemoveAt(int index) + void SCG.IList.RemoveAt(int index) { RemoveAt(index); } - void System.Collections.Generic.ICollection.Add(T item) + void SCG.ICollection.Add(T item) { Add(item); } @@ -3406,7 +3406,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) { if (index < 0 || index + Count > arr.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(arr), $"{nameof(arr)} and {nameof(index)} combination is out of range"); } foreach (T item in this) diff --git a/C5/LinkedLists/LinkedList.cs b/C5/LinkedLists/LinkedList.cs index 9b7d82b8..59c116fb 100644 --- a/C5/LinkedLists/LinkedList.cs +++ b/C5/LinkedLists/LinkedList.cs @@ -644,8 +644,8 @@ internal ViewHandler(LinkedList list) { if (leftEnds == null || rightEnds == null) { - leftEnds = new ArrayList(); - rightEnds = new ArrayList(); + leftEnds = []; + rightEnds = []; } leftEnds.Add(new Position(v, true)); rightEnds.Add(new Position(v, false)); @@ -1120,8 +1120,8 @@ public IList Map(Func mapper) { ValidityCheck(); - LinkedList retval = new(); - return Map(mapper, retval); + LinkedList retval = []; + return Map(mapper, retval); } /// @@ -1137,7 +1137,7 @@ public IList Map(Func mapper, SCG.IEqualityComparer equalityCompa ValidityCheck(); LinkedList retval = new(equalityComparer); - return Map(mapper, retval); + return Map(mapper, retval); } private IList Map(Func mapper, LinkedList retval) @@ -1358,7 +1358,7 @@ public IList Slide(int offset, int size) { if (!TrySlide(offset, size)) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(offset), $"{nameof(offset)} and {nameof(size)} combination is out of range"); } return this; @@ -1469,7 +1469,7 @@ public virtual void Reverse() if (_positions != null) { positions = _positions.ToArray(); - Sorting.IntroSort(positions, 0, positions.Length, PositionComparer.Default); + Sorting.IntroSort(positions, 0, positions.Length, PositionComparer.Default); poshigh = positions.Length - 1; } } @@ -1765,7 +1765,7 @@ public virtual void Shuffle(Random rnd) } DisposeOverlappingViews(false); - ArrayList a = new(); + ArrayList a = []; a.AddAll(this); a.Shuffle(rnd); Node cursor = startsentinel!.next!; @@ -2434,7 +2434,7 @@ public IList FindAll(Func filter) { ValidityCheck(); int stamp = this.stamp; - LinkedList retval = new(); + LinkedList retval = []; Node cursor = startsentinel!.next!; Node mcursor = retval.startsentinel!; @@ -2498,7 +2498,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { HashBag hashbag = new(itemEqualityComparer); @@ -2878,12 +2878,12 @@ public virtual bool Check() #region System.Collections.Generic.IList Members - void System.Collections.Generic.IList.RemoveAt(int index) + void SCG.IList.RemoveAt(int index) { RemoveAt(index); } - void System.Collections.Generic.ICollection.Add(T item) + void SCG.ICollection.Add(T item) { Add(item); } @@ -2901,7 +2901,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) { if (index < 0 || index + Count > arr.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(arr), $"{nameof(arr)} and {nameof(index)} combination is out of range"); } foreach (T item in this) diff --git a/C5/Sorting/Sorting.cs b/C5/Sorting/Sorting.cs index a6fecfe4..b9148178 100644 --- a/C5/Sorting/Sorting.cs +++ b/C5/Sorting/Sorting.cs @@ -26,7 +26,7 @@ public static void IntroSort(T[] array, int start, int count, SCG.IComparer array.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } new Sorter(array, comparer).IntroSort(start, start + count); @@ -56,7 +56,7 @@ public static void InsertionSort(T[] array, int start, int count, SCG.ICompar { if (start < 0 || count < 0 || start + count > array.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } new Sorter(array, comparer).InsertionSort(start, start + count); @@ -76,7 +76,7 @@ public static void HeapSort(T[] array, int start, int count, SCG.IComparer { if (start < 0 || count < 0 || start + count > array.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } new Sorter(array, comparer).HeapSort(start, start + count); diff --git a/C5/Trees/TreeBag.cs b/C5/Trees/TreeBag.cs index 595e0be1..115d550a 100644 --- a/C5/Trees/TreeBag.cs +++ b/C5/Trees/TreeBag.cs @@ -502,7 +502,7 @@ public T Current #region IDisposable Members - void System.IDisposable.Dispose() + void IDisposable.Dispose() { tree = null; valid = false; @@ -1972,12 +1972,12 @@ public void RetainAll(SCG.IEnumerable items) } #warning improve (mainly for bag) by using a Node iterator instead of ItemMultiplicities() - CircularQueue>? wasRemoved = null; + CircularQueue>? wasRemoved = null; if ((ActiveEvents & EventType.Removed) != 0) { - wasRemoved = new CircularQueue>(); - SCG.IEnumerator> ie = ItemMultiplicities().GetEnumerator(); - foreach (System.Collections.Generic.KeyValuePair p in t.ItemMultiplicities()) + wasRemoved = new CircularQueue>(); + SCG.IEnumerator> ie = ItemMultiplicities().GetEnumerator(); + foreach (SCG.KeyValuePair p in t.ItemMultiplicities()) { //We know p.Key is in this! while (ie.MoveNext()) @@ -1988,7 +1988,7 @@ public void RetainAll(SCG.IEnumerable items) int removed = ie.Current.Value - p.Value; if (removed > 0) { - wasRemoved.Enqueue(new System.Collections.Generic.KeyValuePair(p.Key, removed)); + wasRemoved.Enqueue(new SCG.KeyValuePair(p.Key, removed)); } break; @@ -2011,7 +2011,7 @@ public void RetainAll(SCG.IEnumerable items) blackdepth = t.blackdepth; if (wasRemoved != null) { - foreach (System.Collections.Generic.KeyValuePair p in wasRemoved) + foreach (SCG.KeyValuePair p in wasRemoved) { RaiseItemsRemoved(p.Key, p.Value); } @@ -2263,19 +2263,19 @@ public int ContainsCount(T item) //TODO: make work with snapshots - private class Multiplicities : CollectionValueBase>, ICollectionValue> + private class Multiplicities : CollectionValueBase>, ICollectionValue> { private readonly TreeBag treebag; private readonly int origstamp; internal Multiplicities(TreeBag treebag) { this.treebag = treebag; origstamp = treebag.stamp; } - public override System.Collections.Generic.KeyValuePair Choose() { return new System.Collections.Generic.KeyValuePair(treebag.root!.item, treebag.root.items); } + public override SCG.KeyValuePair Choose() { return new SCG.KeyValuePair(treebag.root!.item, treebag.root.items); } - public override SCG.IEnumerator> GetEnumerator() + public override SCG.IEnumerator> GetEnumerator() { return GetEnumerator(treebag.root!, origstamp); //TODO: NBNBNB } - private SCG.IEnumerator> GetEnumerator(Node node, int origstamp) + private SCG.IEnumerator> GetEnumerator(Node node, int origstamp) { if (node == null) { @@ -2284,7 +2284,7 @@ private class Multiplicities : CollectionValueBase> child = GetEnumerator(node.left, origstamp); + SCG.IEnumerator> child = GetEnumerator(node.left, origstamp); while (child.MoveNext()) { @@ -2292,10 +2292,10 @@ private class Multiplicities : CollectionValueBase(node.item, node.items); + yield return new SCG.KeyValuePair(node.item, node.items); if (node.right != null) { - SCG.IEnumerator> child = GetEnumerator(node.right, origstamp); + SCG.IEnumerator> child = GetEnumerator(node.right, origstamp); while (child.MoveNext()) { @@ -2306,7 +2306,7 @@ private class Multiplicities : CollectionValueBase treebag.IsEmpty; - public override int Count { get { int i = 0; foreach (System.Collections.Generic.KeyValuePair p in this) { i++; } return i; } } //TODO: make better + public override int Count { get { int i = 0; foreach (SCG.KeyValuePair p in this) { i++; } return i; } } //TODO: make better public override Speed CountSpeed => Speed.Linear; //TODO: make better } @@ -2331,7 +2331,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { if (!isValid) { @@ -2630,7 +2630,7 @@ public void RemoveInterval(int start, int count) if (start < 0 || count < 0 || start + count > size) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } UpdateCheck(); @@ -2873,7 +2873,7 @@ public override IDirectedCollectionValue Backwards() { return new Interval(tree, start, length, !forwards); } - IDirectedEnumerable C5.IDirectedEnumerable.Backwards() + IDirectedEnumerable IDirectedEnumerable.Backwards() { return Backwards(); } diff --git a/C5/Trees/TreeDictionary.cs b/C5/Trees/TreeDictionary.cs index ff3a78a2..09bb27c5 100644 --- a/C5/Trees/TreeDictionary.cs +++ b/C5/Trees/TreeDictionary.cs @@ -29,7 +29,7 @@ public TreeDictionary() : this(SCG.Comparer.Default, EqualityComparer.Defa private TreeDictionary(SCG.IComparer comparer, SCG.IEqualityComparer equalityComparer) : base(comparer, equalityComparer) { - pairs = sortedPairs = new TreeSet>(new KeyValuePairComparer(comparer)); + pairs = sortedPairs = new TreeSet>(new KeyValuePairComparer(comparer)); } #endregion diff --git a/C5/Trees/TreeSet.cs b/C5/Trees/TreeSet.cs index 08a234f4..51c55cd1 100644 --- a/C5/Trees/TreeSet.cs +++ b/C5/Trees/TreeSet.cs @@ -488,7 +488,7 @@ public T Current #region IDisposable Members - void System.IDisposable.Dispose() + void IDisposable.Dispose() { tree = null; valid = false; @@ -1859,12 +1859,12 @@ public void RetainAll(SCG.IEnumerable items) } #warning improve (mainly for bag) by using a Node iterator instead of ItemMultiplicities() - CircularQueue>? wasRemoved = null; + CircularQueue>? wasRemoved = null; if ((ActiveEvents & EventType.Removed) != 0) { - wasRemoved = new CircularQueue>(); - SCG.IEnumerator> ie = ItemMultiplicities().GetEnumerator(); - foreach (System.Collections.Generic.KeyValuePair p in t.ItemMultiplicities()) + wasRemoved = new CircularQueue>(); + SCG.IEnumerator> ie = ItemMultiplicities().GetEnumerator(); + foreach (SCG.KeyValuePair p in t.ItemMultiplicities()) { //We know p.Key is in this! while (ie.MoveNext()) @@ -1891,7 +1891,7 @@ public void RetainAll(SCG.IEnumerable items) blackdepth = t.blackdepth; if (wasRemoved != null) { - foreach (System.Collections.Generic.KeyValuePair p in wasRemoved) + foreach (SCG.KeyValuePair p in wasRemoved) { RaiseItemsRemoved(p.Key, p.Value); } @@ -2110,7 +2110,7 @@ public virtual ICollectionValue UniqueItems() /// /// /// - public virtual ICollectionValue> ItemMultiplicities() + public virtual ICollectionValue> ItemMultiplicities() { if (!isValid) { @@ -2365,7 +2365,7 @@ public void RemoveInterval(int start, int count) if (start < 0 || count < 0 || start + count > size) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} and {nameof(count)} combination is out of range"); } UpdateCheck(); @@ -2580,7 +2580,7 @@ public override IDirectedCollectionValue Backwards() { return new Interval(tree, start, length, !forwards); } - IDirectedEnumerable C5.IDirectedEnumerable.Backwards() + IDirectedEnumerable IDirectedEnumerable.Backwards() { return Backwards(); } diff --git a/C5/WrappedArray.cs b/C5/WrappedArray.cs index 55314744..a84eb203 100644 --- a/C5/WrappedArray.cs +++ b/C5/WrappedArray.cs @@ -2,6 +2,7 @@ // See https://github.com/sestoft/C5/blob/master/LICENSE for licensing details. using System; +using System.Drawing; using System.Text; using SCG = System.Collections.Generic; @@ -72,7 +73,7 @@ public T this[int index] /// /// /// - public IList Map(Func mapper) { return innerlist.Map(mapper); } + public IList Map(Func mapper) { return innerlist.Map(mapper); } /// /// @@ -81,7 +82,7 @@ public T this[int index] /// /// /// - public IList Map(Func mapper, SCG.IEqualityComparer equalityComparer) { return innerlist.Map(mapper, equalityComparer); } + public IList Map(Func mapper, SCG.IEqualityComparer equalityComparer) { return innerlist.Map(mapper, equalityComparer); } /// /// ???? should we throw NotRelevantException @@ -141,7 +142,7 @@ public void InsertLast(T item) /// /// /// - public void InsertAll(int i, System.Collections.Generic.IEnumerable items) + public void InsertAll(int i, SCG.IEnumerable items) { throw new FixedSizeCollectionException(); } @@ -422,14 +423,14 @@ public T RemoveLast() /// /// /// - public ICollectionValue> ItemMultiplicities() { return innerlist.ItemMultiplicities(); } + public ICollectionValue> ItemMultiplicities() { return innerlist.ItemMultiplicities(); } /// /// /// /// /// - public bool ContainsAll(System.Collections.Generic.IEnumerable items) + public bool ContainsAll(SCG.IEnumerable items) { return innerlist.ContainsAll(items); } /// @@ -501,7 +502,7 @@ public bool ContainsAll(System.Collections.Generic.IEnumerable items) /// /// /// - public void RemoveAll(System.Collections.Generic.IEnumerable items) { throw new FixedSizeCollectionException(); } + public void RemoveAll(SCG.IEnumerable items) { throw new FixedSizeCollectionException(); } /// /// @@ -512,7 +513,7 @@ public bool ContainsAll(System.Collections.Generic.IEnumerable items) /// /// /// - public void RetainAll(System.Collections.Generic.IEnumerable items) { throw new FixedSizeCollectionException(); } + public void RetainAll(SCG.IEnumerable items) { throw new FixedSizeCollectionException(); } #endregion @@ -556,7 +557,7 @@ public bool Add(T item) /// /// /// - public void AddAll(System.Collections.Generic.IEnumerable items) + public void AddAll(SCG.IEnumerable items) { throw new FixedSizeCollectionException(); } @@ -815,12 +816,12 @@ public void Dispose() #region System.Collections.Generic.IList Members - void System.Collections.Generic.IList.RemoveAt(int index) + void SCG.IList.RemoveAt(int index) { throw new FixedSizeCollectionException(); } - void System.Collections.Generic.ICollection.Add(T item) + void SCG.ICollection.Add(T item) { throw new FixedSizeCollectionException(); } @@ -838,7 +839,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) { if (index < 0 || index + Count > arr.Length) { - throw new ArgumentOutOfRangeException(nameof(index)); + throw new ArgumentOutOfRangeException(nameof(arr), $"{nameof(arr)} and {nameof(index)} combination is out of range"); } foreach (T item in this) @@ -854,7 +855,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) object? System.Collections.IList.this[int index] { get => this[index]!; - set + set { if (value is null && default(T) is not null) throw new ArgumentNullException(nameof(value)); if (value is not T) throw new ArgumentException("Wrong type", nameof(value)); diff --git a/C5/Wrappers/GuardedEnumerable.cs b/C5/Wrappers/GuardedEnumerable.cs index fbc0e0ff..0d2cef08 100644 --- a/C5/Wrappers/GuardedEnumerable.cs +++ b/C5/Wrappers/GuardedEnumerable.cs @@ -10,11 +10,11 @@ namespace C5; /// /// This is mainly interesting as a base of other guard classes /// -public class GuardedEnumerable : System.Collections.Generic.IEnumerable +public class GuardedEnumerable : IEnumerable { #region Fields - private readonly System.Collections.Generic.IEnumerable enumerable; + private readonly IEnumerable enumerable; #endregion @@ -24,7 +24,7 @@ public class GuardedEnumerable : System.Collections.Generic.IEnumerable /// Wrap an enumerable in a read-only wrapper /// /// The enumerable to wrap - public GuardedEnumerable(System.Collections.Generic.IEnumerable enumerable) + public GuardedEnumerable(IEnumerable enumerable) { this.enumerable = enumerable; } #endregion diff --git a/C5/Wrappers/GuardedList.cs b/C5/Wrappers/GuardedList.cs index 55444e06..3783dbcf 100644 --- a/C5/Wrappers/GuardedList.cs +++ b/C5/Wrappers/GuardedList.cs @@ -546,7 +546,7 @@ void System.Collections.ICollection.CopyTo(Array arr, int index) { if (index < 0 || index + Count > arr.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(arr), $"{nameof(arr)} and {nameof(index)} combination is out of range"); } foreach (T item in this)