From f4548e0b781efe8e05bc3b014b2e8d8c93e315b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 12:37:01 +0200 Subject: [PATCH 01/14] Replace custom string comparer with built-in. Replace custom array equals with NUnit version --- C5.Tests/Arrays/ArrayListTest.cs | 33 ++------- C5.Tests/Arrays/SortedArrayTests.cs | 10 +-- C5.Tests/BasesTest.cs | 69 +++++++++--------- C5.Tests/SupportClasses.cs | 81 ++++------------------ C5.Tests/Trees/Bag.cs | 40 +++++------ C5.Tests/Trees/Dictionary.cs | 8 +-- C5.Tests/Trees/RedBlackTreeSetTests.cs | 6 +- C5.UserGuideExamples/KeywordRecognition.cs | 4 +- 8 files changed, 84 insertions(+), 167 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index 510efdad..d78fbad9 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -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() { diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index 903e67c4..b24f0845 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -1818,21 +1818,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 +1837,6 @@ public void Map() }); } - [Test] public void BadMap() { @@ -1849,7 +1845,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")); } diff --git a/C5.Tests/BasesTest.cs b/C5.Tests/BasesTest.cs index b9c5cbfd..1b129e28 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)); @@ -162,7 +161,7 @@ public void PrimitiveComparersViaBuilder() [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,7 +484,7 @@ 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))); } @@ -493,7 +492,7 @@ public void SeqequalityComparerViaBuilder2() public void UnseqequalityComparerViaBuilder2() { SCG.IEqualityComparer> h = EqualityComparer>.Default; - C5.HashSet s = new() { 1, 2, 3 }; + C5.HashSet s = [1, 2, 3]; Assert.That(h.GetHashCode(s), Is.EqualTo(CHC.UnsequencedHashCode(1, 2, 3))); } @@ -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/SupportClasses.cs b/C5.Tests/SupportClasses.cs index d767163c..c66bd1e1 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -7,19 +7,6 @@ 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() { } @@ -77,6 +64,7 @@ public static bool Eq(SCG.IEnumerable me, params int[] that) return i == maxind + 1; } + public static bool SetEq(ICollectionValue me, params int[] that) { int[] me2 = me.ToArray(); @@ -177,16 +165,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 +425,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 +493,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 +508,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/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 0ddb53c4..908e8c71 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -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); } @@ -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); @@ -854,7 +854,7 @@ public class UniqueItems private TreeBag list; [SetUp] - public void Init() { list = new TreeBag(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -882,7 +882,7 @@ public class UniqueItemCount private TreeBag list; [SetUp] - public void Init() { list = new TreeBag(); } + public void Init() { list = []; } [TearDown] public void Dispose() { list.Dispose(); } @@ -1091,7 +1091,7 @@ public void Init() public void Dispose() { tree.Dispose(); } - private string aeq(int[] a, params int[] b) + private static string Aeq(int[] a, params int[] b) { if (a.Length != b.Length) { @@ -1102,7 +1102,7 @@ private string aeq(int[] a, params int[] b) { if (a[i] != b[i]) { - return string.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]); + return $"{i}'th elements differ: {a[i]} != {b[i]}"; } } @@ -1113,11 +1113,11 @@ private string aeq(int[] a, params int[] b) [Test] public void ToArray() { - Assert.That(aeq(tree.ToArray()), Is.EqualTo("Alles klar")); + Assert.That(Aeq(tree.ToArray()), Is.EqualTo("Alles klar")); tree.Add(4); tree.Add(7); tree.Add(4); - Assert.That(aeq(tree.ToArray(), 4, 4, 7), Is.EqualTo("Alles klar")); + Assert.That(Aeq(tree.ToArray(), 4, 4, 7), Is.EqualTo("Alles klar")); } @@ -1125,19 +1125,19 @@ 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(Aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); 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(Aeq(a, 1000, 1001, 6, 6, 1004, 1005, 1006, 1007, 1008, 1009), Is.EqualTo("Alles klar")); 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(Aeq(a, 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 1009), Is.EqualTo("Alles klar")); 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(Aeq(a, 1000, 1001, 6, 6, 4, 6, 6, 9, 1008, 7), Is.EqualTo("Alles klar")); } @@ -2805,7 +2805,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 +2813,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 +2843,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")); @@ -3376,8 +3376,8 @@ public void GetRange() [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(); @@ -3415,8 +3415,8 @@ public void GetRangeBackwards() [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(); diff --git a/C5.Tests/Trees/Dictionary.cs b/C5.Tests/Trees/Dictionary.cs index 50f39811..9ceee1b2 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] @@ -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" }, @@ -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", @@ -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..f90f4738 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -2399,13 +2399,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 +2432,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")); } 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(); From bde58cb714f1dd4c03f4d3db45d1ee8cbe136355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 12:44:07 +0200 Subject: [PATCH 02/14] Replace aeq with NUnit equals --- C5.Tests/Arrays/HashedArrayListTest.cs | 38 +++++--------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index 99e0fa03..69b86620 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -511,7 +511,7 @@ public class BadEnumerable [SetUp] public void Init() { - list = new HashedArrayList(); + list = []; } [Test] @@ -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() { From d121ad62ef19a95a822307f9ccd209272d7c049c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 12:57:47 +0200 Subject: [PATCH 03/14] Replace custom array equals with NUnit Is.EqualTo --- C5.Tests/Arrays/SortedArrayTests.cs | 31 ++++------------- C5.Tests/Hashing/HashBagTests.cs | 33 ++++-------------- C5.Tests/Hashing/HashTableTests.cs | 33 ++++-------------- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 33 ++++-------------- C5.Tests/LinkedLists/LinkedListTest.cs | 33 ++++-------------- C5.Tests/Trees/Bag.cs | 33 ++++-------------- C5.Tests/Trees/RedBlackTreeSetTests.cs | 35 ++++---------------- 7 files changed, 42 insertions(+), 189 deletions(-) diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index b24f0845..a4f40c46 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -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 })); } diff --git a/C5.Tests/Hashing/HashBagTests.cs b/C5.Tests/Hashing/HashBagTests.cs index f2f0cc68..9f06f64d 100644 --- a/C5.Tests/Hashing/HashBagTests.cs +++ b/C5.Tests/Hashing/HashBagTests.cs @@ -535,30 +535,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 +547,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 })); } diff --git a/C5.Tests/Hashing/HashTableTests.cs b/C5.Tests/Hashing/HashTableTests.cs index 4ad49246..f44e09c6 100644 --- a/C5.Tests/Hashing/HashTableTests.cs +++ b/C5.Tests/Hashing/HashTableTests.cs @@ -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() { diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index 7fffb4cb..fe2fd764 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -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] diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index c4f36b45..13603ca3 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -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] diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 908e8c71..f840981d 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -1090,54 +1090,33 @@ public void Init() [TearDown] public void Dispose() { tree.Dispose(); } - - private static 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 $"{i}'th elements differ: {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 })); } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index f90f4738..c7f5aaeb 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -635,7 +635,6 @@ public class ArrayTest private TreeSet tree; private int[] a; - [SetUp] public void Init() { @@ -647,58 +646,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() { From 83d0c01d1259eba4ef966b69886dfaaa456cbc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 13:33:24 +0200 Subject: [PATCH 04/14] Fix more warnings and messages --- C5.Tests/Arrays/SortedArrayTests.cs | 4 +- C5.Tests/SupportClasses.cs | 7 +- C5.Tests/Trees/Bag.cs | 4 +- C5.Tests/Trees/RedBlackTreeSetTests.cs | 4 +- C5.UserGuideExamples/EventPatterns.cs | 27 ++--- C5.UserGuideExamples/Extensions.cs | 20 +--- C5.UserGuideExamples/Graph.cs | 135 ++++++++++++++----------- C5.UserGuideExamples/JobQueue.cs | 38 ++----- C5/Arrays/HashedArrayList.cs | 4 +- C5/BaseClasses/CollectionBase.cs | 15 +-- C5/BaseClasses/CollectionValueBase.cs | 3 +- C5/Hashing/HashBag.cs | 4 +- C5/LinkedLists/HashedLinkedList.cs | 4 +- C5/LinkedLists/LinkedList.cs | 4 +- C5/Sorting/Sorting.cs | 6 +- C5/Trees/TreeBag.cs | 2 +- C5/Trees/TreeSet.cs | 2 +- C5/WrappedArray.cs | 3 +- C5/Wrappers/GuardedList.cs | 2 +- 19 files changed, 131 insertions(+), 157 deletions(-) diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index a4f40c46..dd3c3a85 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -2576,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); } @@ -2690,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/SupportClasses.cs b/C5.Tests/SupportClasses.cs index c66bd1e1..3d7bcaf3 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -96,12 +96,9 @@ public static bool SetEq(ICollectionValue> me, params } } - 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 diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index f840981d..e4eeae13 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -3456,7 +3456,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); } @@ -3570,7 +3570,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/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index c7f5aaeb..c903f28c 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -3166,7 +3166,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); } @@ -3279,7 +3279,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.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/Graph.cs b/C5.UserGuideExamples/Graph.cs index 41af878e..87dc7b9c 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) @@ -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> @@ -724,9 +743,9 @@ public int ComponentCount } } - public ICollectionValue>> Components() + public ICollectionValue>> Components() { - ArrayList>> retval = new(); + ArrayList>> retval = new(); HashGraph component; ArrayList vertices = null; void edgeaction(Edge e) @@ -747,12 +766,12 @@ void aftercomponent(V v) { //component.graph[start] = graph[start].Clone(); HashDictionary edgeset = component._graph[start] = new HashDictionary(); - foreach (System.Collections.Generic.KeyValuePair adjacent in _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) @@ -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); diff --git a/C5.UserGuideExamples/JobQueue.cs b/C5.UserGuideExamples/JobQueue.cs index e320247b..306a2a1e 100644 --- a/C5.UserGuideExamples/JobQueue.cs +++ b/C5.UserGuideExamples/JobQueue.cs @@ -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/Arrays/HashedArrayList.cs b/C5/Arrays/HashedArrayList.cs index 2fed561d..1b42cab7 100644 --- a/C5/Arrays/HashedArrayList.cs +++ b/C5/Arrays/HashedArrayList.cs @@ -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; @@ -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/BaseClasses/CollectionBase.cs b/C5/BaseClasses/CollectionBase.cs index badc8a78..968c6e18 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; @@ -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, System.Collections.Generic.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)); } diff --git a/C5/BaseClasses/CollectionValueBase.cs b/C5/BaseClasses/CollectionValueBase.cs index 0f94a168..1db82312 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) diff --git a/C5/Hashing/HashBag.cs b/C5/Hashing/HashBag.cs index 6b3f8984..11c1135a 100644 --- a/C5/Hashing/HashBag.cs +++ b/C5/Hashing/HashBag.cs @@ -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++) { diff --git a/C5/LinkedLists/HashedLinkedList.cs b/C5/LinkedLists/HashedLinkedList.cs index 0a96c5ea..9e05f928 100644 --- a/C5/LinkedLists/HashedLinkedList.cs +++ b/C5/LinkedLists/HashedLinkedList.cs @@ -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; @@ -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..69969015 100644 --- a/C5/LinkedLists/LinkedList.cs +++ b/C5/LinkedLists/LinkedList.cs @@ -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; @@ -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..be996342 100644 --- a/C5/Trees/TreeBag.cs +++ b/C5/Trees/TreeBag.cs @@ -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(); diff --git a/C5/Trees/TreeSet.cs b/C5/Trees/TreeSet.cs index 08a234f4..e2415fe6 100644 --- a/C5/Trees/TreeSet.cs +++ b/C5/Trees/TreeSet.cs @@ -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(); diff --git a/C5/WrappedArray.cs b/C5/WrappedArray.cs index 55314744..063ed85e 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; @@ -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) 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) From 385f277108022946e2daaaf2abc180616870e344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 13:59:04 +0200 Subject: [PATCH 05/14] Simplify namespace and type params --- C5.Tests/Arrays/ArrayListTest.cs | 56 +++++++++---------- C5.Tests/Arrays/CircularQueueTest.cs | 6 +- C5.Tests/Arrays/HashedArrayListTest.cs | 6 +- C5.Tests/Arrays/SortedArrayTests.cs | 36 ++++++------ C5.Tests/BasesTest.cs | 36 ++++++------ C5.Tests/Hashing/HashBagTests.cs | 6 +- C5.Tests/Hashing/HashDictionaryTests.cs | 12 ++-- C5.Tests/Hashing/HashTableTests.cs | 20 +++---- C5.Tests/Heaps/HeapTests.cs | 4 +- C5.Tests/InterfacesTest.cs | 2 +- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 8 +-- C5.Tests/LinkedLists/LinkedListTest.cs | 12 ++-- C5.Tests/Sorting.cs | 32 +++++------ C5.Tests/SupportClasses.cs | 2 +- C5.Tests/Templates/Events.cs | 12 ++-- C5.Tests/Templates/GenericCollectionTester.cs | 2 +- C5.Tests/Trees/Bag.cs | 55 ++++++++---------- C5.Tests/Trees/Dictionary.cs | 12 ++-- C5.Tests/Trees/RedBlackTreeSetTests.cs | 6 +- C5.Tests/WrappersTest.cs | 8 +-- C5.UserGuideExamples/CommonWords.cs | 2 +- C5.UserGuideExamples/GNfaToDfa.cs | 2 +- C5.UserGuideExamples/MultiDictionary.cs | 6 +- C5.UserGuideExamples/MultiDictionary2.cs | 6 +- C5.UserGuideExamples/PointLocation.cs | 18 +++--- C5.UserGuideExamples/SortingPermutation.cs | 6 +- C5/Arrays/ArrayList.cs | 16 +++--- C5/Arrays/HashedArrayList.cs | 36 ++++++------ C5/Arrays/SortedArray.cs | 4 +- C5/BaseClasses/ArrayBase.cs | 2 +- C5/BaseClasses/CollectionBase.cs | 12 ++-- C5/BaseClasses/CollectionValueBase.cs | 2 +- C5/BaseClasses/DictionaryBase.cs | 6 +- C5/Comparers/KeyValuePairComparer.cs | 8 +-- C5/Dictionaries/SortedDictionaryBase.cs | 2 +- C5/Hashing/HashBag.cs | 26 ++++----- C5/Hashing/HashSet.cs | 2 +- C5/Interfaces/ICollection.cs | 2 +- C5/Interfaces/IDictionary.cs | 2 +- C5/Interfaces/IExtensible.cs | 2 +- C5/Interfaces/IList.cs | 6 +- C5/Interfaces/ISorted.cs | 2 +- C5/Interfaces/ISortedDictionary.cs | 2 +- C5/LinkedLists/HashedLinkedList.cs | 12 ++-- C5/LinkedLists/LinkedList.cs | 12 ++-- C5/Trees/TreeBag.cs | 34 +++++------ C5/Trees/TreeDictionary.cs | 2 +- C5/Trees/TreeSet.cs | 16 +++--- C5/WrappedArray.cs | 22 ++++---- C5/Wrappers/GuardedEnumerable.cs | 6 +- 50 files changed, 299 insertions(+), 310 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index d78fbad9..ff7c2173 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); } @@ -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; }; } @@ -2075,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); } @@ -2090,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(() => { @@ -2098,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); @@ -2111,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(() => { @@ -2119,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); } @@ -2127,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(() => { @@ -2135,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); @@ -2163,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(() => { @@ -2173,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); } } @@ -2211,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 IC()); - 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(() => { @@ -2295,7 +2295,7 @@ public void Shuffle() lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); + Sorting.IntroSort(lst2); Assert.That(IC.Eq(lst2, 3, 5, 5, 6, 7), Is.True, "Contents " + i); } } diff --git a/C5.Tests/Arrays/CircularQueueTest.cs b/C5.Tests/Arrays/CircularQueueTest.cs index e8e66fde..6ed4fdec 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] @@ -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 69b86620..aeca16ae 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] @@ -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; }; } diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index dd3c3a85..fb31c5a5 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); } } @@ -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 IC())); } @@ -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; }; } @@ -587,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 IC())); 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)); } } @@ -607,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(() => { @@ -615,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); } @@ -623,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(() => { @@ -631,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); @@ -644,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(() => { @@ -652,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); } @@ -660,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(() => { @@ -668,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); @@ -723,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(() => { @@ -733,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); } } diff --git a/C5.Tests/BasesTest.cs b/C5.Tests/BasesTest.cs index 1b129e28..3b1f78de 100644 --- a/C5.Tests/BasesTest.cs +++ b/C5.Tests/BasesTest.cs @@ -143,18 +143,18 @@ private static 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 @@ -491,8 +491,8 @@ public void SeqequalityComparerViaBuilder2() [Test] public void UnseqequalityComparerViaBuilder2() { - SCG.IEqualityComparer> h = EqualityComparer>.Default; - C5.HashSet s = [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))); } @@ -500,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() { } @@ -540,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(); } diff --git a/C5.Tests/Hashing/HashBagTests.cs b/C5.Tests/Hashing/HashBagTests.cs index 9f06f64d..2d44e3cb 100644 --- a/C5.Tests/Hashing/HashBagTests.cs +++ b/C5.Tests/Hashing/HashBagTests.cs @@ -11,8 +11,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] @@ -453,7 +453,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; }; } diff --git a/C5.Tests/Hashing/HashDictionaryTests.cs b/C5.Tests/Hashing/HashDictionaryTests.cs index f7cc833d..dca835a5 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); } } @@ -75,20 +75,20 @@ public void Init() [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 = new(); for (int i = 0; i < 5; i++) { diff --git a/C5.Tests/Hashing/HashTableTests.cs b/C5.Tests/Hashing/HashTableTests.cs index f44e09c6..c03faa61 100644 --- a/C5.Tests/Hashing/HashTableTests.cs +++ b/C5.Tests/Hashing/HashTableTests.cs @@ -12,8 +12,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); } } @@ -315,7 +315,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; }; } @@ -796,16 +796,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)); } } @@ -817,7 +817,7 @@ public void Init() [Test] public void Find() { - System.Collections.Generic.KeyValuePair p = new(3, 78); + SCG.KeyValuePair p = new(3, 78); Assert.Multiple(() => { @@ -825,7 +825,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); } @@ -917,7 +917,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(); @@ -926,7 +926,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); } } diff --git a/C5.Tests/Heaps/HeapTests.cs b/C5.Tests/Heaps/HeapTests.cs index 0cb3810e..1fc62d72 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); } } diff --git a/C5.Tests/InterfacesTest.cs b/C5.Tests/InterfacesTest.cs index 91abba2a..9f8f1d34 100644 --- a/C5.Tests/InterfacesTest.cs +++ b/C5.Tests/InterfacesTest.cs @@ -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 fe2fd764..4ba079b6 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] @@ -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; }; } @@ -1638,7 +1638,7 @@ public void Shuffle() lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); + Sorting.IntroSort(lst2); Assert.That(IC.Eq(lst2, 3, 5, 6, 7), Is.True, "Contents " + i); } } diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index 13603ca3..053206da 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] @@ -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; }; } @@ -1661,7 +1661,7 @@ public void Shuffle() lst.Shuffle(new C5Random(i + 1)); Assert.That(lst.Check(), Is.True, "Check " + i); int[] lst2 = lst.ToArray(); - Sorting.IntroSort(lst2); + Sorting.IntroSort(lst2); Assert.That(IC.Eq(lst2, 3, 5, 5, 6, 7), Is.True, "Contents " + i); } } diff --git a/C5.Tests/Sorting.cs b/C5.Tests/Sorting.cs index 33bb80c4..310ff8fb 100644 --- a/C5.Tests/Sorting.cs +++ b/C5.Tests/Sorting.cs @@ -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); @@ -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); @@ -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); @@ -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 3d7bcaf3..d4e1ebca 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -11,7 +11,7 @@ internal class TenEqualityComparer : SCG.IEqualityComparer, SCG.IComparer new(); + public static TenEqualityComparer Instance => new(); public int GetHashCode(int item) { return (item / 10).GetHashCode(); } 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 e4eeae13..ec2efd68 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); } } @@ -792,7 +792,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; }; } @@ -2127,7 +2127,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)); @@ -2136,7 +2136,7 @@ public void Bug20120422_1() [Test] public void Bug20120422_2() { - var coll = new C5.TreeBag + var coll = new TreeBag { "B", "A", @@ -3031,29 +3031,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 IC()); + } [Test] public void EmptyEmpty() { - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FunEnumerable(0, i => i * i)); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } - [Test] public void SomeEmpty() { @@ -3062,19 +3055,19 @@ public void SomeEmpty() tree.Add(i); } - tree.AddSorted(new FunEnumerable(0, new Func(sqr))); + tree.AddSorted(new FunEnumerable(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 FunEnumerable(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)); @@ -3086,11 +3079,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 FunEnumerable(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)); @@ -3099,7 +3092,6 @@ public void EmptySome2() }); } - [Test] public void SomeSome() { @@ -3109,37 +3101,34 @@ public void SomeSome() } tree.Add(1); + tree.AddSorted(new FunEnumerable(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); }); } - [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 FunEnumerable(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() { diff --git a/C5.Tests/Trees/Dictionary.cs b/C5.Tests/Trees/Dictionary.cs index 9ceee1b2..4a9cab07 100644 --- a/C5.Tests/Trees/Dictionary.cs +++ b/C5.Tests/Trees/Dictionary.cs @@ -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")); @@ -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")); @@ -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); } } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index c903f28c..98efccc6 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); } } @@ -545,7 +545,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; }; } diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index 2f5ca709..ce198632 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); } @@ -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 ]")); @@ -800,7 +800,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 ]")); 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/GNfaToDfa.cs b/C5.UserGuideExamples/GNfaToDfa.cs index 1bc1028a..ccdd4b60 100644 --- a/C5.UserGuideExamples/GNfaToDfa.cs +++ b/C5.UserGuideExamples/GNfaToDfa.cs @@ -120,7 +120,7 @@ public void AddTrans(int s1, string lab, int s2) 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); diff --git a/C5.UserGuideExamples/MultiDictionary.cs b/C5.UserGuideExamples/MultiDictionary.cs index c64b5d15..ca159b1f 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) { @@ -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..d0e8fe6a 100644 --- a/C5.UserGuideExamples/MultiDictionary2.cs +++ b/C5.UserGuideExamples/MultiDictionary2.cs @@ -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..c8180a1d 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 = new TreeDictionary>, LinkedList>>>(); } public PointLocator(SCG.IEnumerable> edges) { //htree = new TreeDictionary>>(dc); - endpoints = new TreeDictionary>, LinkedList>>>(); + endpoints = new TreeDictionary>, LinkedList>>>(); 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>>(new LinkedList>(), new 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>>(new LinkedList>(), new LinkedList>())); } kv = endpoints[edge.Xe]; @@ -214,7 +214,7 @@ public void Build() htree[double.NegativeInfinity] = (ISorted>)(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) { @@ -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/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/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 1b42cab7..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"); @@ -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); } 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 968c6e18..a93b8b23 100644 --- a/C5/BaseClasses/CollectionBase.cs +++ b/C5/BaseClasses/CollectionBase.cs @@ -31,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 @@ -69,7 +69,7 @@ protected void CheckRange(int start, int count) /// The collection to compute hash code for /// 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; @@ -116,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)) { @@ -147,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(); @@ -319,7 +319,7 @@ protected virtual void UpdateCheck() /// /// /// - public virtual System.Collections.Generic.IEqualityComparer EqualityComparer => itemEqualityComparer; + public virtual SCG.IEqualityComparer EqualityComparer => itemEqualityComparer; /// /// @@ -334,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 1db82312..cc4bea8f 100644 --- a/C5/BaseClasses/CollectionValueBase.cs +++ b/C5/BaseClasses/CollectionValueBase.cs @@ -604,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 11c1135a..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)) { @@ -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..36c263bc 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); } 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 9e05f928..f2ae3297 100644 --- a/C5/LinkedLists/HashedLinkedList.cs +++ b/C5/LinkedLists/HashedLinkedList.cs @@ -1508,7 +1508,7 @@ public IList Map(Func mapper) Validitycheck(); HashedLinkedList retval = new(); - return Map(mapper, 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) @@ -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; } } @@ -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); } diff --git a/C5/LinkedLists/LinkedList.cs b/C5/LinkedLists/LinkedList.cs index 69969015..841ef18f 100644 --- a/C5/LinkedLists/LinkedList.cs +++ b/C5/LinkedLists/LinkedList.cs @@ -1121,7 +1121,7 @@ public IList Map(Func mapper) ValidityCheck(); LinkedList retval = new(); - return Map(mapper, 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) @@ -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; } } @@ -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); } diff --git a/C5/Trees/TreeBag.cs b/C5/Trees/TreeBag.cs index be996342..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) { @@ -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 e2415fe6..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) { @@ -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 063ed85e..a84eb203 100644 --- a/C5/WrappedArray.cs +++ b/C5/WrappedArray.cs @@ -73,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); } /// /// @@ -82,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 @@ -142,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(); } @@ -423,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); } /// @@ -502,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(); } /// /// @@ -513,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 @@ -557,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(); } @@ -816,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(); } @@ -855,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 From f6f1a01e47641fbf5ac94899d329471ae96c7a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 14:32:28 +0200 Subject: [PATCH 06/14] Replace custom collection equality with NUnit Is.EqualTo and Is.EquivalentTo --- C5.Tests/Arrays/ArrayListTest.cs | 180 +++++++++---------- C5.Tests/Arrays/HashedArrayListTest.cs | 126 ++++++------- C5.Tests/Arrays/SortedArrayTests.cs | 12 +- C5.Tests/Hashing/HashBagTests.cs | 68 ++++--- C5.Tests/Hashing/HashDictionaryTests.cs | 4 +- C5.Tests/Hashing/HashTableTests.cs | 100 ++++++----- C5.Tests/Heaps/HeapTests.cs | 6 +- C5.Tests/InterfacesTest.cs | 6 +- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 120 ++++++------- C5.Tests/LinkedLists/LinkedListTest.cs | 174 +++++++++--------- C5.Tests/SupportClasses.cs | 30 ---- C5.Tests/Trees/Bag.cs | 8 +- C5.Tests/Trees/RedBlackTreeSetTests.cs | 10 +- C5.Tests/WrappersTest.cs | 16 +- C5.UserGuideExamples/AnagramHashBag.cs | 2 +- C5.UserGuideExamples/AnagramTreeBag.cs | 2 +- C5.UserGuideExamples/Anagrams.cs | 2 +- C5.UserGuideExamples/BipartiteMatching.cs | 6 +- C5.UserGuideExamples/CollectionSanity.cs | 6 +- C5.UserGuideExamples/FileIndex.cs | 2 +- C5.UserGuideExamples/GNfaToDfa.cs | 10 +- C5.UserGuideExamples/Graph.cs | 24 +-- C5.UserGuideExamples/HashCodes.cs | 2 +- C5.UserGuideExamples/IndexedObjects.cs | 2 +- C5.UserGuideExamples/IndexedObjects2.cs | 4 +- C5.UserGuideExamples/JobQueue.cs | 2 +- C5.UserGuideExamples/Locking.cs | 12 +- C5.UserGuideExamples/MultiDictionary.cs | 8 +- C5.UserGuideExamples/MultiDictionary2.cs | 8 +- C5.UserGuideExamples/PointLocation.cs | 12 +- C5.UserGuideExamples/RandomSelection.cs | 2 +- C5.UserGuideExamples/UnionFind.cs | 2 +- C5/Hashing/HashSet.cs | 2 +- C5/LinkedLists/HashedLinkedList.cs | 10 +- C5/LinkedLists/LinkedList.cs | 10 +- 35 files changed, 478 insertions(+), 512 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index ff7c2173..2be20f15 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -591,7 +591,7 @@ public class BadEnumerable [SetUp] public void Init() { - list = new ArrayList(); + list = []; } [Test] @@ -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,7 +960,7 @@ 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); @@ -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++) { @@ -1164,7 +1164,7 @@ public class Searching [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] public void NullEqualityComparerinConstructor1() @@ -1268,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); @@ -1287,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); @@ -1317,7 +1317,7 @@ public void RetainAll() [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); @@ -1417,7 +1417,7 @@ public class Searching [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; } @@ -1459,7 +1459,7 @@ public class Removing [SetUp] public void Init() { - dit = new ArrayList(); + dit = []; } @@ -2313,7 +2313,7 @@ public class Stack [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] @@ -2354,7 +2354,7 @@ public class Queue private ArrayList list; [SetUp] - public void Init() { list = new ArrayList(); } + public void Init() { list = []; } [Test] public void Normal() @@ -2502,7 +2502,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); } @@ -2703,7 +2703,7 @@ public void Add() Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); }); - ArrayList lst2 = new() { 90, 92 }; + ArrayList lst2 = [90, 92]; view.AddAll(lst2); check(); Assert.Multiple(() => @@ -2747,7 +2747,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); @@ -2989,7 +2989,7 @@ public void Remove() view.FIFO = false; - ArrayList l2 = new() { 1, 2, 2, 3, 1 }; + ArrayList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); @@ -3115,7 +3115,7 @@ public class MulipleViews [SetUp] public void Init() { - list = new ArrayList(); + list = []; for (int i = 0; i < 6; i++) { list.Add(i); @@ -3313,7 +3313,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); @@ -3334,7 +3334,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); @@ -3355,13 +3355,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); @@ -3376,7 +3376,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); @@ -3447,7 +3447,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); @@ -3518,13 +3518,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); @@ -3633,15 +3633,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 = []; } @@ -3696,15 +3696,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 = []; } @@ -3765,17 +3765,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] @@ -3836,17 +3836,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 = []; } @@ -3904,9 +3904,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; } [Test] @@ -4027,9 +4027,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new ArrayList(); - dat = new ArrayList(); - dut = new ArrayList(); + dit = []; + dat = []; + dut = []; } [Test] @@ -4150,15 +4150,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 = []; } @@ -4209,15 +4209,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 = []; } @@ -4269,18 +4269,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 = []; } @@ -4339,18 +4339,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/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index aeca16ae..6bdee308 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -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,7 +884,7 @@ 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); @@ -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++) { @@ -1086,7 +1086,7 @@ public class Searching [SetUp] - public void Init() { list = new HashedArrayList(); } + public void Init() { list = []; } [Test] @@ -1201,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); @@ -1216,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); @@ -1246,7 +1246,7 @@ public void RetainAll() [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); @@ -1326,7 +1326,7 @@ public class Searching [SetUp] public void Init() { - dit = new HashedArrayList(); + dit = []; } @@ -1367,7 +1367,7 @@ public class Removing [SetUp] public void Init() { - dit = new HashedArrayList(); + dit = []; } [Test] @@ -2211,7 +2211,7 @@ public class Range [SetUp] - public void Init() { lst = new HashedArrayList(); } + public void Init() { lst = []; } [TearDown] @@ -2309,13 +2309,13 @@ public class Simple [SetUp] public void Init() { - list = new HashedArrayList - { + list = + [ 0, 1, 2, 3 - }; + ]; view = (HashedArrayList)list.View(1, 2); } @@ -2516,11 +2516,11 @@ public void Add() Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); }); - HashedArrayList lst2 = new() - { + HashedArrayList lst2 = + [ 90, 92 - }; + ]; view.AddAll(lst2); check(); Assert.Multiple(() => @@ -2563,10 +2563,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(() => @@ -2757,14 +2757,14 @@ public void Remove() 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); - HashedArrayList l2 = new() - { + HashedArrayList l2 = + [ 1, 2, 2, 3, 1 - }; + ]; view.RemoveAll(l2); check(); Assert.That(IC.Eq(view, 5), Is.True); @@ -3435,9 +3435,9 @@ public class IIndexed [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; } @@ -3562,9 +3562,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new HashedArrayList(); - dat = new HashedArrayList(); - dut = new HashedArrayList(); + dit = []; + dat = []; + dut = []; } @@ -3689,15 +3689,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 = []; } @@ -3750,15 +3750,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 = []; } @@ -3812,18 +3812,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 = []; } @@ -3882,18 +3882,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 fb31c5a5..d3446b8a 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -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) })); }); } } @@ -697,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); @@ -710,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; diff --git a/C5.Tests/Hashing/HashBagTests.cs b/C5.Tests/Hashing/HashBagTests.cs index 2d44e3cb..e9f6d7db 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] @@ -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() { @@ -348,7 +348,7 @@ public void RemoveAllCopies() [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() { @@ -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++) { @@ -607,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 dca835a5..406ffe26 100644 --- a/C5.Tests/Hashing/HashDictionaryTests.cs +++ b/C5.Tests/Hashing/HashDictionaryTests.cs @@ -68,7 +68,7 @@ public class HashDict [SetUp] public void Init() { - dict = new HashDictionary(); + dict = []; //dict = TreeDictionary.MakeNaturalO(); } @@ -261,7 +261,7 @@ public void CombinedOps() [Test] public void DeepBucket() { - DictionaryIntToInt 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 c03faa61..2ba0cef1 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 { @@ -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; } } @@ -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++) { @@ -468,7 +468,7 @@ public class Collision [SetUp] public void Init() { - hashset = new HashSet(); + hashset = []; } @@ -503,7 +503,7 @@ public class Searching public void Init() { Debug.UseDeterministicHashing = true; - hashset = new HashSet(); + hashset = []; } @@ -615,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)); } @@ -664,7 +664,7 @@ public void RemoveAllCopies() [Test] public void ContainsAll() { - HashSet list2 = new(); + HashSet list2 = []; Assert.That(hashset.ContainsAll(list2), Is.True); list2.Add(4); @@ -683,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 @@ -711,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); @@ -730,7 +730,7 @@ 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); @@ -756,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() { @@ -1135,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 = []; } @@ -1193,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 1fc62d72..9862f4cf 100644 --- a/C5.Tests/Heaps/HeapTests.cs +++ b/C5.Tests/Heaps/HeapTests.cs @@ -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 9f8f1d34..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)); } } diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index 4ba079b6..d25d13c1 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -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,7 +290,7 @@ 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); @@ -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++) { @@ -500,7 +500,7 @@ public class Searching [SetUp] - public void Init() { list = new HashedLinkedList(); } + public void Init() { list = []; } [Test] @@ -604,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); @@ -619,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); @@ -649,7 +649,7 @@ public void RetainAll() [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); @@ -729,7 +729,7 @@ public class Searching [SetUp] public void Init() { - dit = new HashedLinkedList(); + dit = []; } @@ -772,7 +772,7 @@ public class Removing [SetUp] public void Init() { - dit = new HashedLinkedList(); + dit = []; } [Test] @@ -876,7 +876,7 @@ public class Searching [SetUp] - public void Init() { lst = new HashedLinkedList(); } + public void Init() { lst = []; } [TearDown] @@ -1622,7 +1622,7 @@ public class ShuffleTests [SetUp] - public void Init() { lst = new HashedLinkedList(); } + public void Init() { lst = []; } [TearDown] @@ -1651,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); @@ -1664,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); @@ -1682,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); @@ -1695,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); @@ -1819,7 +1819,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); } @@ -2018,7 +2018,7 @@ public void Add() Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); }); - HashedLinkedList lst2 = new() { 90, 92 }; + HashedLinkedList lst2 = [90, 92]; view.AddAll(lst2); check(); @@ -2062,7 +2062,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(() => @@ -2248,7 +2248,7 @@ public void Remove() 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); - HashedLinkedList l2 = new() { 1, 2, 2, 3, 1 }; + HashedLinkedList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); @@ -2901,9 +2901,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3028,9 +3028,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new HashedLinkedList(); - dat = new HashedLinkedList(); - dut = new HashedLinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3158,15 +3158,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 = []; } @@ -3219,15 +3219,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 = []; } @@ -3281,18 +3281,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 = []; } @@ -3351,18 +3351,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 053206da..32ae335f 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -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,7 +293,7 @@ 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); @@ -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++) { @@ -483,7 +483,7 @@ public class Sync [SetUp] public void Init() { - list = new LinkedList(); + list = []; } [TearDown] @@ -505,7 +505,7 @@ public class Searching private LinkedList list; [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] public void Contains() @@ -596,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); @@ -615,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); @@ -645,7 +645,7 @@ public void RetainAll() [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); @@ -746,7 +746,7 @@ public class Searching [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; } @@ -791,7 +791,7 @@ public class Removing [SetUp] public void Init() { - dit = new LinkedList(); + dit = []; } @@ -1678,7 +1678,7 @@ public class Stack [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] @@ -1714,7 +1714,7 @@ public class Queue [SetUp] - public void Init() { list = new LinkedList(); } + public void Init() { list = []; } [Test] @@ -1862,7 +1862,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); } @@ -2064,7 +2064,7 @@ public void Add() Assert.That(IC.Eq(view, 8, 18, 12, 15), Is.True); }); - LinkedList lst2 = new() { 90, 92 }; + LinkedList lst2 = [90, 92]; view.AddAll(lst2); check(); Assert.Multiple(() => @@ -2107,7 +2107,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); @@ -2329,7 +2329,7 @@ public void Remove() 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); - LinkedList l2 = new() { 1, 2, 2, 3, 1 }; + LinkedList l2 = [1, 2, 2, 3, 1]; view.RemoveAll(l2); check(); @@ -2654,7 +2654,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); @@ -2675,7 +2675,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); @@ -2696,7 +2696,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++) { @@ -2717,7 +2717,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); @@ -2788,7 +2788,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(() => @@ -2859,7 +2859,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++) @@ -3213,15 +3213,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 = []; } @@ -3278,15 +3278,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 = []; } @@ -3347,17 +3347,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 = []; } @@ -3422,17 +3422,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 = []; } @@ -3493,9 +3493,9 @@ public class ISequenced [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3620,9 +3620,9 @@ public class IEditableCollection [SetUp] public void Init() { - dit = new LinkedList(); - dat = new LinkedList(); - dut = new LinkedList(); + dit = []; + dat = []; + dut = []; } @@ -3750,15 +3750,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 = []; } @@ -3811,15 +3811,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 = []; } @@ -3873,18 +3873,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 = []; } @@ -3943,18 +3943,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/SupportClasses.cs b/C5.Tests/SupportClasses.cs index d4e1ebca..438ddae9 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -64,36 +64,6 @@ public static bool Eq(SCG.IEnumerable me, params int[] that) 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 ReverseIntegerComparer : SCG.IComparer diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index ec2efd68..06c56e28 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -864,14 +864,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) })); }); } } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index 98efccc6..0f9bd6b1 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -607,7 +607,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 +617,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) })); }); } } diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index ce198632..1e876796 100644 --- a/C5.Tests/WrappersTest.cs +++ b/C5.Tests/WrappersTest.cs @@ -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] @@ -814,21 +814,19 @@ public void View() 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.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.TrySlide(-1, 2), Is.True); Assert.That(IC.Eq(wrapped, 4, 5), Is.True); 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/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 ccdd4b60..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,7 +114,7 @@ public void AddTrans(int s1, string lab, int s2) } else { - s1Trans = new ArrayList(); + s1Trans = []; Trans.Add(s1, s1Trans); } s1Trans.Add(new Transition(lab, s2)); @@ -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 87dc7b9c..ffd6b5fe 100644 --- a/C5.UserGuideExamples/Graph.cs +++ b/C5.UserGuideExamples/Graph.cs @@ -500,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)) @@ -510,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); @@ -529,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) @@ -631,7 +631,7 @@ public bool AddVertex(V v) return false; } - _graph.Add(v, new HashDictionary()); + _graph.Add(v, []); return true; } @@ -648,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; } @@ -658,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) @@ -722,7 +722,7 @@ public IGraph SubGraph(ICollectionValue vs) { if (!(vs is HashSet vertexset)) { - vertexset = new HashSet(); + vertexset = []; vertexset.AddAll(vs); } @@ -745,7 +745,7 @@ public int ComponentCount public ICollectionValue>> Components() { - ArrayList>> retval = new(); + ArrayList>> retval = []; HashGraph component; ArrayList vertices = null; void edgeaction(Edge e) @@ -755,7 +755,7 @@ void edgeaction(Edge e) void beforecomponent(V v) { - vertices = new ArrayList() { v }; + vertices = [v]; } void aftercomponent(V v) @@ -765,7 +765,7 @@ void aftercomponent(V v) foreach (V start in vertices) { //component.graph[start] = graph[start].Clone(); - HashDictionary edgeset = component._graph[start] = new HashDictionary(); + HashDictionary edgeset = component._graph[start] = []; foreach (SCG.KeyValuePair adjacent in _graph[start]) { edgeset[adjacent.Key] = adjacent.Value; @@ -1122,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); @@ -1759,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 306a2a1e..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) 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 ca159b1f..035d12c2 100644 --- a/C5.UserGuideExamples/MultiDictionary.cs +++ b/C5.UserGuideExamples/MultiDictionary.cs @@ -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); diff --git a/C5.UserGuideExamples/MultiDictionary2.cs b/C5.UserGuideExamples/MultiDictionary2.cs index d0e8fe6a..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); diff --git a/C5.UserGuideExamples/PointLocation.cs b/C5.UserGuideExamples/PointLocation.cs index c8180a1d..4dd2919d 100644 --- a/C5.UserGuideExamples/PointLocation.cs +++ b/C5.UserGuideExamples/PointLocation.cs @@ -145,13 +145,13 @@ public class PointLocator 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,7 +167,7 @@ private void add(Edge edge) if (!endpoints.Contains(edge.Xs)) { - endpoints.Add(edge.Xs, new SCG.KeyValuePair>, LinkedList>>(new LinkedList>(), new LinkedList>())); + endpoints.Add(edge.Xs, new SCG.KeyValuePair>, LinkedList>>([], [])); } SCG.KeyValuePair>, LinkedList>> kv; @@ -175,7 +175,7 @@ private void add(Edge edge) kv.Key.Add(edge); if (!endpoints.Contains(edge.Xe)) { - endpoints.Add(edge.Xe, new SCG.KeyValuePair>, LinkedList>>(new LinkedList>(), new LinkedList>())); + endpoints.Add(edge.Xe, new SCG.KeyValuePair>, LinkedList>>([], [])); } kv = endpoints[edge.Xe]; @@ -208,9 +208,9 @@ 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()); 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/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/Hashing/HashSet.cs b/C5/Hashing/HashSet.cs index 36c263bc..664333fa 100644 --- a/C5/Hashing/HashSet.cs +++ b/C5/Hashing/HashSet.cs @@ -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/LinkedLists/HashedLinkedList.cs b/C5/LinkedLists/HashedLinkedList.cs index f2ae3297..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,7 +1507,7 @@ public IList Map(Func mapper) { Validitycheck(); - HashedLinkedList retval = new(); + HashedLinkedList retval = []; return Map(mapper, retval); } @@ -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); diff --git a/C5/LinkedLists/LinkedList.cs b/C5/LinkedLists/LinkedList.cs index 841ef18f..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,7 +1120,7 @@ public IList Map(Func mapper) { ValidityCheck(); - LinkedList retval = new(); + LinkedList retval = []; return Map(mapper, retval); } @@ -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!; From 470aeaedfeedea611d74efb91cddaceb4d85df8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 14:52:16 +0200 Subject: [PATCH 07/14] Remove unn. casts. Replace IC.Eq with Is.EqualTo --- C5.Tests/Arrays/ArrayListTest.cs | 260 +++++++++---------- C5.Tests/Arrays/CircularQueueTest.cs | 6 +- C5.Tests/Arrays/HashedArrayListTest.cs | 234 ++++++++--------- C5.Tests/Arrays/SortedArrayTests.cs | 30 +-- C5.Tests/Hashing/HashBagTests.cs | 2 +- C5.Tests/Hashing/HashTableTests.cs | 8 +- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 224 ++++++++-------- C5.Tests/LinkedLists/LinkedListTest.cs | 250 +++++++++--------- C5.Tests/Trees/Bag.cs | 30 +-- C5.Tests/Trees/RedBlackTreeSetTests.cs | 30 +-- C5.Tests/WrappersTest.cs | 4 +- C5.UserGuideExamples/PointLocation.cs | 4 +- 12 files changed, 541 insertions(+), 541 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index 2be20f15..c8aa6aaa 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -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 })); }); } @@ -963,12 +963,12 @@ public void AddAll() 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 })); }); } @@ -1246,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 })); } @@ -1260,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 })); }); } @@ -1295,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(); @@ -1304,7 +1304,7 @@ 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); @@ -1325,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(); @@ -1334,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 })); } @@ -1356,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; @@ -1375,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 })); }); } @@ -1470,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 })); } @@ -1511,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(dit.Check(), Is.True); Assert.That(IC.Eq(dit), Is.True); }); 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 })); }); } @@ -1617,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 })); } @@ -1700,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); }); } @@ -1739,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 })); }); } @@ -1801,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 })); } @@ -1816,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 })); }); } @@ -1844,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 })); }); } @@ -1874,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 })); }); } @@ -2011,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 })); }); } @@ -2203,7 +2203,7 @@ public void Sort() { 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, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -2441,7 +2441,7 @@ 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(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); 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); @@ -2541,8 +2541,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 })); }); } @@ -2603,21 +2603,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)); }); } @@ -2625,10 +2625,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] @@ -2651,15 +2651,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(() => @@ -2669,7 +2669,7 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); Assert.That(IC.Eq(view), Is.True); view.Add(8); Assert.That(view.IsEmpty, Is.False); @@ -2678,29 +2678,29 @@ 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 = [90, 92]; @@ -2708,16 +2708,16 @@ public void Add() 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 })); }); } @@ -2727,7 +2727,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)); @@ -2785,11 +2785,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(() => { @@ -2797,7 +2797,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 })); } @@ -2821,7 +2821,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 })); }); } @@ -2873,7 +2873,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(); @@ -2883,7 +2883,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 })); }); } @@ -2915,8 +2915,8 @@ public void Sort() 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 })); }); } @@ -2927,32 +2927,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); @@ -2960,32 +2960,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, 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; @@ -2993,10 +2993,10 @@ public void Remove() 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(() => { @@ -3005,7 +3005,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(() => { @@ -3015,7 +3015,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 })); } @@ -3030,12 +3030,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 })); }); } @@ -3045,24 +3045,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); 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() @@ -3096,7 +3096,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 })); }); } @@ -3989,7 +3989,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); diff --git a/C5.Tests/Arrays/CircularQueueTest.cs b/C5.Tests/Arrays/CircularQueueTest.cs index 6ed4fdec..e722b780 100644 --- a/C5.Tests/Arrays/CircularQueueTest.cs +++ b/C5.Tests/Arrays/CircularQueueTest.cs @@ -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)); } diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index 6bdee308..b582d799 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -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 })); }); } @@ -887,12 +887,12 @@ public void AddAll() 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 })); }); } @@ -1179,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 })); } @@ -1193,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 })); }); } @@ -1224,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(); @@ -1233,7 +1233,7 @@ 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); @@ -1254,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(); @@ -1263,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 })); } @@ -1284,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 })); }); } @@ -1377,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] @@ -1415,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(dit.Check(), Is.True); Assert.That(IC.Eq(dit), Is.True); }); 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 })); }); } @@ -1518,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] @@ -1632,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)); } @@ -1656,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]); @@ -1670,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 })); }); } @@ -1678,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]); @@ -1692,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 })); }); } @@ -1744,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 })); } @@ -1759,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 })); }); } @@ -1797,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 })); }); } @@ -1841,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 })); }); } @@ -1998,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 })); }); } @@ -2193,7 +2193,7 @@ public void Sort() { 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, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } } @@ -2247,7 +2247,7 @@ 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(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); 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); @@ -2352,8 +2352,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 })); }); } @@ -2414,21 +2414,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)); }); } @@ -2451,10 +2451,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 })); } @@ -2464,15 +2464,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(() => @@ -2482,7 +2482,7 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); Assert.That(IC.Eq(view), Is.True); view.Add(8); Assert.That(view.IsEmpty, Is.False); @@ -2491,29 +2491,29 @@ 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 = @@ -2525,15 +2525,15 @@ public void Add() 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 })); }); } @@ -2543,7 +2543,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)); @@ -2603,11 +2603,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(() => { @@ -2615,7 +2615,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 })); } @@ -2640,7 +2640,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 })); }); } @@ -2692,7 +2692,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 @@ -2704,7 +2704,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 })); }); } @@ -2718,8 +2718,8 @@ public void Sort() 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 })); }); } @@ -2730,32 +2730,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, 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 = [ @@ -2767,7 +2767,7 @@ public void Remove() ]; 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); @@ -2789,7 +2789,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 })); } @@ -2804,12 +2804,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 })); }); } @@ -2819,21 +2819,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); 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() @@ -2867,7 +2867,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 })); } @@ -3522,7 +3522,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); diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index d3446b8a..a8468988 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -125,11 +125,11 @@ public void Remove() } 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); } @@ -2015,7 +2015,7 @@ public void SomeSome() 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 })); }); } @@ -2096,7 +2096,7 @@ public void SomeSome() 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 })); }); } @@ -2143,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++) { @@ -2189,21 +2189,21 @@ 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); @@ -2264,14 +2264,14 @@ 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(() => @@ -2309,7 +2309,7 @@ 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); } diff --git a/C5.Tests/Hashing/HashBagTests.cs b/C5.Tests/Hashing/HashBagTests.cs index e9f6d7db..a2982185 100644 --- a/C5.Tests/Hashing/HashBagTests.cs +++ b/C5.Tests/Hashing/HashBagTests.cs @@ -341,7 +341,7 @@ 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 })); } diff --git a/C5.Tests/Hashing/HashTableTests.cs b/C5.Tests/Hashing/HashTableTests.cs index 2ba0cef1..c91f2784 100644 --- a/C5.Tests/Hashing/HashTableTests.cs +++ b/C5.Tests/Hashing/HashTableTests.cs @@ -657,7 +657,7 @@ 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 })); } @@ -735,16 +735,16 @@ public void RemoveAll() 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 })); } diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index d25d13c1..cd417663 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -293,12 +293,12 @@ public void AddAll() 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 })); }); } @@ -582,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 })); } @@ -596,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 })); }); } @@ -627,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(); @@ -636,7 +636,7 @@ 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); @@ -657,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(); @@ -666,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 })); } @@ -687,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 })); }); } @@ -782,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 })); } @@ -822,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(dit.Check(), Is.True); Assert.That(IC.Eq(dit), Is.True); }); 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 })); }); } @@ -927,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] @@ -1181,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)); } @@ -1205,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]); @@ -1219,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 })); }); } @@ -1227,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]); @@ -1241,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 })); }); } @@ -1296,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 })); } @@ -1311,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 })); }); } @@ -1349,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 })); }); } @@ -1388,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 })); }); } @@ -1540,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 })); }); } @@ -1610,7 +1610,7 @@ public void Sort() 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, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } } @@ -1756,7 +1756,7 @@ 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(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); 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); @@ -1855,8 +1855,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 })); }); } @@ -1917,21 +1917,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)); }); } @@ -1954,10 +1954,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] @@ -1966,15 +1966,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(() => @@ -1984,7 +1984,7 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); Assert.That(IC.Eq(view), Is.True); view.Add(8); Assert.That(view.IsEmpty, Is.False); @@ -1993,29 +1993,29 @@ 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 = [90, 92]; @@ -2024,15 +2024,15 @@ public void Add() 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 })); }); } @@ -2042,7 +2042,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)); @@ -2098,11 +2098,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(() => { @@ -2110,7 +2110,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 })); } @@ -2135,7 +2135,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 })); }); } @@ -2187,7 +2187,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 }; @@ -2195,7 +2195,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 })); }); } @@ -2209,8 +2209,8 @@ public void Sort() 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 })); }); } @@ -2221,38 +2221,38 @@ 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 = [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); @@ -2274,7 +2274,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 })); } @@ -2289,12 +2289,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 })); }); } @@ -2304,21 +2304,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); 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() @@ -2354,7 +2354,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 })); } @@ -2988,7 +2988,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); diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index 32ae335f..6a458156 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -296,12 +296,12 @@ public void AddAll() 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 })); }); } @@ -574,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 })); } @@ -588,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 })); }); } @@ -623,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(); @@ -632,7 +632,7 @@ 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); @@ -653,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(); @@ -662,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 })); } @@ -685,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; @@ -704,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 })); }); } @@ -802,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 })); } @@ -842,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(dit.Check(), Is.True); Assert.That(IC.Eq(dit), Is.True); }); 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 })); }); } @@ -946,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] @@ -1156,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); }); } @@ -1194,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 })); }); } @@ -1256,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 })); } @@ -1271,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 })); }); } @@ -1311,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 })); }); } @@ -1353,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 })); }); } @@ -1502,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 })); }); } @@ -1570,7 +1570,7 @@ public void Sort() 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, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -1797,7 +1797,7 @@ 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(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); 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); @@ -1900,8 +1900,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 })); }); } @@ -1963,21 +1963,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)); }); } @@ -1999,10 +1999,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 })); } @@ -2012,15 +2012,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(() => @@ -2030,7 +2030,7 @@ public void Add() Assert.That(view.IsEmpty, Is.True); }); check(); - Assert.That(IC.Eq(list, 0, 3), Is.True); + Assert.That(list, Is.EqualTo(new[] { 0, 3 })); Assert.That(IC.Eq(view), Is.True); view.Add(8); Assert.That(view.IsEmpty, Is.False); @@ -2039,29 +2039,29 @@ 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 = [90, 92]; @@ -2069,15 +2069,15 @@ public void Add() 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 })); }); } @@ -2087,7 +2087,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)); @@ -2144,11 +2144,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(() => { @@ -2156,7 +2156,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 })); } @@ -2180,7 +2180,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 })); }); } @@ -2232,7 +2232,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(); @@ -2242,7 +2242,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 })); }); } @@ -2256,8 +2256,8 @@ public void Sort() 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 })); }); } @@ -2269,32 +2269,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); @@ -2302,41 +2302,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 = [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(() => { @@ -2345,7 +2345,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(() => { @@ -2355,7 +2355,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 })); } @@ -2370,12 +2370,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 })); }); } @@ -2385,24 +2385,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); 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() @@ -2435,7 +2435,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 })); } @@ -3580,7 +3580,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); diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 06c56e28..46042bb5 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -542,11 +542,11 @@ public void Remove() } 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); } @@ -772,7 +772,7 @@ 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 })); } @@ -3017,7 +3017,7 @@ public void SomeSome() 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 })); }); } @@ -3107,7 +3107,7 @@ public void SomeSome() { 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 })); }); } @@ -3156,28 +3156,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++) { @@ -3202,21 +3202,21 @@ 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); @@ -3277,14 +3277,14 @@ 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(() => diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index 0f9bd6b1..c5c04043 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -262,11 +262,11 @@ public void Remove() } 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); } @@ -2597,7 +2597,7 @@ public void SomeSome() 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 })); }); } @@ -2678,7 +2678,7 @@ public void SomeSome() 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 })); }); } @@ -2725,28 +2725,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++) { @@ -2771,21 +2771,21 @@ 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); @@ -2846,14 +2846,14 @@ 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(() => @@ -2890,7 +2890,7 @@ 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); } diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index 1e876796..a4993a49 100644 --- a/C5.Tests/WrappersTest.cs +++ b/C5.Tests/WrappersTest.cs @@ -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(() => diff --git a/C5.UserGuideExamples/PointLocation.cs b/C5.UserGuideExamples/PointLocation.cs index 4dd2919d..5ce507d9 100644 --- a/C5.UserGuideExamples/PointLocation.cs +++ b/C5.UserGuideExamples/PointLocation.cs @@ -212,7 +212,7 @@ public void Build() TreeSet> vtree = []; - htree[double.NegativeInfinity] = (ISorted>)(vtree.Snapshot()); + htree[double.NegativeInfinity] = vtree.Snapshot(); foreach (SCG.KeyValuePair>, LinkedList>>> p in endpoints) { @@ -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; From ac9b8821f9fc04e563c2f60ff919500aeac50f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 15:01:28 +0200 Subject: [PATCH 08/14] more --- C5.Tests/Arrays/ArrayListTest.cs | 26 ++++++-------------- C5.Tests/Arrays/HashedArrayListTest.cs | 12 ++++----- C5.Tests/Arrays/SortedArrayTests.cs | 18 +++++++------- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 12 ++++----- C5.Tests/LinkedLists/LinkedListTest.cs | 8 +++--- C5.Tests/Trees/Bag.cs | 16 ++++++------ C5.Tests/Trees/RedBlackTreeSetTests.cs | 18 +++++++------- 7 files changed, 49 insertions(+), 61 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index c8aa6aaa..a3739b3e 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -1310,7 +1310,7 @@ public void RetainAll() 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); } @@ -1530,7 +1530,7 @@ public void RemoveInterval() Assert.Multiple(() => { Assert.That(dit.Check(), Is.True); - Assert.That(IC.Eq(dit), 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); @@ -2275,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); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 5, 6, 7 }), "Contents " + i); } } } - } - namespace IStackQueue { [TestFixture] @@ -2670,7 +2658,7 @@ public void Add() }); check(); Assert.That(list, Is.EqualTo(new[] { 0, 3 })); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.True); @@ -3060,7 +3048,7 @@ public void Slide() 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(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index b582d799..430bfb27 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -1239,7 +1239,7 @@ public void RetainAll() 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); } @@ -1434,7 +1434,7 @@ public void RemoveInterval() Assert.Multiple(() => { Assert.That(dit.Check(), Is.True); - Assert.That(IC.Eq(dit), 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); @@ -2483,7 +2483,7 @@ public void Add() }); check(); Assert.That(list, Is.EqualTo(new[] { 0, 3 })); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.False); @@ -2770,7 +2770,7 @@ public void Remove() 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(() => { @@ -2779,7 +2779,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(() => { @@ -2831,7 +2831,7 @@ public void Slide() 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(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index a8468988..8e7649a0 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -107,7 +107,7 @@ public void Remove() array.RemoveRangeFrom(13); Assert.That(IC.Eq(array, [2, 4, 6, 8, 10, 12]), Is.True); array.RemoveRangeFrom(2); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); foreach (int i in all) { array.Add(i); @@ -118,7 +118,7 @@ public void Remove() array.RemoveRangeTo(2); Assert.That(IC.Eq(array, [10, 12, 14, 16, 18, 20]), Is.True); array.RemoveRangeTo(21); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); foreach (int i in all) { array.Add(i); @@ -131,7 +131,7 @@ public void Remove() array.RemoveRangeFromTo(0, 9); 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] @@ -2176,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); }); } @@ -2210,7 +2210,7 @@ public void RetainAll() 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++) { @@ -2222,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++) { @@ -2234,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); }); } @@ -2278,7 +2278,7 @@ public void RemoveInterval() { Assert.That(array.Check(), Is.True); Assert.That(array, Is.Empty); - Assert.That(IC.Eq(array), Is.True); + Assert.That(array, Is.Empty); }); } @@ -2311,7 +2311,7 @@ public void GetRange() 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] diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index cd417663..a4c90858 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -642,7 +642,7 @@ public void RetainAll() 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); } @@ -841,7 +841,7 @@ public void RemoveInterval() Assert.Multiple(() => { Assert.That(dit.Check(), Is.True); - Assert.That(IC.Eq(dit), 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); @@ -1985,7 +1985,7 @@ public void Add() }); check(); Assert.That(list, Is.EqualTo(new[] { 0, 3 })); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.False); @@ -2255,7 +2255,7 @@ public void Remove() 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(() => { @@ -2264,7 +2264,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(() => { @@ -2316,7 +2316,7 @@ public void Slide() 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(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index 6a458156..7fc4feef 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -638,7 +638,7 @@ public void RetainAll() 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); } @@ -861,7 +861,7 @@ public void RemoveInterval() Assert.Multiple(() => { Assert.That(dit.Check(), Is.True); - Assert.That(IC.Eq(dit), 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); @@ -2031,7 +2031,7 @@ public void Add() }); check(); Assert.That(list, Is.EqualTo(new[] { 0, 3 })); - Assert.That(IC.Eq(view), Is.True); + Assert.That(view, Is.Empty); view.Add(8); Assert.That(view.IsEmpty, Is.False); Assert.That(view.AllowsDuplicates, Is.True); @@ -2400,7 +2400,7 @@ public void Slide() 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(list, Is.EqualTo(new[] { 0, 28, 1, 2, 3 })); } diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 46042bb5..ce85024d 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -524,7 +524,7 @@ public void Remove() 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); tree.RemoveRangeFrom(1); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); @@ -535,7 +535,7 @@ public void Remove() tree.RemoveRangeTo(2); Assert.That(IC.Eq(tree, [10, 10, 12, 14, 16, 18, 20]), Is.True); tree.RemoveRangeTo(21); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); @@ -548,7 +548,7 @@ public void Remove() tree.RemoveRangeFromTo(0, 9); 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); } @@ -3189,7 +3189,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -3223,7 +3223,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++) { @@ -3235,7 +3235,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++) { @@ -3247,7 +3247,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -3291,7 +3291,7 @@ public void RemoveInterval() { Assert.That(tree.Check(), Is.True); Assert.That(tree, Is.Empty); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index c5c04043..a5b7bafe 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -244,7 +244,7 @@ public void Remove() tree.RemoveRangeFrom(28); Assert.That(IC.Eq(tree, [2, 4, 6, 8, 10, 12, 14, 16]), Is.True); tree.RemoveRangeFrom(2); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); @@ -255,7 +255,7 @@ public void Remove() tree.RemoveRangeTo(2); Assert.That(IC.Eq(tree, [10, 12, 14, 16, 18, 20]), Is.True); tree.RemoveRangeTo(21); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); foreach (int i in all) { tree.Add(i); @@ -268,7 +268,7 @@ public void Remove() tree.RemoveRangeFromTo(0, 9); 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] @@ -2758,7 +2758,7 @@ public void RemoveAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2792,7 +2792,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++) { @@ -2804,7 +2804,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++) { @@ -2816,7 +2816,7 @@ public void RetainAll() Assert.Multiple(() => { Assert.That(tree.Check(), Is.True); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2860,7 +2860,7 @@ public void RemoveInterval() { Assert.That(tree.Check(), Is.True); Assert.That(tree, Is.Empty); - Assert.That(IC.Eq(tree), Is.True); + Assert.That(tree, Is.Empty); }); } @@ -2892,7 +2892,7 @@ public void GetRange() SCG.IEnumerable e = tree[3, 3]; 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] From abc66015ffc97da1c59341f13afd39d72e07a5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 15:12:50 +0200 Subject: [PATCH 09/14] more --- C5.Tests/Arrays/ArrayListTest.cs | 6 +++--- C5.Tests/Arrays/HashedArrayListTest.cs | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index a3739b3e..9ff39c06 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -2430,9 +2430,9 @@ public void Backwards() Assert.Multiple(() => { Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); - 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[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 })); }); } diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index 430bfb27..7cd9fd5e 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -2217,7 +2217,6 @@ public class Range [TearDown] public void Dispose() { lst.Dispose(); } - [Test] public void GetRange() { @@ -2229,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() { @@ -2248,13 +2246,12 @@ public void Backwards() Assert.Multiple(() => { Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); - 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[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() { From 792cde14af4f2432799775f34e21a1893cc63061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 15:22:18 +0200 Subject: [PATCH 10/14] more --- C5.Tests/Arrays/SortedArrayTests.cs | 4020 ++++++++++++------------ C5.Tests/Trees/Bag.cs | 8 +- C5.Tests/Trees/RedBlackTreeSetTests.cs | 8 +- 3 files changed, 2018 insertions(+), 2018 deletions(-) diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index 8e7649a0..0e59e052 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -101,11 +101,11 @@ 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(array, Is.Empty); foreach (int i in all) @@ -114,9 +114,9 @@ public void Remove() } 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(array, Is.Empty); foreach (int i in all) @@ -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,1108 +178,1334 @@ 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 })); + }); + } + + [Test] + public void Direction() + { + Assert.Multiple(() => + { + Assert.That(array.Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeFrom(20).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeTo(7).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeFromTo(1, 12).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeAll().Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeFrom(20).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeTo(7).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeFromTo(1, 12).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeAll().Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + }); + } - [Test] - public void Direction() - { - Assert.Multiple(() => - { - Assert.That(array.Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeFrom(20).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeTo(7).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeFromTo(1, 12).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeAll().Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeFrom(20).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeTo(7).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeFromTo(1, 12).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeAll().Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - }); - } + [TearDown] + public void Dispose() + { + array = null; + c = null; + } +} + +[TestFixture] +public class BagItf +{ + private SortedArray array; - [TearDown] - public void Dispose() + + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + for (int i = 10; i < 20; i++) { - array = null; - c = null; + array.Add(i); + array.Add(i + 10); } } - [TestFixture] - public class BagItf + + [Test] + public void Both() { - private SortedArray array; + Assert.Multiple(() => + { + Assert.That(array.ContainsCount(7), Is.EqualTo(0)); + Assert.That(array.ContainsCount(10), Is.EqualTo(1)); + }); + array.RemoveAllCopies(10); + Assert.That(array.ContainsCount(10), Is.EqualTo(0)); + array.RemoveAllCopies(7); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - for (int i = 10; i < 20; i++) - { - array.Add(i); - array.Add(i + 10); - } - } + [TearDown] + public void Dispose() + { + array = null; + } +} - [Test] - public void Both() - { - Assert.Multiple(() => - { - Assert.That(array.ContainsCount(7), Is.EqualTo(0)); - Assert.That(array.ContainsCount(10), Is.EqualTo(1)); - }); - array.RemoveAllCopies(10); - Assert.That(array.ContainsCount(10), Is.EqualTo(0)); - array.RemoveAllCopies(7); - } +[TestFixture] +public class Div +{ + private SortedArray array; - [TearDown] - public void Dispose() - { - array = null; - } + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); } + [Test] + public void NullEqualityComparerinConstructor1() + { + Assert.Throws(() => new SortedArray(null)); + } - [TestFixture] - public class Div + [Test] + public void NullEqualityComparerinConstructor2() { - private SortedArray array; + Assert.Throws(() => new SortedArray(5, null)); + } + [Test] + public void NullEqualityComparerinConstructor3() + { + Assert.Throws(() => new SortedArray(5, null, EqualityComparer.Default)); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - } + [Test] + public void NullEqualityComparerinConstructor4() + { + Assert.Throws(() => new SortedArray(5, SCG.Comparer.Default, null)); + } - [Test] - public void NullEqualityComparerinConstructor1() - { - Assert.Throws(() => new SortedArray(null)); - } + [Test] + public void NullEqualityComparerinConstructor5() + { + Assert.Throws(() => new SortedArray(5, null, null)); + } - [Test] - public void NullEqualityComparerinConstructor2() - { - Assert.Throws(() => new SortedArray(5, null)); - } + [Test] + public void Choose() + { + array.Add(7); + Assert.That(array.Choose(), Is.EqualTo(7)); + } - [Test] - public void NullEqualityComparerinConstructor3() - { - Assert.Throws(() => new SortedArray(5, null, EqualityComparer.Default)); - } + [Test] + public void BadChoose() + { + Assert.Throws(() => array.Choose()); + } - [Test] - public void NullEqualityComparerinConstructor4() + private void loadup() + { + for (int i = 10; i < 20; i++) { - Assert.Throws(() => new SortedArray(5, SCG.Comparer.Default, null)); + array.Add(i); + array.Add(i + 10); } + } - [Test] - public void NullEqualityComparerinConstructor5() - { - Assert.Throws(() => new SortedArray(5, null, null)); - } - [Test] - public void Choose() + [Test] + public void NoDuplicatesEtc() + { + Assert.That(array.AllowsDuplicates, Is.False); + loadup(); + Assert.Multiple(() => { - array.Add(7); - Assert.That(array.Choose(), Is.EqualTo(7)); - } + Assert.That(array.AllowsDuplicates, Is.False); + Assert.That(array.ContainsSpeed, Is.EqualTo(Speed.Log)); + Assert.That(array.Comparer.Compare(2, 3), Is.LessThan(0)); + Assert.That(array.Comparer.Compare(4, 3), Is.GreaterThan(0)); + Assert.That(array.Comparer.Compare(3, 3), Is.EqualTo(0)); + }); + } - [Test] - public void BadChoose() + [Test] + public void Add() + { + Assert.That(array.Add(17), Is.True); + Assert.Multiple(() => { - Assert.Throws(() => array.Choose()); - } - - private void loadup() + Assert.That(array.Add(17), Is.False); + Assert.That(array.Add(18), Is.True); + }); + Assert.Multiple(() => { - for (int i = 10; i < 20; i++) - { - array.Add(i); - array.Add(i + 10); - } - } + Assert.That(array.Add(18), Is.False); + Assert.That(array, Has.Count.EqualTo(2)); + }); + } - [Test] - public void NoDuplicatesEtc() - { - Assert.That(array.AllowsDuplicates, Is.False); - loadup(); - Assert.Multiple(() => - { - Assert.That(array.AllowsDuplicates, Is.False); - Assert.That(array.ContainsSpeed, Is.EqualTo(Speed.Log)); - Assert.That(array.Comparer.Compare(2, 3), Is.LessThan(0)); - Assert.That(array.Comparer.Compare(4, 3), Is.GreaterThan(0)); - Assert.That(array.Comparer.Compare(3, 3), Is.EqualTo(0)); - }); - } + [TearDown] + public void Dispose() + { + array = null; + } +} - [Test] - public void Add() - { - Assert.That(array.Add(17), Is.True); - Assert.Multiple(() => - { - Assert.That(array.Add(17), Is.False); - Assert.That(array.Add(18), Is.True); - }); - Assert.Multiple(() => - { - Assert.That(array.Add(18), Is.False); - Assert.That(array, Has.Count.EqualTo(2)); - }); - } + +[TestFixture] +public class FindOrAdd +{ + private SortedArray> bag; - [TearDown] - public void Dispose() - { - array = null; - } + [SetUp] + public void Init() + { + bag = new SortedArray>(new KeyValuePairComparer(new IC())); } - [TestFixture] - public class FindOrAdd + [TearDown] + public void Dispose() { - private SortedArray> bag; + bag = null; + } - [SetUp] - public void Init() + [Test] + public void Test() + { + SCG.KeyValuePair p = new(3, "tre"); + + Assert.That(bag.FindOrAdd(ref p), Is.False); + p = new SCG.KeyValuePair(p.Key, "drei"); + Assert.Multiple(() => { - bag = new SortedArray>(new KeyValuePairComparer(new IC())); - } + Assert.That(bag.FindOrAdd(ref p), Is.True); + Assert.That(p.Value, Is.EqualTo("tre")); + }); + p = new SCG.KeyValuePair(p.Key, "three"); + Assert.Multiple(() => + { + Assert.That(bag.ContainsCount(p), Is.EqualTo(1)); + Assert.That(bag[0].Value, Is.EqualTo("tre")); + }); + } +} + +[TestFixture] +public class FindPredicate +{ + private SortedArray list; + private Func pred; + [SetUp] + public void Init() + { + list = new SortedArray(TenEqualityComparer.Instance); + pred = delegate (int i) { return i % 5 == 0; }; + } - [TearDown] - public void Dispose() - { - bag = null; - } + [TearDown] + public void Dispose() { list = null; } + [Test] + public void Find() + { + Assert.That(list.Find(pred, out int i), Is.False); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.Find(pred, out i), Is.False); + list.AddAll([45, 122, 675, 137]); + Assert.Multiple(() => + { + Assert.That(list.Find(pred, out i), Is.True); + Assert.That(i, Is.EqualTo(45)); + }); + } - [Test] - public void Test() - { - SCG.KeyValuePair p = new(3, "tre"); + [Test] + public void FindLast() + { + Assert.That(list.FindLast(pred, out int i), Is.False); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindLast(pred, out i), Is.False); + list.AddAll([45, 122, 675, 137]); + Assert.Multiple(() => + { + Assert.That(list.FindLast(pred, out i), Is.True); + Assert.That(i, Is.EqualTo(675)); + }); + } - Assert.That(bag.FindOrAdd(ref p), Is.False); - p = new SCG.KeyValuePair(p.Key, "drei"); - Assert.Multiple(() => - { - Assert.That(bag.FindOrAdd(ref p), Is.True); - Assert.That(p.Value, Is.EqualTo("tre")); - }); - p = new SCG.KeyValuePair(p.Key, "three"); - Assert.Multiple(() => - { - Assert.That(bag.ContainsCount(p), Is.EqualTo(1)); - Assert.That(bag[0].Value, Is.EqualTo("tre")); - }); - } + [Test] + public void FindIndex() + { + Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([45, 122, 675, 137]); + Assert.That(list.FindIndex(pred), Is.EqualTo(3)); } - [TestFixture] - public class FindPredicate + [Test] + public void FindLastIndex() { - private SortedArray list; - private Func pred; + Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([45, 122, 675, 137]); + Assert.That(list.FindLastIndex(pred), Is.EqualTo(7)); + } +} - [SetUp] - public void Init() - { - list = new SortedArray(TenEqualityComparer.Instance); - pred = delegate (int i) { return i % 5 == 0; }; - } +[TestFixture] +public class UniqueItems +{ + private SortedArray list; - [TearDown] - public void Dispose() { list = null; } + [SetUp] + public void Init() { list = []; } - [Test] - public void Find() - { - Assert.That(list.Find(pred, out int i), Is.False); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.Find(pred, out i), Is.False); - list.AddAll([45, 122, 675, 137]); - Assert.Multiple(() => - { - Assert.That(list.Find(pred, out i), Is.True); - Assert.That(i, Is.EqualTo(45)); - }); - } + [TearDown] + public void Dispose() { list = null; } - [Test] - public void FindLast() + [Test] + public void Test() + { + Assert.Multiple(() => { - Assert.That(list.FindLast(pred, out int i), Is.False); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindLast(pred, out i), Is.False); - list.AddAll([45, 122, 675, 137]); - Assert.Multiple(() => - { - Assert.That(list.FindLast(pred, out i), Is.True); - Assert.That(i, Is.EqualTo(675)); - }); - } - - [Test] - public void FindIndex() + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); + }); + list.AddAll([7, 9, 7]); + Assert.Multiple(() => { - Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([45, 122, 675, 137]); - Assert.That(list.FindIndex(pred), Is.EqualTo(3)); - } + 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) })); + }); + } +} - [Test] - public void FindLastIndex() +[TestFixture] +public class ArrayTest +{ + private SortedArray tree; + private int[] a; + + + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + a = new int[10]; + for (int i = 0; i < 10; i++) { - Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([45, 122, 675, 137]); - Assert.That(list.FindLastIndex(pred), Is.EqualTo(7)); + a[i] = 1000 + i; } } - [TestFixture] - public class UniqueItems - { - private SortedArray list; - [SetUp] - public void Init() { list = []; } + [TearDown] + public void Dispose() { tree = null; } - [TearDown] - public void Dispose() { list = null; } - [Test] - public void Test() - { - Assert.Multiple(() => - { - Assert.That(list.UniqueItems(), Is.Empty); - Assert.That(list.ItemMultiplicities(), Is.Empty); - }); - list.AddAll([7, 9, 7]); - Assert.Multiple(() => - { - 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) })); - }); - } + [Test] + public void ToArray() + { + Assert.That(tree.ToArray(), Is.Empty); + tree.Add(7); + tree.Add(4); + Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); } - [TestFixture] - public class ArrayTest + + [Test] + public void CopyTo() { - private SortedArray tree; - private int[] a; + tree.CopyTo(a, 1); + 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(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(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(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); + } - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - a = new int[10]; - for (int i = 0; i < 10; i++) - { - a[i] = 1000 + i; - } - } + [Test] + public void CopyToBad() + { + Assert.Throws(() => tree.CopyTo(a, 11)); + } - [TearDown] - public void Dispose() { tree = null; } + [Test] + public void CopyToBad2() + { + Assert.Throws(() => tree.CopyTo(a, -1)); + } - [Test] - public void ToArray() - { - Assert.That(tree.ToArray(), Is.Empty); - tree.Add(7); - tree.Add(4); - Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); - } + [Test] + public void CopyToTooFar() + { + tree.Add(3); + tree.Add(4); + Assert.Throws(() => tree.CopyTo(a, 9)); + } +} - [Test] - public void CopyTo() - { - tree.CopyTo(a, 1); - 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(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(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(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); - } +[TestFixture] +public class Combined +{ + private IIndexedSorted> lst; - [Test] - public void CopyToBad() + [SetUp] + public void Init() + { + lst = new SortedArray>(new KeyValuePairComparer(new IC())); + for (int i = 0; i < 10; i++) { - Assert.Throws(() => tree.CopyTo(a, 11)); + lst.Add(new SCG.KeyValuePair(i, i + 30)); } + } + [TearDown] + public void Dispose() { lst = null; } - [Test] - public void CopyToBad2() - { - Assert.Throws(() => tree.CopyTo(a, -1)); - } + [Test] + public void Find() + { + SCG.KeyValuePair p = new(3, 78); - [Test] - public void CopyToTooFar() + Assert.Multiple(() => { - tree.Add(3); - tree.Add(4); - Assert.Throws(() => tree.CopyTo(a, 9)); - } + Assert.That(lst.Find(ref p), Is.True); + Assert.That(p.Key, Is.EqualTo(3)); + Assert.That(p.Value, Is.EqualTo(33)); + }); + p = new SCG.KeyValuePair(13, 78); + Assert.That(lst.Find(ref p), Is.False); } - [TestFixture] - public class Combined + [Test] + public void FindOrAdd() { - private IIndexedSorted> lst; - + SCG.KeyValuePair p = new(3, 78); - [SetUp] - public void Init() + Assert.Multiple(() => { - lst = new SortedArray>(new KeyValuePairComparer(new IC())); - for (int i = 0; i < 10; i++) - { - lst.Add(new SCG.KeyValuePair(i, i + 30)); - } - } + Assert.That(lst.FindOrAdd(ref p), Is.True); + Assert.That(p.Key, Is.EqualTo(3)); + Assert.That(p.Value, Is.EqualTo(33)); + }); + p = new SCG.KeyValuePair(13, 79); + Assert.Multiple(() => + { + Assert.That(lst.FindOrAdd(ref p), Is.False); + Assert.That(lst[10].Key, Is.EqualTo(13)); + Assert.That(lst[10].Value, Is.EqualTo(79)); + }); + } - [TearDown] - public void Dispose() { lst = null; } + [Test] + public void Update() + { + SCG.KeyValuePair p = new(3, 78); - [Test] - public void Find() + Assert.Multiple(() => { - SCG.KeyValuePair p = new(3, 78); + Assert.That(lst.Update(p), Is.True); + Assert.That(lst[3].Key, Is.EqualTo(3)); + Assert.That(lst[3].Value, Is.EqualTo(78)); + }); + p = new SCG.KeyValuePair(13, 78); + Assert.That(lst.Update(p), Is.False); + } - 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 SCG.KeyValuePair(13, 78); - Assert.That(lst.Find(ref p), Is.False); - } + [Test] + public void UpdateOrAdd1() + { + SCG.KeyValuePair p = new(3, 78); - [Test] - public void FindOrAdd() + Assert.Multiple(() => { - SCG.KeyValuePair p = new(3, 78); - - Assert.Multiple(() => - { - Assert.That(lst.FindOrAdd(ref p), Is.True); - Assert.That(p.Key, Is.EqualTo(3)); - Assert.That(p.Value, Is.EqualTo(33)); - }); - p = new SCG.KeyValuePair(13, 79); - Assert.Multiple(() => - { - Assert.That(lst.FindOrAdd(ref p), Is.False); - Assert.That(lst[10].Key, Is.EqualTo(13)); - Assert.That(lst[10].Value, Is.EqualTo(79)); - }); - } + Assert.That(lst.UpdateOrAdd(p), Is.True); + Assert.That(lst[3].Key, Is.EqualTo(3)); + Assert.That(lst[3].Value, Is.EqualTo(78)); + }); + p = new SCG.KeyValuePair(13, 79); + Assert.Multiple(() => + { + Assert.That(lst.UpdateOrAdd(p), Is.False); + Assert.That(lst[10].Key, Is.EqualTo(13)); + Assert.That(lst[10].Value, Is.EqualTo(79)); + }); + } + [Test] + public void UpdateOrAdd2() + { + ICollection coll = new SortedArray(); + // s1 and s2 are distinct objects but contain the same text: + string s1 = "abc", s2 = ("def" + s1).Substring(3); + Assert.Multiple(() => + { + Assert.That(coll.UpdateOrAdd(s1, out string old), Is.False); + Assert.That(old, Is.EqualTo(null)); + Assert.That(coll.UpdateOrAdd(s2, out old), Is.True); + Assert.That(ReferenceEquals(s1, old), Is.True); + Assert.That(ReferenceEquals(s2, old), Is.False); + }); + } - [Test] - public void Update() + [Test] + public void UpdateOrAddWithExpand() + { + // bug20071217 + SortedArray arr = []; + for (int i = 0; i < 50; i++) { - SCG.KeyValuePair p = new(3, 78); + arr.UpdateOrAdd(i + 0.1); + arr.Add(i + 0.2); + } + Assert.That(arr, Has.Count.EqualTo(100)); + } - Assert.Multiple(() => - { - Assert.That(lst.Update(p), Is.True); - Assert.That(lst[3].Key, Is.EqualTo(3)); - Assert.That(lst[3].Value, Is.EqualTo(78)); - }); - p = new SCG.KeyValuePair(13, 78); - Assert.That(lst.Update(p), Is.False); + [Test] + public void FindOrAddWithExpand() + { + // bug20071217 + SortedArray arr = []; + for (int i = 0; i < 50; i++) + { + double iVar = i + 0.1; + arr.FindOrAdd(ref iVar); + arr.Add(i * 0.2); } + Assert.That(arr, Has.Count.EqualTo(100)); + } + [Test] + public void RemoveWithReturn() + { + SCG.KeyValuePair p = new(3, 78); + + Assert.Multiple(() => + { + Assert.That(lst.Remove(p, out p), Is.True); + Assert.That(p.Key, Is.EqualTo(3)); + Assert.That(p.Value, Is.EqualTo(33)); + Assert.That(lst[3].Key, Is.EqualTo(4)); + Assert.That(lst[3].Value, Is.EqualTo(34)); + }); + p = new SCG.KeyValuePair(13, 78); + Assert.That(lst.Remove(p, out _), Is.False); + } +} - [Test] - public void UpdateOrAdd1() - { - SCG.KeyValuePair p = new(3, 78); - Assert.Multiple(() => - { - Assert.That(lst.UpdateOrAdd(p), Is.True); - Assert.That(lst[3].Key, Is.EqualTo(3)); - Assert.That(lst[3].Value, Is.EqualTo(78)); - }); - p = new SCG.KeyValuePair(13, 79); - Assert.Multiple(() => - { - Assert.That(lst.UpdateOrAdd(p), Is.False); - Assert.That(lst[10].Key, Is.EqualTo(13)); - Assert.That(lst[10].Value, Is.EqualTo(79)); - }); - } +[TestFixture] +public class Remove +{ + private SortedArray array; - [Test] - public void UpdateOrAdd2() - { - ICollection coll = new SortedArray(); - // s1 and s2 are distinct objects but contain the same text: - string s1 = "abc", s2 = ("def" + s1).Substring(3); - Assert.Multiple(() => - { - Assert.That(coll.UpdateOrAdd(s1, out string old), Is.False); - Assert.That(old, Is.EqualTo(null)); - Assert.That(coll.UpdateOrAdd(s2, out old), Is.True); - Assert.That(ReferenceEquals(s1, old), Is.True); - Assert.That(ReferenceEquals(s2, old), Is.False); - }); - } - [Test] - public void UpdateOrAddWithExpand() + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + for (int i = 10; i < 20; i++) { - // bug20071217 - SortedArray arr = []; - for (int i = 0; i < 50; i++) - { - arr.UpdateOrAdd(i + 0.1); - arr.Add(i + 0.2); - } - Assert.That(arr, Has.Count.EqualTo(100)); + array.Add(i); + array.Add(i + 10); } + } - [Test] - public void FindOrAddWithExpand() - { - // bug20071217 - SortedArray arr = []; - for (int i = 0; i < 50; i++) - { - double iVar = i + 0.1; - arr.FindOrAdd(ref iVar); - arr.Add(i * 0.2); - } - Assert.That(arr, Has.Count.EqualTo(100)); - } - [Test] - public void RemoveWithReturn() - { - SCG.KeyValuePair p = new(3, 78); + [Test] + public void SmallTrees() + { + array.Clear(); + array.Add(7); + array.Add(9); + Assert.Multiple(() => + { + Assert.That(array.Remove(7), Is.True); + Assert.That(array.Check(), Is.True); + }); + } - Assert.Multiple(() => - { - Assert.That(lst.Remove(p, out p), Is.True); - Assert.That(p.Key, Is.EqualTo(3)); - Assert.That(p.Value, Is.EqualTo(33)); - Assert.That(lst[3].Key, Is.EqualTo(4)); - Assert.That(lst[3].Value, Is.EqualTo(34)); - }); - p = new SCG.KeyValuePair(13, 78); - Assert.That(lst.Remove(p, out _), Is.False); - } + + [Test] + public void ByIndex() + { + //Remove root! + int n = array.Count; + int i = array[10]; + + array.RemoveAt(10); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 1)); + }); + + //Low end + i = array.FindMin(); + array.RemoveAt(0); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 2)); + }); + + //high end + i = array.FindMax(); + array.RemoveAt(array.Count - 1); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 3)); + }); + + //Some leaf + i = 18; + array.RemoveAt(7); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 4)); + }); } - [TestFixture] - public class Remove + [Test] + public void AlmostEmpty() { - private SortedArray array; + //Almost empty + array.Clear(); + array.Add(3); + array.RemoveAt(0); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(3)); + Assert.That(array, Is.Empty); + }); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - for (int i = 10; i < 20; i++) - { - array.Add(i); - array.Add(i + 10); - } - } + [Test] + public void Empty() + { + array.Clear(); + var exception = Assert.Throws(() => array.RemoveAt(0)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + } - [Test] - public void SmallTrees() - { - array.Clear(); - array.Add(7); - array.Add(9); - Assert.Multiple(() => - { - Assert.That(array.Remove(7), Is.True); - Assert.That(array.Check(), Is.True); - }); - } + [Test] + public void HighIndex() + { + var exception = Assert.Throws(() => array.RemoveAt(array.Count)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + } - [Test] - public void ByIndex() - { - //Remove root! - int n = array.Count; - int i = array[10]; - array.RemoveAt(10); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 1)); - }); + [Test] + public void LowIndex() + { + var exception = Assert.Throws(() => array.RemoveAt(-1)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + } - //Low end - i = array.FindMin(); - array.RemoveAt(0); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 2)); - }); - //high end - i = array.FindMax(); - array.RemoveAt(array.Count - 1); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 3)); - }); + [Test] + public void Normal() + { + Assert.Multiple(() => + { + Assert.That(array.Remove(-20), Is.False); - //Some leaf - i = 18; - array.RemoveAt(7); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 4)); - }); - } + //No demote case, with move_item + Assert.That(array.Remove(20), Is.True); + Assert.That(array.Check(), Is.True); + Assert.That(array.Remove(20), Is.False); + //plain case 2 + Assert.That(array.Remove(14), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); - [Test] - public void AlmostEmpty() - { - //Almost empty - array.Clear(); - array.Add(3); - array.RemoveAt(0); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(3)); - Assert.That(array, Is.Empty); - }); - } + //case 1b + Assert.That(array.Remove(25), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); + //case 1c + Assert.That(array.Remove(29), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); - [Test] - public void Empty() - { - array.Clear(); + //1a (terminating) + Assert.That(array.Remove(10), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); - var exception = Assert.Throws(() => array.RemoveAt(0)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); - } + //2+1b + Assert.That(array.Remove(12), Is.True); + Assert.That(array.Remove(11), Is.True); + //1a+1b + Assert.That(array.Remove(18), Is.True); + Assert.That(array.Remove(13), Is.True); + Assert.That(array.Remove(15), Is.True); + }); - [Test] - public void HighIndex() + //2+1c + for (int i = 0; i < 10; i++) { - var exception = Assert.Throws(() => array.RemoveAt(array.Count)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + array.Add(50 - 2 * i); } + Assert.Multiple(() => + { + Assert.That(array.Remove(42), Is.True); + Assert.That(array.Remove(38), Is.True); + Assert.That(array.Remove(28), Is.True); + Assert.That(array.Remove(40), Is.True); - [Test] - public void LowIndex() + // + Assert.That(array.Remove(16), Is.True); + Assert.That(array.Remove(23), Is.True); + Assert.That(array.Remove(17), Is.True); + Assert.That(array.Remove(19), Is.True); + Assert.That(array.Remove(50), Is.True); + Assert.That(array.Remove(26), Is.True); + Assert.That(array.Remove(21), Is.True); + Assert.That(array.Remove(22), Is.True); + Assert.That(array.Remove(24), Is.True); + }); + for (int i = 0; i < 48; i++) { - var exception = Assert.Throws(() => array.RemoveAt(-1)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + array.Remove(i); } - - [Test] - public void Normal() + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(array.Remove(-20), Is.False); + //Almost empty tree: + Assert.That(array.Remove(26), Is.False); + Assert.That(array.Remove(48), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); - //No demote case, with move_item - Assert.That(array.Remove(20), Is.True); - Assert.That(array.Check(), Is.True); - Assert.That(array.Remove(20), Is.False); - - //plain case 2 - Assert.That(array.Remove(14), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - - //case 1b - Assert.That(array.Remove(25), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - - //case 1c - Assert.That(array.Remove(29), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - - //1a (terminating) - Assert.That(array.Remove(10), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - - //2+1b - Assert.That(array.Remove(12), Is.True); - Assert.That(array.Remove(11), Is.True); + //Empty tree: + Assert.That(array.Remove(26), Is.False); + Assert.That(array.Check(), Is.True, "Bad tree"); + }); + } - //1a+1b - Assert.That(array.Remove(18), Is.True); - Assert.That(array.Remove(13), Is.True); - Assert.That(array.Remove(15), Is.True); - }); - //2+1c - for (int i = 0; i < 10; i++) - { - array.Add(50 - 2 * i); - } + [TearDown] + public void Dispose() + { + array = null; + } +} - Assert.Multiple(() => - { - Assert.That(array.Remove(42), Is.True); - Assert.That(array.Remove(38), Is.True); - Assert.That(array.Remove(28), Is.True); - Assert.That(array.Remove(40), Is.True); - - // - Assert.That(array.Remove(16), Is.True); - Assert.That(array.Remove(23), Is.True); - Assert.That(array.Remove(17), Is.True); - Assert.That(array.Remove(19), Is.True); - Assert.That(array.Remove(50), Is.True); - Assert.That(array.Remove(26), Is.True); - Assert.That(array.Remove(21), Is.True); - Assert.That(array.Remove(22), Is.True); - Assert.That(array.Remove(24), Is.True); - }); - for (int i = 0; i < 48; i++) - { - array.Remove(i); - } - Assert.Multiple(() => - { - //Almost empty tree: - Assert.That(array.Remove(26), Is.False); - Assert.That(array.Remove(48), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - //Empty tree: - Assert.That(array.Remove(26), Is.False); - Assert.That(array.Check(), Is.True, "Bad tree"); - }); - } +[TestFixture] +public class PredecessorStructure +{ + private SortedArray tree; - [TearDown] - public void Dispose() - { - array = null; - } + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); } - - [TestFixture] - public class PredecessorStructure + private void loadup() { - private SortedArray tree; - - - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - } - - - private void loadup() + for (int i = 0; i < 20; i++) { - for (int i = 0; i < 20; i++) - { - tree.Add(2 * i); - } + tree.Add(2 * i); } + } - [Test] - public void FindPredecessor() + [Test] + public void FindPredecessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.TryPredecessor(7, out int res) && res == 6, Is.True); - Assert.That(tree.TryPredecessor(8, out res) && res == 6, Is.True); + Assert.That(tree.TryPredecessor(7, out int res) && res == 6, Is.True); + Assert.That(tree.TryPredecessor(8, out res) && res == 6, Is.True); - //The bottom - Assert.That(tree.TryPredecessor(1, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TryPredecessor(1, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryPredecessor(39, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TryPredecessor(39, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindPredecessorTooLow1() + [Test] + public void FindPredecessorTooLow1() + { + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(tree.TryPredecessor(-2, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - Assert.That(tree.TryPredecessor(0, out res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.That(tree.TryPredecessor(-2, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + Assert.That(tree.TryPredecessor(0, out res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void FindWeakPredecessor() + [Test] + public void FindWeakPredecessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.TryWeakPredecessor(7, out int res) && res == 6, Is.True); - Assert.That(tree.TryWeakPredecessor(8, out res) && res == 8, Is.True); + Assert.That(tree.TryWeakPredecessor(7, out int res) && res == 6, Is.True); + Assert.That(tree.TryWeakPredecessor(8, out res) && res == 8, Is.True); - //The bottom - Assert.That(tree.TryWeakPredecessor(1, out res) && res == 0, Is.True); - Assert.That(tree.TryWeakPredecessor(0, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TryWeakPredecessor(1, out res) && res == 0, Is.True); + Assert.That(tree.TryWeakPredecessor(0, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryWeakPredecessor(39, out res) && res == 38, Is.True); - Assert.That(tree.TryWeakPredecessor(38, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TryWeakPredecessor(39, out res) && res == 38, Is.True); + Assert.That(tree.TryWeakPredecessor(38, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindWeakPredecessorTooLow1() + [Test] + public void FindWeakPredecessorTooLow1() + { + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(tree.TryWeakPredecessor(-1, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.That(tree.TryWeakPredecessor(-1, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void FindSuccessor() + [Test] + public void FindSuccessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.TrySuccessor(7, out int res) && res == 8, Is.True); - Assert.That(tree.TrySuccessor(8, out res) && res == 10, Is.True); + Assert.That(tree.TrySuccessor(7, out int res) && res == 8, Is.True); + Assert.That(tree.TrySuccessor(8, out res) && res == 10, Is.True); - //The bottom - Assert.That(tree.TrySuccessor(0, out res) && res == 2, Is.True); - Assert.That(tree.TrySuccessor(-1, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TrySuccessor(0, out res) && res == 2, Is.True); + Assert.That(tree.TrySuccessor(-1, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TrySuccessor(37, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TrySuccessor(37, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindSuccessorTooHigh() + [Test] + public void FindSuccessorTooHigh() + { + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(tree.TrySuccessor(38, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - Assert.That(tree.TrySuccessor(39, out res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.That(tree.TrySuccessor(38, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + Assert.That(tree.TrySuccessor(39, out res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void FindWeakSuccessor() + [Test] + public void FindWeakSuccessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.TryWeakSuccessor(6, out int res) && res == 6, Is.True); - Assert.That(tree.TryWeakSuccessor(7, out res) && res == 8, Is.True); + Assert.That(tree.TryWeakSuccessor(6, out int res) && res == 6, Is.True); + Assert.That(tree.TryWeakSuccessor(7, out res) && res == 8, Is.True); - //The bottom - Assert.That(tree.TryWeakSuccessor(-1, out res) && res == 0, Is.True); - Assert.That(tree.TryWeakSuccessor(0, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TryWeakSuccessor(-1, out res) && res == 0, Is.True); + Assert.That(tree.TryWeakSuccessor(0, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryWeakSuccessor(37, out res) && res == 38, Is.True); - Assert.That(tree.TryWeakSuccessor(38, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TryWeakSuccessor(37, out res) && res == 38, Is.True); + Assert.That(tree.TryWeakSuccessor(38, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindWeakSuccessorTooHigh1() + [Test] + public void FindWeakSuccessorTooHigh1() + { + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(tree.TryWeakSuccessor(39, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.That(tree.TryWeakSuccessor(39, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void Predecessor() + [Test] + public void Predecessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.Predecessor(7), Is.EqualTo(6)); - Assert.That(tree.Predecessor(8), Is.EqualTo(6)); + Assert.That(tree.Predecessor(7), Is.EqualTo(6)); + Assert.That(tree.Predecessor(8), Is.EqualTo(6)); - //The bottom - Assert.That(tree.Predecessor(1), Is.EqualTo(0)); + //The bottom + Assert.That(tree.Predecessor(1), Is.EqualTo(0)); - //The top - Assert.That(tree.Predecessor(39), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.Predecessor(39), Is.EqualTo(38)); + }); + } - [Test] - public void PredecessorTooLow1() - { - Assert.Throws(() => tree.Predecessor(-2)); - } + [Test] + public void PredecessorTooLow1() + { + Assert.Throws(() => tree.Predecessor(-2)); + } - [Test] - public void PredecessorTooLow2() - { - Assert.Throws(() => tree.Predecessor(0)); - } + [Test] + public void PredecessorTooLow2() + { + Assert.Throws(() => tree.Predecessor(0)); + } - [Test] - public void WeakPredecessor() + [Test] + public void WeakPredecessor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.WeakPredecessor(7), Is.EqualTo(6)); - Assert.That(tree.WeakPredecessor(8), Is.EqualTo(8)); + Assert.That(tree.WeakPredecessor(7), Is.EqualTo(6)); + Assert.That(tree.WeakPredecessor(8), Is.EqualTo(8)); - //The bottom - Assert.That(tree.WeakPredecessor(1), Is.EqualTo(0)); - Assert.That(tree.WeakPredecessor(0), Is.EqualTo(0)); + //The bottom + Assert.That(tree.WeakPredecessor(1), Is.EqualTo(0)); + Assert.That(tree.WeakPredecessor(0), Is.EqualTo(0)); - //The top - Assert.That(tree.WeakPredecessor(39), Is.EqualTo(38)); - Assert.That(tree.WeakPredecessor(38), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.WeakPredecessor(39), Is.EqualTo(38)); + Assert.That(tree.WeakPredecessor(38), Is.EqualTo(38)); + }); + } - [Test] - public void WeakPredecessorTooLow1() - { - Assert.Throws(() => tree.WeakPredecessor(-1)); - } + [Test] + public void WeakPredecessorTooLow1() + { + Assert.Throws(() => tree.WeakPredecessor(-1)); + } - [Test] - public void Successor() + [Test] + public void Successor() + { + loadup(); + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.Successor(7), Is.EqualTo(8)); - Assert.That(tree.Successor(8), Is.EqualTo(10)); + Assert.That(tree.Successor(7), Is.EqualTo(8)); + Assert.That(tree.Successor(8), Is.EqualTo(10)); - //The bottom - Assert.That(tree.Successor(0), Is.EqualTo(2)); - Assert.That(tree.Successor(-1), Is.EqualTo(0)); + //The bottom + Assert.That(tree.Successor(0), Is.EqualTo(2)); + Assert.That(tree.Successor(-1), Is.EqualTo(0)); - //The top - Assert.That(tree.Successor(37), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.Successor(37), Is.EqualTo(38)); + }); + } - [Test] - public void SuccessorTooHigh1() + [Test] + public void SuccessorTooHigh1() + { + Assert.Throws(() => tree.Successor(38)); + } + + + [Test] + public void SuccessorTooHigh2() + { + Assert.Throws(() => tree.Successor(39)); + } + + + [Test] + public void WeakSuccessor() + { + loadup(); + Assert.Multiple(() => { - Assert.Throws(() => tree.Successor(38)); - } + Assert.That(tree.WeakSuccessor(6), Is.EqualTo(6)); + Assert.That(tree.WeakSuccessor(7), Is.EqualTo(8)); + //The bottom + Assert.That(tree.WeakSuccessor(-1), Is.EqualTo(0)); + Assert.That(tree.WeakSuccessor(0), Is.EqualTo(0)); - [Test] - public void SuccessorTooHigh2() + //The top + Assert.That(tree.WeakSuccessor(37), Is.EqualTo(38)); + Assert.That(tree.WeakSuccessor(38), Is.EqualTo(38)); + }); + } + + [Test] + public void WeakSuccessorTooHigh1() + { + Assert.Throws(() => tree.WeakSuccessor(39)); + } + + + [TearDown] + public void Dispose() + { + tree = null; + } +} + + + +[TestFixture] +public class PriorityQueue +{ + private SortedArray tree; + + + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + } + + + private void loadup() + { + foreach (int i in new int[] { 1, 2, 3, 4 }) { - Assert.Throws(() => tree.Successor(39)); + tree.Add(i); } + } - [Test] - public void WeakSuccessor() + [Test] + public void Normal() + { + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.FindMin(), Is.EqualTo(1)); + Assert.That(tree.FindMax(), Is.EqualTo(4)); + Assert.That(tree.DeleteMin(), Is.EqualTo(1)); + Assert.That(tree.DeleteMax(), Is.EqualTo(4)); + Assert.That(tree.Check(), Is.True, "Bad tree"); + Assert.That(tree.FindMin(), Is.EqualTo(2)); + Assert.That(tree.FindMax(), Is.EqualTo(3)); + Assert.That(tree.DeleteMin(), Is.EqualTo(2)); + Assert.That(tree.DeleteMax(), Is.EqualTo(3)); + Assert.That(tree.Check(), Is.True, "Bad tree"); + }); + } + + + [Test] + public void Empty1() + { + Assert.Throws(() => tree.FindMin()); + } + + + [Test] + public void Empty2() + { + Assert.Throws(() => tree.FindMax()); + } + + + [Test] + public void Empty3() + { + Assert.Throws(() => tree.DeleteMin()); + } + + + [Test] + public void Empty4() + { + Assert.Throws(() => tree.DeleteMax()); + } + + + [TearDown] + public void Dispose() + { + tree = null; + } +} + + + +[TestFixture] +public class IndexingAndCounting +{ + private SortedArray array; + + + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + } + + + private void populate() + { + array.Add(30); + array.Add(50); + array.Add(10); + array.Add(70); + } + + + [Test] + public void ToArray() + { + populate(); + + int[] a = [.. array]; + + Assert.Multiple(() => { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.WeakSuccessor(6), Is.EqualTo(6)); - Assert.That(tree.WeakSuccessor(7), Is.EqualTo(8)); + Assert.That(a, Has.Length.EqualTo(4)); + Assert.That(a[0], Is.EqualTo(10)); + Assert.That(a[1], Is.EqualTo(30)); + Assert.That(a[2], Is.EqualTo(50)); + Assert.That(a[3], Is.EqualTo(70)); + }); + } - //The bottom - Assert.That(tree.WeakSuccessor(-1), Is.EqualTo(0)); - Assert.That(tree.WeakSuccessor(0), Is.EqualTo(0)); - //The top - Assert.That(tree.WeakSuccessor(37), Is.EqualTo(38)); - Assert.That(tree.WeakSuccessor(38), Is.EqualTo(38)); - }); - } + [Test] + public void GoodIndex() + { + Assert.Multiple(() => + { + Assert.That(array.IndexOf(20), Is.EqualTo(~0)); + Assert.That(array.LastIndexOf(20), Is.EqualTo(~0)); + }); + populate(); + Assert.Multiple(() => + { + Assert.That(array[0], Is.EqualTo(10)); + Assert.That(array[1], Is.EqualTo(30)); + Assert.That(array[2], Is.EqualTo(50)); + Assert.That(array[3], Is.EqualTo(70)); + Assert.That(array.IndexOf(10), Is.EqualTo(0)); + Assert.That(array.IndexOf(30), Is.EqualTo(1)); + Assert.That(array.IndexOf(50), Is.EqualTo(2)); + Assert.That(array.IndexOf(70), Is.EqualTo(3)); + Assert.That(array.IndexOf(20), Is.EqualTo(~1)); + Assert.That(array.IndexOf(0), Is.EqualTo(~0)); + Assert.That(array.IndexOf(90), Is.EqualTo(~4)); + Assert.That(array.LastIndexOf(10), Is.EqualTo(0)); + Assert.That(array.LastIndexOf(30), Is.EqualTo(1)); + Assert.That(array.LastIndexOf(50), Is.EqualTo(2)); + Assert.That(array.LastIndexOf(70), Is.EqualTo(3)); + Assert.That(array.LastIndexOf(20), Is.EqualTo(~1)); + Assert.That(array.LastIndexOf(0), Is.EqualTo(~0)); + Assert.That(array.LastIndexOf(90), Is.EqualTo(~4)); + }); + } - [Test] - public void WeakSuccessorTooHigh1() + + [Test] + public void IndexTooLarge() + { + populate(); + Assert.Throws(() => Console.WriteLine(array[4])); + } + + + [Test] + public void IndexTooSmall() + { + populate(); + Assert.Throws(() => Console.WriteLine(array[-1])); + } + + + [Test] + public void FilledTreeOutsideInput() + { + populate(); + Assert.Multiple(() => + { + Assert.That(array.CountFrom(90), Is.EqualTo(0)); + Assert.That(array.CountFromTo(-20, 0), Is.EqualTo(0)); + Assert.That(array.CountFromTo(80, 100), Is.EqualTo(0)); + Assert.That(array.CountTo(0), Is.EqualTo(0)); + Assert.That(array.CountTo(90), Is.EqualTo(4)); + Assert.That(array.CountFromTo(-20, 90), Is.EqualTo(4)); + Assert.That(array.CountFrom(0), Is.EqualTo(4)); + }); + } + + + [Test] + public void FilledTreeIntermediateInput() + { + populate(); + Assert.Multiple(() => { - Assert.Throws(() => tree.WeakSuccessor(39)); - } + Assert.That(array.CountFrom(20), Is.EqualTo(3)); + Assert.That(array.CountFromTo(20, 40), Is.EqualTo(1)); + Assert.That(array.CountTo(40), Is.EqualTo(2)); + }); + } - [TearDown] - public void Dispose() + [Test] + public void FilledTreeMatchingInput() + { + populate(); + Assert.Multiple(() => + { + Assert.That(array.CountFrom(30), Is.EqualTo(3)); + Assert.That(array.CountFromTo(30, 70), Is.EqualTo(2)); + Assert.That(array.CountFromTo(50, 30), Is.EqualTo(0)); + Assert.That(array.CountFromTo(50, 50), Is.EqualTo(0)); + Assert.That(array.CountTo(10), Is.EqualTo(0)); + Assert.That(array.CountTo(50), Is.EqualTo(2)); + }); + } + + + [Test] + public void CountEmptyTree() + { + Assert.Multiple(() => { - tree = null; - } + Assert.That(array.CountFrom(20), Is.EqualTo(0)); + Assert.That(array.CountFromTo(20, 40), Is.EqualTo(0)); + Assert.That(array.CountTo(40), Is.EqualTo(0)); + }); } + [TearDown] + public void Dispose() + { + array = null; + } +} + + + +namespace ModificationCheck +{ [TestFixture] - public class PriorityQueue + public class Enumerator { private SortedArray tree; + private SCG.IEnumerator e; + [SetUp] public void Init() { tree = new SortedArray(new IC()); - } - - - private void loadup() - { - foreach (int i in new int[] { 1, 2, 3, 4 }) + for (int i = 0; i < 10; i++) { tree.Add(i); } + e = tree.GetEnumerator(); } [Test] - public void Normal() + public void CurrentAfterModification() { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.FindMin(), Is.EqualTo(1)); - Assert.That(tree.FindMax(), Is.EqualTo(4)); - Assert.That(tree.DeleteMin(), Is.EqualTo(1)); - Assert.That(tree.DeleteMax(), Is.EqualTo(4)); - Assert.That(tree.Check(), Is.True, "Bad tree"); - Assert.That(tree.FindMin(), Is.EqualTo(2)); - Assert.That(tree.FindMax(), Is.EqualTo(3)); - Assert.That(tree.DeleteMin(), Is.EqualTo(2)); - Assert.That(tree.DeleteMax(), Is.EqualTo(3)); - Assert.That(tree.Check(), Is.True, "Bad tree"); - }); + e.MoveNext(); + tree.Add(34); + Assert.That(e.Current, Is.EqualTo(0)); } [Test] - public void Empty1() + public void MoveNextAfterAdd() { - Assert.Throws(() => tree.FindMin()); - } - + e.MoveNext(); + tree.Add(34); - [Test] - public void Empty2() - { - Assert.Throws(() => tree.FindMax()); + Assert.Throws(() => e.MoveNext()); } - [Test] - public void Empty3() + public void MoveNextAfterRemove() { - Assert.Throws(() => tree.DeleteMin()); + e.MoveNext(); + tree.Remove(34); + + Assert.Throws(() => e.MoveNext()); } [Test] - public void Empty4() + public void MoveNextAfterClear() { - Assert.Throws(() => tree.DeleteMax()); + e.MoveNext(); + tree.Clear(); + + Assert.Throws(() => e.MoveNext()); } @@ -1287,1510 +1513,1284 @@ public void Empty4() public void Dispose() { tree = null; + e.Dispose(); } } - - [TestFixture] - public class IndexingAndCounting + public class RangeEnumerator { - private SortedArray array; + private SortedArray tree; + + private SCG.IEnumerator e; [SetUp] public void Init() { - array = new SortedArray(new IC()); - } - + tree = new SortedArray(new IC()); + for (int i = 0; i < 10; i++) + { + tree.Add(i); + } - private void populate() - { - array.Add(30); - array.Add(50); - array.Add(10); - array.Add(70); + e = tree.RangeFromTo(3, 7).GetEnumerator(); } [Test] - public void ToArray() + public void CurrentAfterModification() { - populate(); - - int[] a = [.. array]; - - Assert.Multiple(() => - { - Assert.That(a, Has.Length.EqualTo(4)); - Assert.That(a[0], Is.EqualTo(10)); - Assert.That(a[1], Is.EqualTo(30)); - Assert.That(a[2], Is.EqualTo(50)); - Assert.That(a[3], Is.EqualTo(70)); - }); + e.MoveNext(); + tree.Add(34); + Assert.That(e.Current, Is.EqualTo(3)); } [Test] - public void GoodIndex() + public void MoveNextAfterAdd() { - Assert.Multiple(() => - { - Assert.That(array.IndexOf(20), Is.EqualTo(~0)); - Assert.That(array.LastIndexOf(20), Is.EqualTo(~0)); - }); - populate(); - Assert.Multiple(() => - { - Assert.That(array[0], Is.EqualTo(10)); - Assert.That(array[1], Is.EqualTo(30)); - Assert.That(array[2], Is.EqualTo(50)); - Assert.That(array[3], Is.EqualTo(70)); - Assert.That(array.IndexOf(10), Is.EqualTo(0)); - Assert.That(array.IndexOf(30), Is.EqualTo(1)); - Assert.That(array.IndexOf(50), Is.EqualTo(2)); - Assert.That(array.IndexOf(70), Is.EqualTo(3)); - Assert.That(array.IndexOf(20), Is.EqualTo(~1)); - Assert.That(array.IndexOf(0), Is.EqualTo(~0)); - Assert.That(array.IndexOf(90), Is.EqualTo(~4)); - Assert.That(array.LastIndexOf(10), Is.EqualTo(0)); - Assert.That(array.LastIndexOf(30), Is.EqualTo(1)); - Assert.That(array.LastIndexOf(50), Is.EqualTo(2)); - Assert.That(array.LastIndexOf(70), Is.EqualTo(3)); - Assert.That(array.LastIndexOf(20), Is.EqualTo(~1)); - Assert.That(array.LastIndexOf(0), Is.EqualTo(~0)); - Assert.That(array.LastIndexOf(90), Is.EqualTo(~4)); - }); - } + tree.Add(34); - - [Test] - public void IndexTooLarge() - { - populate(); - Assert.Throws(() => Console.WriteLine(array[4])); + Assert.Throws(() => e.MoveNext()); } - [Test] - public void IndexTooSmall() - { - populate(); - Assert.Throws(() => Console.WriteLine(array[-1])); - } [Test] - public void FilledTreeOutsideInput() + public void MoveNextAfterRemove() { - populate(); - Assert.Multiple(() => - { - Assert.That(array.CountFrom(90), Is.EqualTo(0)); - Assert.That(array.CountFromTo(-20, 0), Is.EqualTo(0)); - Assert.That(array.CountFromTo(80, 100), Is.EqualTo(0)); - Assert.That(array.CountTo(0), Is.EqualTo(0)); - Assert.That(array.CountTo(90), Is.EqualTo(4)); - Assert.That(array.CountFromTo(-20, 90), Is.EqualTo(4)); - Assert.That(array.CountFrom(0), Is.EqualTo(4)); - }); - } - + tree.Remove(34); - [Test] - public void FilledTreeIntermediateInput() - { - populate(); - Assert.Multiple(() => - { - Assert.That(array.CountFrom(20), Is.EqualTo(3)); - Assert.That(array.CountFromTo(20, 40), Is.EqualTo(1)); - Assert.That(array.CountTo(40), Is.EqualTo(2)); - }); + Assert.Throws(() => e.MoveNext()); } [Test] - public void FilledTreeMatchingInput() + public void MoveNextAfterClear() { - populate(); - Assert.Multiple(() => - { - Assert.That(array.CountFrom(30), Is.EqualTo(3)); - Assert.That(array.CountFromTo(30, 70), Is.EqualTo(2)); - Assert.That(array.CountFromTo(50, 30), Is.EqualTo(0)); - Assert.That(array.CountFromTo(50, 50), Is.EqualTo(0)); - Assert.That(array.CountTo(10), Is.EqualTo(0)); - Assert.That(array.CountTo(50), Is.EqualTo(2)); - }); - } - + tree.Clear(); - [Test] - public void CountEmptyTree() - { - Assert.Multiple(() => - { - Assert.That(array.CountFrom(20), Is.EqualTo(0)); - Assert.That(array.CountFromTo(20, 40), Is.EqualTo(0)); - Assert.That(array.CountTo(40), Is.EqualTo(0)); - }); + Assert.Throws(() => e.MoveNext()); } [TearDown] public void Dispose() { - array = null; + tree = null; + e.Dispose(); } } +} +namespace HigherOrder +{ + internal class CubeRoot : IComparable + { + private readonly int c; + internal CubeRoot(int c) { this.c = c; } - namespace ModificationCheck - { - [TestFixture] - public class Enumerator - { - private SortedArray tree; - private SCG.IEnumerator e; + public int CompareTo(int that) { return c - that * that * that; } + public bool Equals(int that) { return c == that * that * that; } - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) - { - tree.Add(i); - } - e = tree.GetEnumerator(); - } + } + internal class Interval : IComparable + { + private readonly int b, t; - [Test] - public void CurrentAfterModification() - { - e.MoveNext(); - tree.Add(34); - Assert.That(e.Current, Is.EqualTo(0)); - } + internal Interval(int b, int t) { this.b = b; this.t = t; } - [Test] - public void MoveNextAfterAdd() - { - e.MoveNext(); - tree.Add(34); - Assert.Throws(() => e.MoveNext()); - } + public int CompareTo(int that) { return that < b ? 1 : that > t ? -1 : 0; } - [Test] - public void MoveNextAfterRemove() - { - e.MoveNext(); - tree.Remove(34); + public bool Equals(int that) { return that >= b && that <= t; } + } - Assert.Throws(() => e.MoveNext()); - } - [Test] - public void MoveNextAfterClear() - { - e.MoveNext(); - tree.Clear(); + [TestFixture] + public class Simple + { + private SortedArray array; - Assert.Throws(() => e.MoveNext()); - } + private SCG.IComparer ic; - [TearDown] - public void Dispose() - { - tree = null; - e.Dispose(); - } + [SetUp] + public void Init() + { + ic = new IC(); + array = new SortedArray(ic); } - [TestFixture] - public class RangeEnumerator - { - private SortedArray tree; - private SCG.IEnumerator e; + private bool never(int i) { return false; } - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) - { - tree.Add(i); - } + private bool always(int i) { return true; } - e = tree.RangeFromTo(3, 7).GetEnumerator(); - } + private bool even(int i) { return i % 2 == 0; } - [Test] - public void CurrentAfterModification() - { - e.MoveNext(); - tree.Add(34); - Assert.That(e.Current, Is.EqualTo(3)); - } + private string themap(int i) { return string.Format("AA {0,4} BB", i); } - [Test] - public void MoveNextAfterAdd() - { - tree.Add(34); - Assert.Throws(() => e.MoveNext()); - } + private string badmap(int i) { return string.Format("AA {0} BB", i); } + private int appfield1; + private int appfield2; - [Test] - public void MoveNextAfterRemove() - { - tree.Remove(34); - Assert.Throws(() => e.MoveNext()); - } + private void apply(int i) { appfield1++; appfield2 += i * i; } - [Test] - public void MoveNextAfterClear() - { - tree.Clear(); + [Test] + public void Apply() + { + Simple simple1 = new(); - Assert.Throws(() => e.MoveNext()); - } + array.Apply(new Action(simple1.apply)); + Assert.Multiple(() => + { + Assert.That(simple1.appfield1, Is.EqualTo(0)); + Assert.That(simple1.appfield2, Is.EqualTo(0)); + }); + Simple simple2 = new(); - [TearDown] - public void Dispose() + for (int i = 0; i < 10; i++) { - tree = null; - e.Dispose(); + array.Add(i); } - } - } - - namespace HigherOrder - { - internal class CubeRoot : IComparable - { - private readonly int c; - - - internal CubeRoot(int c) { this.c = c; } - - - public int CompareTo(int that) { return c - that * that * that; } - - public bool Equals(int that) { return c == that * that * that; } + array.Apply(new Action(simple2.apply)); + Assert.Multiple(() => + { + Assert.That(simple2.appfield1, Is.EqualTo(10)); + Assert.That(simple2.appfield2, Is.EqualTo(285)); + }); } - internal class Interval : IComparable - { - private readonly int b, t; - - - internal Interval(int b, int t) { this.b = b; this.t = t; } - - public int CompareTo(int that) { return that < b ? 1 : that > t ? -1 : 0; } - - public bool Equals(int that) { return that >= b && that <= t; } - } - - - - [TestFixture] - public class Simple + [Test] + public void All() { - private SortedArray array; - - private SCG.IComparer ic; - - - [SetUp] - public void Init() + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.True); + Assert.That(array.All(new Func(even)), Is.True); + Assert.That(array.All(new Func(always)), Is.True); + }); + for (int i = 0; i < 10; i++) { - ic = new IC(); - array = new SortedArray(ic); + array.Add(i); } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.False); + Assert.That(array.All(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2); + } - private bool never(int i) { return false; } - - - private bool always(int i) { return true; } - - - private bool even(int i) { return i % 2 == 0; } - - - private string themap(int i) { return string.Format("AA {0,4} BB", i); } - - - private string badmap(int i) { return string.Format("AA {0} BB", i); } - - - private int appfield1; - - private int appfield2; + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.True); + Assert.That(array.All(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2 + 1); + } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.False); + Assert.That(array.All(new Func(always)), Is.True); + }); + } - private void apply(int i) { appfield1++; appfield2 += i * i; } + [Test] + public void Exists() + { + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.False); + Assert.That(array.Exists(new Func(always)), Is.False); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } - [Test] - public void Apply() + Assert.Multiple(() => { - Simple simple1 = new(); + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.True); + Assert.That(array.Exists(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2); + } - array.Apply(new Action(simple1.apply)); - Assert.Multiple(() => - { - Assert.That(simple1.appfield1, Is.EqualTo(0)); - Assert.That(simple1.appfield2, Is.EqualTo(0)); - }); + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.True); + Assert.That(array.Exists(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2 + 1); + } - Simple simple2 = new(); + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.False); + Assert.That(array.Exists(new Func(always)), Is.True); + }); + } - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - array.Apply(new Action(simple2.apply)); - Assert.Multiple(() => - { - Assert.That(simple2.appfield1, Is.EqualTo(10)); - Assert.That(simple2.appfield2, Is.EqualTo(285)); - }); + [Test] + public void FindAll() + { + Assert.That(array.FindAll(new Func(never)), Is.Empty); + for (int i = 0; i < 10; i++) + { + array.Add(i); } - - [Test] - public void All() + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.True); - Assert.That(array.All(new Func(even)), Is.True); - Assert.That(array.All(new Func(always)), Is.True); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.False); - Assert.That(array.All(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2); - } + Assert.That(array.FindAll(new Func(never)), Is.Empty); + Assert.That(array.FindAll(new Func(always)), Has.Count.EqualTo(10)); + Assert.That(array.FindAll(new Func(even)), Has.Count.EqualTo(5)); + Assert.That(((SortedArray)array.FindAll(new Func(even))).Check(), Is.True); + }); + } - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.True); - Assert.That(array.All(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2 + 1); - } - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.False); - Assert.That(array.All(new Func(always)), Is.True); - }); + [Test] + public void Map() + { + Assert.That(array.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); + for (int i = 0; i < 11; i++) + { + array.Add(i * i * i); } + var res = array.Map(new Func(themap), StringComparer.InvariantCulture); - [Test] - public void Exists() + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.False); - Assert.That(array.Exists(new Func(always)), Is.False); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.True); - Assert.That(array.Exists(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2); - } - - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.True); - Assert.That(array.Exists(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2 + 1); - } + Assert.That(((SortedArray)res).Check(), Is.True); + Assert.That(res, Has.Count.EqualTo(11)); + 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")); + Assert.That(res[10], Is.EqualTo("AA 1000 BB")); + }); + } - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.False); - Assert.That(array.Exists(new Func(always)), Is.True); - }); + [Test] + public void BadMap() + { + for (int i = 0; i < 11; i++) + { + array.Add(i * i * i); } + var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), StringComparer.InvariantCulture); }); + Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); + } - [Test] - public void FindAll() - { - Assert.That(array.FindAll(new Func(never)), Is.Empty); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - Assert.Multiple(() => - { - Assert.That(array.FindAll(new Func(never)), Is.Empty); - Assert.That(array.FindAll(new Func(always)), Has.Count.EqualTo(10)); - Assert.That(array.FindAll(new Func(even)), Has.Count.EqualTo(5)); - Assert.That(((SortedArray)array.FindAll(new Func(even))).Check(), Is.True); - }); + [Test] + public void Cut() + { + for (int i = 0; i < 10; i++) + { + array.Add(i); } - - [Test] - public void Map() + Assert.Multiple(() => { - Assert.That(array.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); - for (int i = 0; i < 11; i++) - { - array.Add(i * i * i); - } + Assert.That(array.Cut(new CubeRoot(27), out int low, out bool lval, out int high, out bool hval), Is.True); + Assert.That(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(4)); + Assert.That(low, Is.EqualTo(2)); + Assert.That(array.Cut(new CubeRoot(30), out low, out lval, out high, out hval), Is.False); + Assert.That(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(4)); + Assert.That(low, Is.EqualTo(3)); + }); + } - 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.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")); - Assert.That(res[10], Is.EqualTo("AA 1000 BB")); - }); + [Test] + public void CutInt() + { + for (int i = 0; i < 10; i++) + { + array.Add(2 * i); } - [Test] - public void BadMap() + Assert.Multiple(() => { - for (int i = 0; i < 11; i++) - { - array.Add(i * i * i); - } - - var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), StringComparer.InvariantCulture); }); - Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); - } + Assert.That(array.Cut(new IC(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(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(8)); + Assert.That(low, Is.EqualTo(4)); + }); + } - [Test] - public void Cut() + [Test] + public void CutInterval() + { + for (int i = 0; i < 10; i++) { - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - - Assert.Multiple(() => - { - Assert.That(array.Cut(new CubeRoot(27), out int low, out bool lval, out int high, out bool hval), Is.True); - Assert.That(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(4)); - Assert.That(low, Is.EqualTo(2)); - Assert.That(array.Cut(new CubeRoot(30), out low, out lval, out high, out hval), Is.False); - Assert.That(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(4)); - Assert.That(low, Is.EqualTo(3)); - }); + array.Add(2 * i); } + Assert.That(array.Cut(new Interval(5, 9), out int lo, out bool lv, out int hi, out bool hv), Is.True); + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(10)); + Assert.That(lo, Is.EqualTo(4)); + Assert.That(array.Cut(new Interval(6, 10), out lo, out lv, out hi, out hv), Is.True); + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(12)); + Assert.That(lo, Is.EqualTo(4)); - [Test] - public void CutInt() + for (int i = 0; i < 100; i++) { - for (int i = 0; i < 10; i++) - { - array.Add(2 * i); - } - - 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(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(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(8)); - Assert.That(low, Is.EqualTo(4)); - }); + array.Add(2 * i); } - - [Test] - public void CutInterval() + array.Cut(new Interval(77, 105), out lo, out lv, out hi, out hv); + Assert.Multiple(() => { - for (int i = 0; i < 10; i++) - { - array.Add(2 * i); - } - - Assert.That(array.Cut(new Interval(5, 9), out int lo, out bool lv, out int hi, out bool hv), Is.True); Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(10)); - Assert.That(lo, Is.EqualTo(4)); - Assert.That(array.Cut(new Interval(6, 10), out lo, out lv, out hi, out hv), Is.True); + Assert.That(hi, Is.EqualTo(106)); + Assert.That(lo, Is.EqualTo(76)); + }); + array.Cut(new Interval(5, 7), out lo, out lv, out hi, out hv); + Assert.Multiple(() => + { Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(12)); + Assert.That(hi, Is.EqualTo(8)); Assert.That(lo, Is.EqualTo(4)); + }); + array.Cut(new Interval(80, 110), out lo, out lv, out hi, out hv); + Assert.Multiple(() => + { + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(112)); + Assert.That(lo, Is.EqualTo(78)); + }); + } - for (int i = 0; i < 100; i++) - { - array.Add(2 * i); - } - array.Cut(new Interval(77, 105), out lo, out lv, out hi, out hv); - Assert.Multiple(() => - { - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(106)); - Assert.That(lo, Is.EqualTo(76)); - }); - array.Cut(new Interval(5, 7), out lo, out lv, out hi, out hv); - Assert.Multiple(() => - { - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(8)); - Assert.That(lo, Is.EqualTo(4)); - }); - array.Cut(new Interval(80, 110), out lo, out lv, out hi, out hv); - Assert.Multiple(() => - { - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(112)); - Assert.That(lo, Is.EqualTo(78)); - }); + [Test] + public void UpperCut() + { + for (int i = 0; i < 10; i++) + { + array.Add(i); } - - [Test] - public void UpperCut() + Assert.Multiple(() => { - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - - Assert.Multiple(() => - { - Assert.That(array.Cut(new CubeRoot(1000), out int l, out bool lv, out _, out bool hv), Is.False); - Assert.That(lv && !hv, Is.True); - Assert.That(l, Is.EqualTo(9)); - Assert.That(array.Cut(new CubeRoot(-50), out _, out lv, out int h, out hv), Is.False); - Assert.That(!lv && hv, Is.True); - Assert.That(h, Is.EqualTo(0)); - }); - } + Assert.That(array.Cut(new CubeRoot(1000), out int l, out bool lv, out _, out bool hv), Is.False); + Assert.That(lv && !hv, Is.True); + Assert.That(l, Is.EqualTo(9)); + Assert.That(array.Cut(new CubeRoot(-50), out _, out lv, out int h, out hv), Is.False); + Assert.That(!lv && hv, Is.True); + Assert.That(h, Is.EqualTo(0)); + }); + } - [TearDown] - public void Dispose() { ic = null; array = null; } - } + [TearDown] + public void Dispose() { ic = null; array = null; } } +} - namespace MultiOps +namespace MultiOps +{ + [TestFixture] + public class AddAll { - [TestFixture] - public class AddAll - { - private int sqr(int i) { return i * i; } + private int sqr(int i) { return i * i; } + + private SortedArray array; + - private SortedArray array; + [SetUp] + public void Init() { array = new SortedArray(new IC()); } - [SetUp] - public void Init() { array = new SortedArray(new IC()); } + [Test] + public void EmptyEmpty() + { + array.AddAll(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + } - [Test] - public void EmptyEmpty() + [Test] + public void SomeEmpty() + { + for (int i = 4; i < 9; i++) { - array.AddAll(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); + array.Add(i); } + array.AddAll(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(5)); + Assert.That(array.Check(), Is.True); + } - [Test] - public void SomeEmpty() - { - for (int i = 4; i < 9; i++) - { - array.Add(i); - } - array.AddAll(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(5)); + [Test] + public void EmptySome() + { + array.AddAll(new FunEnumerable(4, new Func(sqr))); + Assert.Multiple(() => + { + Assert.That(array, Has.Count.EqualTo(4)); Assert.That(array.Check(), Is.True); - } + Assert.That(array[0], Is.EqualTo(0)); + Assert.That(array[1], Is.EqualTo(1)); + Assert.That(array[2], Is.EqualTo(4)); + Assert.That(array[3], Is.EqualTo(9)); + }); + } - [Test] - public void EmptySome() + [Test] + public void SomeSome() + { + for (int i = 3; i < 9; i++) { - array.AddAll(new FunEnumerable(4, new Func(sqr))); - Assert.Multiple(() => - { - Assert.That(array, Has.Count.EqualTo(4)); - Assert.That(array.Check(), Is.True); - Assert.That(array[0], Is.EqualTo(0)); - Assert.That(array[1], Is.EqualTo(1)); - Assert.That(array[2], Is.EqualTo(4)); - Assert.That(array[3], Is.EqualTo(9)); - }); + array.Add(i); } - - [Test] - public void SomeSome() + array.AddAll(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(9)); + Assert.Multiple(() => { - for (int i = 3; i < 9; i++) - { - array.Add(i); - } - - array.AddAll(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(9)); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); - }); - } + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); + }); + } - [TearDown] - public void Dispose() { array = null; } - } + [TearDown] + public void Dispose() { array = null; } + } - [TestFixture] - public class AddSorted - { - private int sqr(int i) { return i * i; } + [TestFixture] + public class AddSorted + { + private int sqr(int i) { return i * i; } - private int bad(int i) { return i * (5 - i); } + private int bad(int i) { return i * (5 - i); } - private SortedArray array; + private SortedArray array; - [SetUp] - public void Init() { array = new SortedArray(new IC()); } + [SetUp] + public void Init() { array = new SortedArray(new IC()); } - [Test] - public void EmptyEmpty() - { - array.AddSorted(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - } + [Test] + public void EmptyEmpty() + { + array.AddSorted(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + } - [Test] - public void SomeEmpty() + [Test] + public void SomeEmpty() + { + for (int i = 4; i < 9; i++) { - for (int i = 4; i < 9; i++) - { - array.Add(i); - } - - array.AddSorted(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(5)); - Assert.That(array.Check(), Is.True); + array.Add(i); } + array.AddSorted(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(5)); + Assert.That(array.Check(), Is.True); + } + - [Test] - public void EmptySome() + [Test] + public void EmptySome() + { + array.AddSorted(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(4)); + Assert.Multiple(() => { - array.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(4)); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array[0], Is.EqualTo(0)); - Assert.That(array[1], Is.EqualTo(1)); - Assert.That(array[2], Is.EqualTo(4)); - Assert.That(array[3], Is.EqualTo(9)); - }); - } + Assert.That(array.Check(), Is.True); + Assert.That(array[0], Is.EqualTo(0)); + Assert.That(array[1], Is.EqualTo(1)); + Assert.That(array[2], Is.EqualTo(4)); + Assert.That(array[3], Is.EqualTo(9)); + }); + } - [Test] - public void SomeSome() + [Test] + public void SomeSome() + { + for (int i = 3; i < 9; i++) { - for (int i = 3; i < 9; i++) - { - array.Add(i); - } - - array.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(9)); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); - }); + array.Add(i); } - [Test] - public void EmptyBad() + array.AddSorted(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(9)); + Assert.Multiple(() => { - var exception = Assert.Throws(() => array.AddSorted(new FunEnumerable(9, new Func(bad)))); - Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); - } - - - [TearDown] - public void Dispose() { array = null; } + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); + }); } - [TestFixture] - public class Rest + [Test] + public void EmptyBad() { - private SortedArray array, array2; + var exception = Assert.Throws(() => array.AddSorted(new FunEnumerable(9, new Func(bad)))); + Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); + } + + + [TearDown] + public void Dispose() { array = null; } + } + [TestFixture] + public class Rest + { + private SortedArray array, array2; - [SetUp] - public void Init() + + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + array2 = new SortedArray(new IC()); + for (int i = 0; i < 10; i++) { - array = new SortedArray(new IC()); - array2 = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } + array.Add(i); + } - for (int i = 0; i < 10; i++) - { - array2.Add(2 * i); - } + for (int i = 0; i < 10; i++) + { + array2.Add(2 * i); } + } - [Test] - public void RemoveAll() + [Test] + public void RemoveAll() + { + array.RemoveAll(array2.RangeFromTo(3, 7)); + Assert.Multiple(() => { - array.RemoveAll(array2.RangeFromTo(3, 7)); - Assert.Multiple(() => - { - Assert.That(array, Has.Count.EqualTo(8)); - Assert.That(array.Check(), 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(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(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(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); - }); - for (int i = 0; i < 10; i++) - { - array2.Add(i); - } - - array.RemoveAll(array2.RangeFromTo(-1, 10)); - Assert.Multiple(() => - { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); + Assert.That(array.Check(), 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(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(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(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); + }); + for (int i = 0; i < 10; i++) + { + array2.Add(i); } - - [Test] - public void RetainAll() + array.RemoveAll(array2.RangeFromTo(-1, 10)); + Assert.Multiple(() => { - array.RetainAll(array2.RangeFromTo(3, 17)); - Assert.Multiple(() => - { - Assert.That(array, Has.Count.EqualTo(3)); - Assert.That(array.Check(), 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(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(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(array, Is.Empty); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + } - array.RetainAll(array2.RangeFromTo(5, 5)); - Assert.Multiple(() => - { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - array.RetainAll(array2.RangeFromTo(15, 25)); - Assert.Multiple(() => - { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); + [Test] + public void RetainAll() + { + array.RetainAll(array2.RangeFromTo(3, 17)); + Assert.Multiple(() => + { + Assert.That(array, Has.Count.EqualTo(3)); + Assert.That(array.Check(), 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(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(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(array, Is.Empty); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); } - - [Test] - public void ContainsAll() + array.RetainAll(array2.RangeFromTo(5, 5)); + Assert.Multiple(() => { - Assert.Multiple(() => - { - Assert.That(array.ContainsAll(array2), Is.False); - Assert.That(array.ContainsAll(array), Is.True); - }); - array2.Clear(); - Assert.That(array.ContainsAll(array2), Is.True); - array.Clear(); - Assert.That(array.ContainsAll(array2), Is.True); - array2.Add(8); - Assert.That(array.ContainsAll(array2), Is.False); + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); } - - [Test] - public void RemoveInterval() + array.RetainAll(array2.RangeFromTo(15, 25)); + Assert.Multiple(() => { - array.RemoveInterval(3, 4); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Has.Count.EqualTo(6)); - 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(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(array, Is.Empty); - }); - } + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + } - [Test] - public void RemoveRangeBad1() + [Test] + public void ContainsAll() + { + Assert.Multiple(() => { - Assert.Throws(() => array.RemoveInterval(-3, 8)); - } + Assert.That(array.ContainsAll(array2), Is.False); + Assert.That(array.ContainsAll(array), Is.True); + }); + array2.Clear(); + Assert.That(array.ContainsAll(array2), Is.True); + array.Clear(); + Assert.That(array.ContainsAll(array2), Is.True); + array2.Add(8); + Assert.That(array.ContainsAll(array2), Is.False); + } - [Test] - public void RemoveRangeBad2() + [Test] + public void RemoveInterval() + { + array.RemoveInterval(3, 4); + Assert.Multiple(() => { - Assert.Throws(() => array.RemoveInterval(3, -8)); - } + Assert.That(array.Check(), Is.True); + Assert.That(array, Has.Count.EqualTo(6)); + 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(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(array, Is.Empty); + }); + } - [Test] - public void RemoveRangeBad3() - { - Assert.Throws(() => array.RemoveInterval(3, 8)); - } + [Test] + public void RemoveRangeBad1() + { + Assert.Throws(() => array.RemoveInterval(-3, 8)); + } - [Test] - public void GetRange() - { - SCG.IEnumerable e = array[3, 3]; + [Test] + public void RemoveRangeBad2() + { + Assert.Throws(() => array.RemoveInterval(3, -8)); + } - Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); - e = array[3, 0]; - Assert.That(e, Is.Empty); - } - [Test] - public void GetRangeBad1() - { - Assert.Throws(() => { object foo = array[-3, 0]; }); - } + [Test] + public void RemoveRangeBad3() + { + Assert.Throws(() => array.RemoveInterval(3, 8)); + } + + + [Test] + public void GetRange() + { + SCG.IEnumerable e = array[3, 3]; + + Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); + e = array[3, 0]; + Assert.That(e, Is.Empty); + } - [Test] - public void GetRangeBad2() - { - Assert.Throws(() => { object foo = array[3, -1]; }); - } + [Test] + public void GetRangeBad1() + { + Assert.Throws(() => { object foo = array[-3, 0]; }); + } - [Test] - public void GetRangeBad3() - { - Assert.Throws(() => { object foo = array[3, 8]; }); - } + [Test] + public void GetRangeBad2() + { + Assert.Throws(() => { object foo = array[3, -1]; }); + } - [TearDown] - public void Dispose() { array = null; array2 = null; } + [Test] + public void GetRangeBad3() + { + Assert.Throws(() => { object foo = array[3, 8]; }); } + + [TearDown] + public void Dispose() { array = null; array2 = null; } } +} - namespace Sync +namespace Sync +{ + [TestFixture] + public class SyncRoot { - [TestFixture] - public class SyncRoot + private SortedArray tree; + private readonly object mySyncRoot = new(); + private readonly int sz = 5000; + + + [Test] + public void Safe() { - private SortedArray tree; - private readonly object mySyncRoot = new(); - private readonly int sz = 5000; + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(safe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(safe2)); + t1.Start(); + t2.Start(); + t1.Join(); + t2.Join(); + Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); + Assert.That(tree.Check(), Is.True); + } + + + //[Test] + public void UnSafe() + { + bool bad = false; - [Test] - public void Safe() + for (int i = 0; i < 10; i++) { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(safe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(safe2)); + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); t1.Start(); t2.Start(); t1.Join(); t2.Join(); - Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); - Assert.That(tree.Check(), Is.True); + if (bad = 2 * sz + 1 != tree.Count) + { + Console.WriteLine("{0}::Unsafe(): bad at {1}", GetType(), i); + break; + } } + Assert.That(bad, Is.True, "No sync problems!"); + } - //[Test] - public void UnSafe() - { - bool bad = false; - for (int i = 0; i < 10; i++) - { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); - - t1.Start(); - t2.Start(); - t1.Join(); - t2.Join(); - if (bad = 2 * sz + 1 != tree.Count) - { - Console.WriteLine("{0}::Unsafe(): bad at {1}", GetType(), i); - break; - } - } + [Test] + public void SafeUnSafe() + { + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); - Assert.That(bad, Is.True, "No sync problems!"); - } + t1.Start(); + t1.Join(); + t2.Start(); + t2.Join(); + Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); + } - [Test] - public void SafeUnSafe() - { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); + [SetUp] + public void Init() { tree = new SortedArray(new IC()); } - t1.Start(); - t1.Join(); - t2.Start(); - t2.Join(); - Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); - } + private void unsafe1() + { + for (int i = 0; i < 2 * sz; i++) + { + tree.Add(i * 2); + } - [SetUp] - public void Init() { tree = new SortedArray(new IC()); } + for (int i = 1; i < sz; i++) + { + tree.Remove(i * 4); + } + } - private void unsafe1() + private void safe1() + { + for (int i = 0; i < 2 * sz; i++) { - for (int i = 0; i < 2 * sz; i++) + lock (mySyncRoot) { tree.Add(i * 2); } + } - for (int i = 1; i < sz; i++) + for (int i = 1; i < sz; i++) + { + lock (mySyncRoot) { tree.Remove(i * 4); } } + } - private void safe1() + private void unsafe2() + { + for (int i = 2 * sz; i > 0; i--) { - for (int i = 0; i < 2 * sz; i++) - { - lock (mySyncRoot) - { - tree.Add(i * 2); - } - } + tree.Add(i * 2 + 1); + } - for (int i = 1; i < sz; i++) - { - lock (mySyncRoot) - { - tree.Remove(i * 4); - } - } + for (int i = sz; i > 0; i--) + { + tree.Remove(i * 4 + 1); } + } - private void unsafe2() + private void safe2() + { + for (int i = 2 * sz; i > 0; i--) { - for (int i = 2 * sz; i > 0; i--) + lock (mySyncRoot) { tree.Add(i * 2 + 1); } - - for (int i = sz; i > 0; i--) - { - tree.Remove(i * 4 + 1); - } } - - private void safe2() + for (int i = sz; i > 0; i--) { - for (int i = 2 * sz; i > 0; i--) - { - lock (mySyncRoot) - { - tree.Add(i * 2 + 1); - } - } - - for (int i = sz; i > 0; i--) + lock (mySyncRoot) { - lock (mySyncRoot) - { - tree.Remove(i * 4 + 1); - } + tree.Remove(i * 4 + 1); } } + } - [TearDown] - public void Dispose() { tree = null; } - } + [TearDown] + public void Dispose() { tree = null; } + } - //[TestFixture] - public class ConcurrentQueries - { - private SortedArray tree; - private readonly int sz = 500000; + //[TestFixture] + public class ConcurrentQueries + { + private SortedArray tree; + private readonly int sz = 500000; - [SetUp] - public void Init() + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + for (int i = 0; i < sz; i++) { - tree = new SortedArray(new IC()); - for (int i = 0; i < sz; i++) - { - tree.Add(i); - } + tree.Add(i); } + } - private class A - { - public int count = 0; - private readonly SortedArray t; + private class A + { + public int count = 0; + private readonly SortedArray t; - public A(SortedArray t) { this.t = t; } + public A(SortedArray t) { this.t = t; } - public void a(int i) { count++; } + public void a(int i) { count++; } - public void traverse() { t.Apply(new Action(a)); } - } + public void traverse() { t.Apply(new Action(a)); } + } - [Test] - public void Safe() - { - A a = new(tree); + [Test] + public void Safe() + { + A a = new(tree); - a.traverse(); - Assert.That(a.count, Is.EqualTo(sz)); - } + a.traverse(); + Assert.That(a.count, Is.EqualTo(sz)); + } - [Test] - public void RegrettablyUnsafe() + [Test] + public void RegrettablyUnsafe() + { + System.Threading.Thread[] t = new System.Threading.Thread[10]; + A[] a = new A[10]; + for (int i = 0; i < 10; i++) { - System.Threading.Thread[] t = new System.Threading.Thread[10]; - A[] a = new A[10]; - for (int i = 0; i < 10; i++) - { - a[i] = new A(tree); - t[i] = new System.Threading.Thread(new System.Threading.ThreadStart(a[i].traverse)); - } + a[i] = new A(tree); + t[i] = new System.Threading.Thread(new System.Threading.ThreadStart(a[i].traverse)); + } - for (int i = 0; i < 10; i++) - { - t[i].Start(); - } + for (int i = 0; i < 10; i++) + { + t[i].Start(); + } - for (int i = 0; i < 10; i++) - { - t[i].Join(); - } + for (int i = 0; i < 10; i++) + { + t[i].Join(); + } - for (int i = 0; i < 10; i++) - { - Assert.That(a[i].count, Is.EqualTo(sz)); - } + for (int i = 0; i < 10; i++) + { + Assert.That(a[i].count, Is.EqualTo(sz)); } + } - [TearDown] - public void Dispose() { tree = null; } - } + [TearDown] + public void Dispose() { tree = null; } } +} - namespace Hashing +namespace Hashing +{ + [TestFixture] + public class ISequenced { - [TestFixture] - public class ISequenced - { - private ISequenced dit, dat, dut; + private ISequenced dit, dat, dut; - [SetUp] - 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 ReverseIntegerComparer(), EqualityComparer.Default); - } + [SetUp] + 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 ReverseIntegerComparer(), EqualityComparer.Default); + } - [Test] - public void EmptyEmpty() - { - Assert.That(dit.SequencedEquals(dat), Is.True); - } + [Test] + public void EmptyEmpty() + { + Assert.That(dit.SequencedEquals(dat), Is.True); + } - [Test] - public void EmptyNonEmpty() + [Test] + public void EmptyNonEmpty() + { + dit.Add(3); + Assert.Multiple(() => { - dit.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dat), Is.False); - Assert.That(dat.SequencedEquals(dit), Is.False); - }); - } + Assert.That(dit.SequencedEquals(dat), Is.False); + Assert.That(dat.SequencedEquals(dit), Is.False); + }); + } - [Test] - public void HashVal() + [Test] + public void HashVal() + { + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); + dit.Add(3); + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); + dit.Add(7); + Assert.Multiple(() => { - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); - dit.Add(3); - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); - dit.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3, 7))); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); - }); - dut.Add(3); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); - dut.Add(7); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(7, 3))); - } + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3, 7))); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); + }); + dut.Add(3); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); + dut.Add(7); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(7, 3))); + } - [Test] - public void Normal() + [Test] + public void Normal() + { + dit.Add(3); + dit.Add(7); + dat.Add(3); + Assert.Multiple(() => { - dit.Add(3); - dit.Add(7); - dat.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dat), Is.False); - Assert.That(dat.SequencedEquals(dit), Is.False); - }); - dat.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dat), Is.True); - Assert.That(dat.SequencedEquals(dit), Is.True); - }); - } - - - [Test] - public void WrongOrder() + Assert.That(dit.SequencedEquals(dat), Is.False); + Assert.That(dat.SequencedEquals(dit), Is.False); + }); + dat.Add(7); + Assert.Multiple(() => { - dit.Add(3); - dut.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dut), Is.True); - Assert.That(dut.SequencedEquals(dit), Is.True); - }); - dit.Add(7); - dut.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dut), Is.False); - Assert.That(dut.SequencedEquals(dit), Is.False); - }); - } + Assert.That(dit.SequencedEquals(dat), Is.True); + Assert.That(dat.SequencedEquals(dit), Is.True); + }); + } - [Test] - public void Reflexive() + [Test] + public void WrongOrder() + { + dit.Add(3); + dut.Add(3); + Assert.Multiple(() => { - Assert.That(dit.SequencedEquals(dit), Is.True); - dit.Add(3); - Assert.That(dit.SequencedEquals(dit), Is.True); - dit.Add(7); - Assert.That(dit.SequencedEquals(dit), Is.True); - } - - - [TearDown] - public void Dispose() + Assert.That(dit.SequencedEquals(dut), Is.True); + Assert.That(dut.SequencedEquals(dit), Is.True); + }); + dit.Add(7); + dut.Add(7); + Assert.Multiple(() => { - dit = null; - dat = null; - dut = null; - } + Assert.That(dit.SequencedEquals(dut), Is.False); + Assert.That(dut.SequencedEquals(dit), Is.False); + }); } + [Test] + public void Reflexive() + { + Assert.That(dit.SequencedEquals(dit), Is.True); + dit.Add(3); + Assert.That(dit.SequencedEquals(dit), Is.True); + dit.Add(7); + Assert.That(dit.SequencedEquals(dit), Is.True); + } + - [TestFixture] - public class IEditableCollection + [TearDown] + public void Dispose() { - private ICollection dit, dat, dut; + dit = null; + dat = null; + dut = null; + } + } - [SetUp] - 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 ReverseIntegerComparer(), EqualityComparer.Default); - } + [TestFixture] + public class IEditableCollection + { + private ICollection dit, dat, dut; - [Test] - public void EmptyEmpty() - { - Assert.That(dit.UnsequencedEquals(dat), Is.True); - } + + [SetUp] + 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 ReverseIntegerComparer(), EqualityComparer.Default); + } - [Test] - public void EmptyNonEmpty() - { - dit.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dat), Is.False); - Assert.That(dat.UnsequencedEquals(dit), Is.False); - }); - } + [Test] + public void EmptyEmpty() + { + Assert.That(dit.UnsequencedEquals(dat), Is.True); + } - [Test] - public void HashVal() + [Test] + public void EmptyNonEmpty() + { + dit.Add(3); + Assert.Multiple(() => { - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); - dit.Add(3); - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); - dit.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3, 7))); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); - }); - dut.Add(3); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); - dut.Add(7); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(7, 3))); - } + Assert.That(dit.UnsequencedEquals(dat), Is.False); + Assert.That(dat.UnsequencedEquals(dit), Is.False); + }); + } - [Test] - public void Normal() + [Test] + public void HashVal() + { + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); + dit.Add(3); + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); + dit.Add(7); + Assert.Multiple(() => { - dit.Add(3); - dit.Add(7); - dat.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dat), Is.False); - Assert.That(dat.UnsequencedEquals(dit), Is.False); - }); - dat.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dat), Is.True); - Assert.That(dat.UnsequencedEquals(dit), Is.True); - }); - } + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3, 7))); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); + }); + dut.Add(3); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); + dut.Add(7); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(7, 3))); + } - [Test] - public void WrongOrder() + [Test] + public void Normal() + { + dit.Add(3); + dit.Add(7); + dat.Add(3); + Assert.Multiple(() => { - dit.Add(3); - dut.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dut), Is.True); - Assert.That(dut.UnsequencedEquals(dit), Is.True); - }); - dit.Add(7); - dut.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dut), Is.True); - Assert.That(dut.UnsequencedEquals(dit), Is.True); - }); - } + Assert.That(dit.UnsequencedEquals(dat), Is.False); + Assert.That(dat.UnsequencedEquals(dit), Is.False); + }); + dat.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dat), Is.True); + Assert.That(dat.UnsequencedEquals(dit), Is.True); + }); + } - [Test] - public void Reflexive() + [Test] + public void WrongOrder() + { + dit.Add(3); + dut.Add(3); + Assert.Multiple(() => { - Assert.That(dit.UnsequencedEquals(dit), Is.True); - dit.Add(3); - Assert.That(dit.UnsequencedEquals(dit), Is.True); - dit.Add(7); - Assert.That(dit.UnsequencedEquals(dit), Is.True); - } + Assert.That(dit.UnsequencedEquals(dut), Is.True); + Assert.That(dut.UnsequencedEquals(dit), Is.True); + }); + dit.Add(7); + dut.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dut), Is.True); + Assert.That(dut.UnsequencedEquals(dit), Is.True); + }); + } - [TearDown] - public void Dispose() - { - dit = null; - dat = null; - dut = null; - } + [Test] + public void Reflexive() + { + Assert.That(dit.UnsequencedEquals(dit), Is.True); + dit.Add(3); + Assert.That(dit.UnsequencedEquals(dit), Is.True); + dit.Add(7); + Assert.That(dit.UnsequencedEquals(dit), Is.True); } + + [TearDown] + public void Dispose() + { + dit = null; + dat = null; + dut = null; + } } + +} } \ No newline at end of file diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index ce85024d..77be2703 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -520,9 +520,9 @@ 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(tree, Is.Empty); foreach (int i in all) @@ -531,9 +531,9 @@ public void Remove() } 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(tree, Is.Empty); foreach (int i in all) diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index a5b7bafe..f7b59aed 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -240,9 +240,9 @@ 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(tree, Is.Empty); foreach (int i in all) @@ -251,9 +251,9 @@ public void Remove() } 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(tree, Is.Empty); foreach (int i in all) From aaabc55b1dfb2bd2e849902ca23bc09fdf1d57e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 15:25:16 +0200 Subject: [PATCH 11/14] snap --- C5.Tests/Arrays/SortedArrayTests.cs | 3976 ++++++++++++------------ C5.Tests/Trees/Bag.cs | 46 +- C5.Tests/Trees/RedBlackTreeSetTests.cs | 43 +- 3 files changed, 2032 insertions(+), 2033 deletions(-) diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index 0e59e052..57268605 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -178,1334 +178,1108 @@ public void Backwards() Assert.Multiple(() => { - 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 })); - }); - } - - [Test] - public void Direction() - { - Assert.Multiple(() => - { - Assert.That(array.Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeFrom(20).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeTo(7).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeFromTo(1, 12).Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.RangeAll().Direction, Is.EqualTo(C5.Direction.Forwards)); - Assert.That(array.Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeFrom(20).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeTo(7).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeFromTo(1, 12).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - Assert.That(array.RangeAll().Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); - }); - } - - - [TearDown] - public void Dispose() - { - array = null; - c = null; - } -} + 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 })); + }); + } -[TestFixture] -public class BagItf -{ - private SortedArray array; + [Test] + public void Direction() + { + Assert.Multiple(() => + { + Assert.That(array.Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeFrom(20).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeTo(7).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeFromTo(1, 12).Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.RangeAll().Direction, Is.EqualTo(C5.Direction.Forwards)); + Assert.That(array.Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeFrom(20).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeTo(7).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeFromTo(1, 12).Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + Assert.That(array.RangeAll().Backwards().Direction, Is.EqualTo(C5.Direction.Backwards)); + }); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - for (int i = 10; i < 20; i++) + [TearDown] + public void Dispose() { - array.Add(i); - array.Add(i + 10); + array = null; + c = null; } } - - [Test] - public void Both() + [TestFixture] + public class BagItf { - Assert.Multiple(() => - { - Assert.That(array.ContainsCount(7), Is.EqualTo(0)); - Assert.That(array.ContainsCount(10), Is.EqualTo(1)); - }); - array.RemoveAllCopies(10); - Assert.That(array.ContainsCount(10), Is.EqualTo(0)); - array.RemoveAllCopies(7); - } - + private SortedArray array; - [TearDown] - public void Dispose() - { - array = null; - } -} + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + for (int i = 10; i < 20; i++) + { + array.Add(i); + array.Add(i + 10); + } + } -[TestFixture] -public class Div -{ - private SortedArray array; + [Test] + public void Both() + { + Assert.Multiple(() => + { + Assert.That(array.ContainsCount(7), Is.EqualTo(0)); + Assert.That(array.ContainsCount(10), Is.EqualTo(1)); + }); + array.RemoveAllCopies(10); + Assert.That(array.ContainsCount(10), Is.EqualTo(0)); + array.RemoveAllCopies(7); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - } - [Test] - public void NullEqualityComparerinConstructor1() - { - Assert.Throws(() => new SortedArray(null)); + [TearDown] + public void Dispose() + { + array = null; + } } - [Test] - public void NullEqualityComparerinConstructor2() - { - Assert.Throws(() => new SortedArray(5, null)); - } - [Test] - public void NullEqualityComparerinConstructor3() + [TestFixture] + public class Div { - Assert.Throws(() => new SortedArray(5, null, EqualityComparer.Default)); - } + private SortedArray array; - [Test] - public void NullEqualityComparerinConstructor4() - { - Assert.Throws(() => new SortedArray(5, SCG.Comparer.Default, null)); - } - [Test] - public void NullEqualityComparerinConstructor5() - { - Assert.Throws(() => new SortedArray(5, null, null)); - } + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + } - [Test] - public void Choose() - { - array.Add(7); - Assert.That(array.Choose(), Is.EqualTo(7)); - } + [Test] + public void NullEqualityComparerinConstructor1() + { + Assert.Throws(() => new SortedArray(null)); + } - [Test] - public void BadChoose() - { - Assert.Throws(() => array.Choose()); - } + [Test] + public void NullEqualityComparerinConstructor2() + { + Assert.Throws(() => new SortedArray(5, null)); + } - private void loadup() - { - for (int i = 10; i < 20; i++) + [Test] + public void NullEqualityComparerinConstructor3() { - array.Add(i); - array.Add(i + 10); + Assert.Throws(() => new SortedArray(5, null, EqualityComparer.Default)); } - } + [Test] + public void NullEqualityComparerinConstructor4() + { + Assert.Throws(() => new SortedArray(5, SCG.Comparer.Default, null)); + } - [Test] - public void NoDuplicatesEtc() - { - Assert.That(array.AllowsDuplicates, Is.False); - loadup(); - Assert.Multiple(() => + [Test] + public void NullEqualityComparerinConstructor5() { - Assert.That(array.AllowsDuplicates, Is.False); - Assert.That(array.ContainsSpeed, Is.EqualTo(Speed.Log)); - Assert.That(array.Comparer.Compare(2, 3), Is.LessThan(0)); - Assert.That(array.Comparer.Compare(4, 3), Is.GreaterThan(0)); - Assert.That(array.Comparer.Compare(3, 3), Is.EqualTo(0)); - }); - } + Assert.Throws(() => new SortedArray(5, null, null)); + } - [Test] - public void Add() - { - Assert.That(array.Add(17), Is.True); - Assert.Multiple(() => + [Test] + public void Choose() { - Assert.That(array.Add(17), Is.False); - Assert.That(array.Add(18), Is.True); - }); - Assert.Multiple(() => + array.Add(7); + Assert.That(array.Choose(), Is.EqualTo(7)); + } + + [Test] + public void BadChoose() { - Assert.That(array.Add(18), Is.False); - Assert.That(array, Has.Count.EqualTo(2)); - }); - } + Assert.Throws(() => array.Choose()); + } + private void loadup() + { + for (int i = 10; i < 20; i++) + { + array.Add(i); + array.Add(i + 10); + } + } - [TearDown] - public void Dispose() - { - array = null; - } -} + [Test] + public void NoDuplicatesEtc() + { + Assert.That(array.AllowsDuplicates, Is.False); + loadup(); + Assert.Multiple(() => + { + Assert.That(array.AllowsDuplicates, Is.False); + Assert.That(array.ContainsSpeed, Is.EqualTo(Speed.Log)); + Assert.That(array.Comparer.Compare(2, 3), Is.LessThan(0)); + Assert.That(array.Comparer.Compare(4, 3), Is.GreaterThan(0)); + Assert.That(array.Comparer.Compare(3, 3), Is.EqualTo(0)); + }); + } -[TestFixture] -public class FindOrAdd -{ - private SortedArray> bag; + [Test] + public void Add() + { + Assert.That(array.Add(17), Is.True); + Assert.Multiple(() => + { + Assert.That(array.Add(17), Is.False); + Assert.That(array.Add(18), Is.True); + }); + Assert.Multiple(() => + { + Assert.That(array.Add(18), Is.False); + Assert.That(array, Has.Count.EqualTo(2)); + }); + } - [SetUp] - public void Init() - { - bag = new SortedArray>(new KeyValuePairComparer(new IC())); + [TearDown] + public void Dispose() + { + array = null; + } } - [TearDown] - public void Dispose() + [TestFixture] + public class FindOrAdd { - bag = null; - } - + private SortedArray> bag; - [Test] - public void Test() - { - SCG.KeyValuePair p = new(3, "tre"); - Assert.That(bag.FindOrAdd(ref p), Is.False); - p = new SCG.KeyValuePair(p.Key, "drei"); - Assert.Multiple(() => - { - Assert.That(bag.FindOrAdd(ref p), Is.True); - Assert.That(p.Value, Is.EqualTo("tre")); - }); - p = new SCG.KeyValuePair(p.Key, "three"); - Assert.Multiple(() => + [SetUp] + public void Init() { - Assert.That(bag.ContainsCount(p), Is.EqualTo(1)); - Assert.That(bag[0].Value, Is.EqualTo("tre")); - }); - } -} - -[TestFixture] -public class FindPredicate -{ - private SortedArray list; - private Func pred; + bag = new SortedArray>(new KeyValuePairComparer(new IC())); + } - [SetUp] - public void Init() - { - list = new SortedArray(TenEqualityComparer.Instance); - pred = delegate (int i) { return i % 5 == 0; }; - } - [TearDown] - public void Dispose() { list = null; } + [TearDown] + public void Dispose() + { + bag = null; + } - [Test] - public void Find() - { - Assert.That(list.Find(pred, out int i), Is.False); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.Find(pred, out i), Is.False); - list.AddAll([45, 122, 675, 137]); - Assert.Multiple(() => - { - Assert.That(list.Find(pred, out i), Is.True); - Assert.That(i, Is.EqualTo(45)); - }); - } - [Test] - public void FindLast() - { - Assert.That(list.FindLast(pred, out int i), Is.False); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindLast(pred, out i), Is.False); - list.AddAll([45, 122, 675, 137]); - Assert.Multiple(() => - { - Assert.That(list.FindLast(pred, out i), Is.True); - Assert.That(i, Is.EqualTo(675)); - }); - } + [Test] + public void Test() + { + SCG.KeyValuePair p = new(3, "tre"); - [Test] - public void FindIndex() - { - Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([45, 122, 675, 137]); - Assert.That(list.FindIndex(pred), Is.EqualTo(3)); + Assert.That(bag.FindOrAdd(ref p), Is.False); + p = new SCG.KeyValuePair(p.Key, "drei"); + Assert.Multiple(() => + { + Assert.That(bag.FindOrAdd(ref p), Is.True); + Assert.That(p.Value, Is.EqualTo("tre")); + }); + p = new SCG.KeyValuePair(p.Key, "three"); + Assert.Multiple(() => + { + Assert.That(bag.ContainsCount(p), Is.EqualTo(1)); + Assert.That(bag[0].Value, Is.EqualTo("tre")); + }); + } } - [Test] - public void FindLastIndex() + [TestFixture] + public class FindPredicate { - Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([4, 22, 67, 37]); - Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); - list.AddAll([45, 122, 675, 137]); - Assert.That(list.FindLastIndex(pred), Is.EqualTo(7)); - } -} + private SortedArray list; + private Func pred; -[TestFixture] -public class UniqueItems -{ - private SortedArray list; - - [SetUp] - public void Init() { list = []; } + [SetUp] + public void Init() + { + list = new SortedArray(TenEqualityComparer.Instance); + pred = delegate (int i) { return i % 5 == 0; }; + } - [TearDown] - public void Dispose() { list = null; } + [TearDown] + public void Dispose() { list = null; } - [Test] - public void Test() - { - Assert.Multiple(() => - { - Assert.That(list.UniqueItems(), Is.Empty); - Assert.That(list.ItemMultiplicities(), Is.Empty); - }); - list.AddAll([7, 9, 7]); - Assert.Multiple(() => + [Test] + public void Find() { - 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) })); - }); - } -} + Assert.That(list.Find(pred, out int i), Is.False); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.Find(pred, out i), Is.False); + list.AddAll([45, 122, 675, 137]); + Assert.Multiple(() => + { + Assert.That(list.Find(pred, out i), Is.True); + Assert.That(i, Is.EqualTo(45)); + }); + } -[TestFixture] -public class ArrayTest -{ - private SortedArray tree; - private int[] a; + [Test] + public void FindLast() + { + Assert.That(list.FindLast(pred, out int i), Is.False); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindLast(pred, out i), Is.False); + list.AddAll([45, 122, 675, 137]); + Assert.Multiple(() => + { + Assert.That(list.FindLast(pred, out i), Is.True); + Assert.That(i, Is.EqualTo(675)); + }); + } + [Test] + public void FindIndex() + { + Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([45, 122, 675, 137]); + Assert.That(list.FindIndex(pred), Is.EqualTo(3)); + } - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - a = new int[10]; - for (int i = 0; i < 10; i++) + [Test] + public void FindLastIndex() { - a[i] = 1000 + i; + Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([4, 22, 67, 37]); + Assert.That(list.FindLastIndex(pred), Is.LessThanOrEqualTo(0)); + list.AddAll([45, 122, 675, 137]); + Assert.That(list.FindLastIndex(pred), Is.EqualTo(7)); } } + [TestFixture] + public class UniqueItems + { + private SortedArray list; - [TearDown] - public void Dispose() { tree = null; } + [SetUp] + public void Init() { list = []; } + [TearDown] + public void Dispose() { list = null; } - [Test] - public void ToArray() - { - Assert.That(tree.ToArray(), Is.Empty); - tree.Add(7); - tree.Add(4); - Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); + [Test] + public void Test() + { + Assert.Multiple(() => + { + Assert.That(list.UniqueItems(), Is.Empty); + Assert.That(list.ItemMultiplicities(), Is.Empty); + }); + list.AddAll([7, 9, 7]); + Assert.Multiple(() => + { + 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) })); + }); + } } - - [Test] - public void CopyTo() + [TestFixture] + public class ArrayTest { - tree.CopyTo(a, 1); - 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(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(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(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); - } + private SortedArray tree; + private int[] a; - [Test] - public void CopyToBad() - { - Assert.Throws(() => tree.CopyTo(a, 11)); - } + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + a = new int[10]; + for (int i = 0; i < 10; i++) + { + a[i] = 1000 + i; + } + } - [Test] - public void CopyToBad2() - { - Assert.Throws(() => tree.CopyTo(a, -1)); - } + [TearDown] + public void Dispose() { tree = null; } - [Test] - public void CopyToTooFar() - { - tree.Add(3); - tree.Add(4); - Assert.Throws(() => tree.CopyTo(a, 9)); - } -} + [Test] + public void ToArray() + { + Assert.That(tree.ToArray(), Is.Empty); + tree.Add(7); + tree.Add(4); + Assert.That(tree.ToArray(), Is.EqualTo(new[] { 4, 7 })); + } -[TestFixture] -public class Combined -{ - private IIndexedSorted> lst; + [Test] + public void CopyTo() + { + tree.CopyTo(a, 1); + 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(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(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(a, Is.EqualTo(new[] { 1000, 1001, 6, 1003, 4, 6, 9, 1007, 1008, 7 })); + } - [SetUp] - public void Init() - { - lst = new SortedArray>(new KeyValuePairComparer(new IC())); - for (int i = 0; i < 10; i++) + [Test] + public void CopyToBad() { - lst.Add(new SCG.KeyValuePair(i, i + 30)); + Assert.Throws(() => tree.CopyTo(a, 11)); } - } - [TearDown] - public void Dispose() { lst = null; } + [Test] + public void CopyToBad2() + { + Assert.Throws(() => tree.CopyTo(a, -1)); + } - [Test] - public void Find() - { - SCG.KeyValuePair p = new(3, 78); - Assert.Multiple(() => + [Test] + public void CopyToTooFar() { - Assert.That(lst.Find(ref p), Is.True); - Assert.That(p.Key, Is.EqualTo(3)); - Assert.That(p.Value, Is.EqualTo(33)); - }); - p = new SCG.KeyValuePair(13, 78); - Assert.That(lst.Find(ref p), Is.False); + tree.Add(3); + tree.Add(4); + Assert.Throws(() => tree.CopyTo(a, 9)); + } } - [Test] - public void FindOrAdd() + [TestFixture] + public class Combined { - SCG.KeyValuePair p = new(3, 78); + private IIndexedSorted> lst; - Assert.Multiple(() => - { - Assert.That(lst.FindOrAdd(ref p), Is.True); - Assert.That(p.Key, Is.EqualTo(3)); - Assert.That(p.Value, Is.EqualTo(33)); - }); - p = new SCG.KeyValuePair(13, 79); - Assert.Multiple(() => + + [SetUp] + public void Init() { - Assert.That(lst.FindOrAdd(ref p), Is.False); - Assert.That(lst[10].Key, Is.EqualTo(13)); - Assert.That(lst[10].Value, Is.EqualTo(79)); - }); - } + lst = new SortedArray>(new KeyValuePairComparer(new IC())); + for (int i = 0; i < 10; i++) + { + lst.Add(new SCG.KeyValuePair(i, i + 30)); + } + } + [TearDown] + public void Dispose() { lst = null; } - [Test] - public void Update() - { - SCG.KeyValuePair p = new(3, 78); - Assert.Multiple(() => + [Test] + public void Find() { - Assert.That(lst.Update(p), Is.True); - Assert.That(lst[3].Key, Is.EqualTo(3)); - Assert.That(lst[3].Value, Is.EqualTo(78)); - }); - p = new SCG.KeyValuePair(13, 78); - Assert.That(lst.Update(p), Is.False); - } + 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 SCG.KeyValuePair(13, 78); + Assert.That(lst.Find(ref p), Is.False); + } - [Test] - public void UpdateOrAdd1() - { - SCG.KeyValuePair p = new(3, 78); - Assert.Multiple(() => - { - Assert.That(lst.UpdateOrAdd(p), Is.True); - Assert.That(lst[3].Key, Is.EqualTo(3)); - Assert.That(lst[3].Value, Is.EqualTo(78)); - }); - p = new SCG.KeyValuePair(13, 79); - Assert.Multiple(() => + [Test] + public void FindOrAdd() { - Assert.That(lst.UpdateOrAdd(p), Is.False); - Assert.That(lst[10].Key, Is.EqualTo(13)); - Assert.That(lst[10].Value, Is.EqualTo(79)); - }); - } - - [Test] - public void UpdateOrAdd2() - { - ICollection coll = new SortedArray(); - // s1 and s2 are distinct objects but contain the same text: - string s1 = "abc", s2 = ("def" + s1).Substring(3); - Assert.Multiple(() => - { - Assert.That(coll.UpdateOrAdd(s1, out string old), Is.False); - Assert.That(old, Is.EqualTo(null)); - Assert.That(coll.UpdateOrAdd(s2, out old), Is.True); - Assert.That(ReferenceEquals(s1, old), Is.True); - Assert.That(ReferenceEquals(s2, old), Is.False); - }); - } + SCG.KeyValuePair p = new(3, 78); - [Test] - public void UpdateOrAddWithExpand() - { - // bug20071217 - SortedArray arr = []; - for (int i = 0; i < 50; i++) - { - arr.UpdateOrAdd(i + 0.1); - arr.Add(i + 0.2); + Assert.Multiple(() => + { + Assert.That(lst.FindOrAdd(ref p), Is.True); + Assert.That(p.Key, Is.EqualTo(3)); + Assert.That(p.Value, Is.EqualTo(33)); + }); + p = new SCG.KeyValuePair(13, 79); + Assert.Multiple(() => + { + Assert.That(lst.FindOrAdd(ref p), Is.False); + Assert.That(lst[10].Key, Is.EqualTo(13)); + Assert.That(lst[10].Value, Is.EqualTo(79)); + }); } - Assert.That(arr, Has.Count.EqualTo(100)); - } - [Test] - public void FindOrAddWithExpand() - { - // bug20071217 - SortedArray arr = []; - for (int i = 0; i < 50; i++) + + [Test] + public void Update() { - double iVar = i + 0.1; - arr.FindOrAdd(ref iVar); - arr.Add(i * 0.2); - } - Assert.That(arr, Has.Count.EqualTo(100)); - } + SCG.KeyValuePair p = new(3, 78); - [Test] - public void RemoveWithReturn() - { - SCG.KeyValuePair p = new(3, 78); - - Assert.Multiple(() => - { - Assert.That(lst.Remove(p, out p), Is.True); - Assert.That(p.Key, Is.EqualTo(3)); - Assert.That(p.Value, Is.EqualTo(33)); - Assert.That(lst[3].Key, Is.EqualTo(4)); - Assert.That(lst[3].Value, Is.EqualTo(34)); - }); - p = new SCG.KeyValuePair(13, 78); - Assert.That(lst.Remove(p, out _), Is.False); - } -} + Assert.Multiple(() => + { + Assert.That(lst.Update(p), Is.True); + Assert.That(lst[3].Key, Is.EqualTo(3)); + Assert.That(lst[3].Value, Is.EqualTo(78)); + }); + p = new SCG.KeyValuePair(13, 78); + Assert.That(lst.Update(p), Is.False); + } -[TestFixture] -public class Remove -{ - private SortedArray array; + [Test] + public void UpdateOrAdd1() + { + SCG.KeyValuePair p = new(3, 78); + Assert.Multiple(() => + { + Assert.That(lst.UpdateOrAdd(p), Is.True); + Assert.That(lst[3].Key, Is.EqualTo(3)); + Assert.That(lst[3].Value, Is.EqualTo(78)); + }); + p = new SCG.KeyValuePair(13, 79); + Assert.Multiple(() => + { + Assert.That(lst.UpdateOrAdd(p), Is.False); + Assert.That(lst[10].Key, Is.EqualTo(13)); + Assert.That(lst[10].Value, Is.EqualTo(79)); + }); + } - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - for (int i = 10; i < 20; i++) + [Test] + public void UpdateOrAdd2() { - array.Add(i); - array.Add(i + 10); + ICollection coll = new SortedArray(); + // s1 and s2 are distinct objects but contain the same text: + string s1 = "abc", s2 = ("def" + s1).Substring(3); + Assert.Multiple(() => + { + Assert.That(coll.UpdateOrAdd(s1, out string old), Is.False); + Assert.That(old, Is.EqualTo(null)); + Assert.That(coll.UpdateOrAdd(s2, out old), Is.True); + Assert.That(ReferenceEquals(s1, old), Is.True); + Assert.That(ReferenceEquals(s2, old), Is.False); + }); } - } + [Test] + public void UpdateOrAddWithExpand() + { + // bug20071217 + SortedArray arr = []; + for (int i = 0; i < 50; i++) + { + arr.UpdateOrAdd(i + 0.1); + arr.Add(i + 0.2); + } + Assert.That(arr, Has.Count.EqualTo(100)); + } - [Test] - public void SmallTrees() - { - array.Clear(); - array.Add(7); - array.Add(9); - Assert.Multiple(() => - { - Assert.That(array.Remove(7), Is.True); - Assert.That(array.Check(), Is.True); - }); - } + [Test] + public void FindOrAddWithExpand() + { + // bug20071217 + SortedArray arr = []; + for (int i = 0; i < 50; i++) + { + double iVar = i + 0.1; + arr.FindOrAdd(ref iVar); + arr.Add(i * 0.2); + } + Assert.That(arr, Has.Count.EqualTo(100)); + } + [Test] + public void RemoveWithReturn() + { + SCG.KeyValuePair p = new(3, 78); - [Test] - public void ByIndex() - { - //Remove root! - int n = array.Count; - int i = array[10]; - - array.RemoveAt(10); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 1)); - }); - - //Low end - i = array.FindMin(); - array.RemoveAt(0); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 2)); - }); - - //high end - i = array.FindMax(); - array.RemoveAt(array.Count - 1); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 3)); - }); - - //Some leaf - i = 18; - array.RemoveAt(7); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(i)); - Assert.That(array, Has.Count.EqualTo(n - 4)); - }); + Assert.Multiple(() => + { + Assert.That(lst.Remove(p, out p), Is.True); + Assert.That(p.Key, Is.EqualTo(3)); + Assert.That(p.Value, Is.EqualTo(33)); + Assert.That(lst[3].Key, Is.EqualTo(4)); + Assert.That(lst[3].Value, Is.EqualTo(34)); + }); + p = new SCG.KeyValuePair(13, 78); + Assert.That(lst.Remove(p, out _), Is.False); + } } - [Test] - public void AlmostEmpty() + [TestFixture] + public class Remove { - //Almost empty - array.Clear(); - array.Add(3); - array.RemoveAt(0); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Does.Not.Contain(3)); - Assert.That(array, Is.Empty); - }); - } + private SortedArray array; - [Test] - public void Empty() - { - array.Clear(); + [SetUp] + public void Init() + { + array = new SortedArray(new IC()); + for (int i = 10; i < 20; i++) + { + array.Add(i); + array.Add(i + 10); + } + } - var exception = Assert.Throws(() => array.RemoveAt(0)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); - } + [Test] + public void SmallTrees() + { + array.Clear(); + array.Add(7); + array.Add(9); + Assert.Multiple(() => + { + Assert.That(array.Remove(7), Is.True); + Assert.That(array.Check(), Is.True); + }); + } - [Test] - public void HighIndex() - { - var exception = Assert.Throws(() => array.RemoveAt(array.Count)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); - } + [Test] + public void ByIndex() + { + //Remove root! + int n = array.Count; + int i = array[10]; - [Test] - public void LowIndex() - { - var exception = Assert.Throws(() => array.RemoveAt(-1)); - Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); - } + array.RemoveAt(10); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 1)); + }); + //Low end + i = array.FindMin(); + array.RemoveAt(0); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 2)); + }); - [Test] - public void Normal() - { - Assert.Multiple(() => - { - Assert.That(array.Remove(-20), Is.False); + //high end + i = array.FindMax(); + array.RemoveAt(array.Count - 1); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 3)); + }); - //No demote case, with move_item - Assert.That(array.Remove(20), Is.True); - Assert.That(array.Check(), Is.True); - Assert.That(array.Remove(20), Is.False); + //Some leaf + i = 18; + array.RemoveAt(7); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(i)); + Assert.That(array, Has.Count.EqualTo(n - 4)); + }); + } - //plain case 2 - Assert.That(array.Remove(14), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - //case 1b - Assert.That(array.Remove(25), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); + [Test] + public void AlmostEmpty() + { + //Almost empty + array.Clear(); + array.Add(3); + array.RemoveAt(0); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Does.Not.Contain(3)); + Assert.That(array, Is.Empty); + }); + } - //case 1c - Assert.That(array.Remove(29), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); - //1a (terminating) - Assert.That(array.Remove(10), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); + [Test] + public void Empty() + { + array.Clear(); - //2+1b - Assert.That(array.Remove(12), Is.True); - Assert.That(array.Remove(11), Is.True); + var exception = Assert.Throws(() => array.RemoveAt(0)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); + } - //1a+1b - Assert.That(array.Remove(18), Is.True); - Assert.That(array.Remove(13), Is.True); - Assert.That(array.Remove(15), Is.True); - }); - //2+1c - for (int i = 0; i < 10; i++) + [Test] + public void HighIndex() { - array.Add(50 - 2 * i); + var exception = Assert.Throws(() => array.RemoveAt(array.Count)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); } - Assert.Multiple(() => - { - Assert.That(array.Remove(42), Is.True); - Assert.That(array.Remove(38), Is.True); - Assert.That(array.Remove(28), Is.True); - Assert.That(array.Remove(40), Is.True); - // - Assert.That(array.Remove(16), Is.True); - Assert.That(array.Remove(23), Is.True); - Assert.That(array.Remove(17), Is.True); - Assert.That(array.Remove(19), Is.True); - Assert.That(array.Remove(50), Is.True); - Assert.That(array.Remove(26), Is.True); - Assert.That(array.Remove(21), Is.True); - Assert.That(array.Remove(22), Is.True); - Assert.That(array.Remove(24), Is.True); - }); - for (int i = 0; i < 48; i++) + [Test] + public void LowIndex() { - array.Remove(i); + var exception = Assert.Throws(() => array.RemoveAt(-1)); + Assert.That(exception.Message, Is.EqualTo("Index out of range for sequenced collectionvalue")); } - Assert.Multiple(() => + + [Test] + public void Normal() { - //Almost empty tree: - Assert.That(array.Remove(26), Is.False); - Assert.That(array.Remove(48), Is.True); - Assert.That(array.Check(), Is.True, "Bad tree"); + Assert.Multiple(() => + { + Assert.That(array.Remove(-20), Is.False); - //Empty tree: - Assert.That(array.Remove(26), Is.False); - Assert.That(array.Check(), Is.True, "Bad tree"); - }); - } + //No demote case, with move_item + Assert.That(array.Remove(20), Is.True); + Assert.That(array.Check(), Is.True); + Assert.That(array.Remove(20), Is.False); + //plain case 2 + Assert.That(array.Remove(14), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); - [TearDown] - public void Dispose() - { - array = null; - } -} + //case 1b + Assert.That(array.Remove(25), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); + //case 1c + Assert.That(array.Remove(29), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); + //1a (terminating) + Assert.That(array.Remove(10), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); -[TestFixture] -public class PredecessorStructure -{ - private SortedArray tree; + //2+1b + Assert.That(array.Remove(12), Is.True); + Assert.That(array.Remove(11), Is.True); + //1a+1b + Assert.That(array.Remove(18), Is.True); + Assert.That(array.Remove(13), Is.True); + Assert.That(array.Remove(15), Is.True); + }); - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - } + //2+1c + for (int i = 0; i < 10; i++) + { + array.Add(50 - 2 * i); + } + + Assert.Multiple(() => + { + Assert.That(array.Remove(42), Is.True); + Assert.That(array.Remove(38), Is.True); + Assert.That(array.Remove(28), Is.True); + Assert.That(array.Remove(40), Is.True); + + // + Assert.That(array.Remove(16), Is.True); + Assert.That(array.Remove(23), Is.True); + Assert.That(array.Remove(17), Is.True); + Assert.That(array.Remove(19), Is.True); + Assert.That(array.Remove(50), Is.True); + Assert.That(array.Remove(26), Is.True); + Assert.That(array.Remove(21), Is.True); + Assert.That(array.Remove(22), Is.True); + Assert.That(array.Remove(24), Is.True); + }); + for (int i = 0; i < 48; i++) + { + array.Remove(i); + } + + Assert.Multiple(() => + { + //Almost empty tree: + Assert.That(array.Remove(26), Is.False); + Assert.That(array.Remove(48), Is.True); + Assert.That(array.Check(), Is.True, "Bad tree"); + //Empty tree: + Assert.That(array.Remove(26), Is.False); + Assert.That(array.Check(), Is.True, "Bad tree"); + }); + } - private void loadup() - { - for (int i = 0; i < 20; i++) + + [TearDown] + public void Dispose() { - tree.Add(2 * i); + array = null; } } - [Test] - public void FindPredecessor() + + + [TestFixture] + public class PredecessorStructure { - loadup(); - Assert.Multiple(() => + private SortedArray tree; + + + [SetUp] + public void Init() { - Assert.That(tree.TryPredecessor(7, out int res) && res == 6, Is.True); - Assert.That(tree.TryPredecessor(8, out res) && res == 6, Is.True); + tree = new SortedArray(new IC()); + } - //The bottom - Assert.That(tree.TryPredecessor(1, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryPredecessor(39, out res) && res == 38, Is.True); - }); - } + private void loadup() + { + for (int i = 0; i < 20; i++) + { + tree.Add(2 * i); + } + } - [Test] - public void FindPredecessorTooLow1() - { - Assert.Multiple(() => + [Test] + public void FindPredecessor() { - Assert.That(tree.TryPredecessor(-2, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - Assert.That(tree.TryPredecessor(0, out res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.TryPredecessor(7, out int res) && res == 6, Is.True); + Assert.That(tree.TryPredecessor(8, out res) && res == 6, Is.True); - [Test] - public void FindWeakPredecessor() - { - loadup(); - Assert.Multiple(() => + //The bottom + Assert.That(tree.TryPredecessor(1, out res) && res == 0, Is.True); + + //The top + Assert.That(tree.TryPredecessor(39, out res) && res == 38, Is.True); + }); + } + + [Test] + public void FindPredecessorTooLow1() + { + Assert.Multiple(() => + { + Assert.That(tree.TryPredecessor(-2, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + Assert.That(tree.TryPredecessor(0, out res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } + + [Test] + public void FindWeakPredecessor() { - Assert.That(tree.TryWeakPredecessor(7, out int res) && res == 6, Is.True); - Assert.That(tree.TryWeakPredecessor(8, out res) && res == 8, Is.True); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.TryWeakPredecessor(7, out int res) && res == 6, Is.True); + Assert.That(tree.TryWeakPredecessor(8, out res) && res == 8, Is.True); - //The bottom - Assert.That(tree.TryWeakPredecessor(1, out res) && res == 0, Is.True); - Assert.That(tree.TryWeakPredecessor(0, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TryWeakPredecessor(1, out res) && res == 0, Is.True); + Assert.That(tree.TryWeakPredecessor(0, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryWeakPredecessor(39, out res) && res == 38, Is.True); - Assert.That(tree.TryWeakPredecessor(38, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TryWeakPredecessor(39, out res) && res == 38, Is.True); + Assert.That(tree.TryWeakPredecessor(38, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindWeakPredecessorTooLow1() - { - Assert.Multiple(() => + [Test] + public void FindWeakPredecessorTooLow1() { - Assert.That(tree.TryWeakPredecessor(-1, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.Multiple(() => + { + Assert.That(tree.TryWeakPredecessor(-1, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void FindSuccessor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void FindSuccessor() { - Assert.That(tree.TrySuccessor(7, out int res) && res == 8, Is.True); - Assert.That(tree.TrySuccessor(8, out res) && res == 10, Is.True); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.TrySuccessor(7, out int res) && res == 8, Is.True); + Assert.That(tree.TrySuccessor(8, out res) && res == 10, Is.True); - //The bottom - Assert.That(tree.TrySuccessor(0, out res) && res == 2, Is.True); - Assert.That(tree.TrySuccessor(-1, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TrySuccessor(0, out res) && res == 2, Is.True); + Assert.That(tree.TrySuccessor(-1, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TrySuccessor(37, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TrySuccessor(37, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindSuccessorTooHigh() - { - Assert.Multiple(() => + [Test] + public void FindSuccessorTooHigh() { - Assert.That(tree.TrySuccessor(38, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - Assert.That(tree.TrySuccessor(39, out res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.Multiple(() => + { + Assert.That(tree.TrySuccessor(38, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + Assert.That(tree.TrySuccessor(39, out res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void FindWeakSuccessor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void FindWeakSuccessor() { - Assert.That(tree.TryWeakSuccessor(6, out int res) && res == 6, Is.True); - Assert.That(tree.TryWeakSuccessor(7, out res) && res == 8, Is.True); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.TryWeakSuccessor(6, out int res) && res == 6, Is.True); + Assert.That(tree.TryWeakSuccessor(7, out res) && res == 8, Is.True); - //The bottom - Assert.That(tree.TryWeakSuccessor(-1, out res) && res == 0, Is.True); - Assert.That(tree.TryWeakSuccessor(0, out res) && res == 0, Is.True); + //The bottom + Assert.That(tree.TryWeakSuccessor(-1, out res) && res == 0, Is.True); + Assert.That(tree.TryWeakSuccessor(0, out res) && res == 0, Is.True); - //The top - Assert.That(tree.TryWeakSuccessor(37, out res) && res == 38, Is.True); - Assert.That(tree.TryWeakSuccessor(38, out res) && res == 38, Is.True); - }); - } + //The top + Assert.That(tree.TryWeakSuccessor(37, out res) && res == 38, Is.True); + Assert.That(tree.TryWeakSuccessor(38, out res) && res == 38, Is.True); + }); + } - [Test] - public void FindWeakSuccessorTooHigh1() - { - Assert.Multiple(() => + [Test] + public void FindWeakSuccessorTooHigh1() { - Assert.That(tree.TryWeakSuccessor(39, out int res), Is.False); - Assert.That(res, Is.EqualTo(0)); - }); - } + Assert.Multiple(() => + { + Assert.That(tree.TryWeakSuccessor(39, out int res), Is.False); + Assert.That(res, Is.EqualTo(0)); + }); + } - [Test] - public void Predecessor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void Predecessor() { - Assert.That(tree.Predecessor(7), Is.EqualTo(6)); - Assert.That(tree.Predecessor(8), Is.EqualTo(6)); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.Predecessor(7), Is.EqualTo(6)); + Assert.That(tree.Predecessor(8), Is.EqualTo(6)); - //The bottom - Assert.That(tree.Predecessor(1), Is.EqualTo(0)); + //The bottom + Assert.That(tree.Predecessor(1), Is.EqualTo(0)); - //The top - Assert.That(tree.Predecessor(39), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.Predecessor(39), Is.EqualTo(38)); + }); + } - [Test] - public void PredecessorTooLow1() - { - Assert.Throws(() => tree.Predecessor(-2)); - } + [Test] + public void PredecessorTooLow1() + { + Assert.Throws(() => tree.Predecessor(-2)); + } - [Test] - public void PredecessorTooLow2() - { - Assert.Throws(() => tree.Predecessor(0)); - } + [Test] + public void PredecessorTooLow2() + { + Assert.Throws(() => tree.Predecessor(0)); + } - [Test] - public void WeakPredecessor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void WeakPredecessor() { - Assert.That(tree.WeakPredecessor(7), Is.EqualTo(6)); - Assert.That(tree.WeakPredecessor(8), Is.EqualTo(8)); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.WeakPredecessor(7), Is.EqualTo(6)); + Assert.That(tree.WeakPredecessor(8), Is.EqualTo(8)); - //The bottom - Assert.That(tree.WeakPredecessor(1), Is.EqualTo(0)); - Assert.That(tree.WeakPredecessor(0), Is.EqualTo(0)); + //The bottom + Assert.That(tree.WeakPredecessor(1), Is.EqualTo(0)); + Assert.That(tree.WeakPredecessor(0), Is.EqualTo(0)); - //The top - Assert.That(tree.WeakPredecessor(39), Is.EqualTo(38)); - Assert.That(tree.WeakPredecessor(38), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.WeakPredecessor(39), Is.EqualTo(38)); + Assert.That(tree.WeakPredecessor(38), Is.EqualTo(38)); + }); + } - [Test] - public void WeakPredecessorTooLow1() - { - Assert.Throws(() => tree.WeakPredecessor(-1)); - } + [Test] + public void WeakPredecessorTooLow1() + { + Assert.Throws(() => tree.WeakPredecessor(-1)); + } - [Test] - public void Successor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void Successor() { - Assert.That(tree.Successor(7), Is.EqualTo(8)); - Assert.That(tree.Successor(8), Is.EqualTo(10)); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.Successor(7), Is.EqualTo(8)); + Assert.That(tree.Successor(8), Is.EqualTo(10)); - //The bottom - Assert.That(tree.Successor(0), Is.EqualTo(2)); - Assert.That(tree.Successor(-1), Is.EqualTo(0)); + //The bottom + Assert.That(tree.Successor(0), Is.EqualTo(2)); + Assert.That(tree.Successor(-1), Is.EqualTo(0)); - //The top - Assert.That(tree.Successor(37), Is.EqualTo(38)); - }); - } + //The top + Assert.That(tree.Successor(37), Is.EqualTo(38)); + }); + } - [Test] - public void SuccessorTooHigh1() - { - Assert.Throws(() => tree.Successor(38)); - } - - - [Test] - public void SuccessorTooHigh2() - { - Assert.Throws(() => tree.Successor(39)); - } - - - [Test] - public void WeakSuccessor() - { - loadup(); - Assert.Multiple(() => + [Test] + public void SuccessorTooHigh1() { - Assert.That(tree.WeakSuccessor(6), Is.EqualTo(6)); - Assert.That(tree.WeakSuccessor(7), Is.EqualTo(8)); - - //The bottom - Assert.That(tree.WeakSuccessor(-1), Is.EqualTo(0)); - Assert.That(tree.WeakSuccessor(0), Is.EqualTo(0)); - - //The top - Assert.That(tree.WeakSuccessor(37), Is.EqualTo(38)); - Assert.That(tree.WeakSuccessor(38), Is.EqualTo(38)); - }); - } - - [Test] - public void WeakSuccessorTooHigh1() - { - Assert.Throws(() => tree.WeakSuccessor(39)); - } - - - [TearDown] - public void Dispose() - { - tree = null; - } -} - - - -[TestFixture] -public class PriorityQueue -{ - private SortedArray tree; - - - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - } + Assert.Throws(() => tree.Successor(38)); + } - private void loadup() - { - foreach (int i in new int[] { 1, 2, 3, 4 }) + [Test] + public void SuccessorTooHigh2() { - tree.Add(i); + Assert.Throws(() => tree.Successor(39)); } - } - - - [Test] - public void Normal() - { - loadup(); - Assert.Multiple(() => - { - Assert.That(tree.FindMin(), Is.EqualTo(1)); - Assert.That(tree.FindMax(), Is.EqualTo(4)); - Assert.That(tree.DeleteMin(), Is.EqualTo(1)); - Assert.That(tree.DeleteMax(), Is.EqualTo(4)); - Assert.That(tree.Check(), Is.True, "Bad tree"); - Assert.That(tree.FindMin(), Is.EqualTo(2)); - Assert.That(tree.FindMax(), Is.EqualTo(3)); - Assert.That(tree.DeleteMin(), Is.EqualTo(2)); - Assert.That(tree.DeleteMax(), Is.EqualTo(3)); - Assert.That(tree.Check(), Is.True, "Bad tree"); - }); - } - - - [Test] - public void Empty1() - { - Assert.Throws(() => tree.FindMin()); - } - - - [Test] - public void Empty2() - { - Assert.Throws(() => tree.FindMax()); - } - - - [Test] - public void Empty3() - { - Assert.Throws(() => tree.DeleteMin()); - } - - - [Test] - public void Empty4() - { - Assert.Throws(() => tree.DeleteMax()); - } - - - [TearDown] - public void Dispose() - { - tree = null; - } -} - - - -[TestFixture] -public class IndexingAndCounting -{ - private SortedArray array; - - - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - } - private void populate() - { - array.Add(30); - array.Add(50); - array.Add(10); - array.Add(70); - } - - - [Test] - public void ToArray() - { - populate(); - - int[] a = [.. array]; - - Assert.Multiple(() => + [Test] + public void WeakSuccessor() { - Assert.That(a, Has.Length.EqualTo(4)); - Assert.That(a[0], Is.EqualTo(10)); - Assert.That(a[1], Is.EqualTo(30)); - Assert.That(a[2], Is.EqualTo(50)); - Assert.That(a[3], Is.EqualTo(70)); - }); - } - - - [Test] - public void GoodIndex() - { - Assert.Multiple(() => - { - Assert.That(array.IndexOf(20), Is.EqualTo(~0)); - Assert.That(array.LastIndexOf(20), Is.EqualTo(~0)); - }); - populate(); - Assert.Multiple(() => - { - Assert.That(array[0], Is.EqualTo(10)); - Assert.That(array[1], Is.EqualTo(30)); - Assert.That(array[2], Is.EqualTo(50)); - Assert.That(array[3], Is.EqualTo(70)); - Assert.That(array.IndexOf(10), Is.EqualTo(0)); - Assert.That(array.IndexOf(30), Is.EqualTo(1)); - Assert.That(array.IndexOf(50), Is.EqualTo(2)); - Assert.That(array.IndexOf(70), Is.EqualTo(3)); - Assert.That(array.IndexOf(20), Is.EqualTo(~1)); - Assert.That(array.IndexOf(0), Is.EqualTo(~0)); - Assert.That(array.IndexOf(90), Is.EqualTo(~4)); - Assert.That(array.LastIndexOf(10), Is.EqualTo(0)); - Assert.That(array.LastIndexOf(30), Is.EqualTo(1)); - Assert.That(array.LastIndexOf(50), Is.EqualTo(2)); - Assert.That(array.LastIndexOf(70), Is.EqualTo(3)); - Assert.That(array.LastIndexOf(20), Is.EqualTo(~1)); - Assert.That(array.LastIndexOf(0), Is.EqualTo(~0)); - Assert.That(array.LastIndexOf(90), Is.EqualTo(~4)); - }); - } - - - [Test] - public void IndexTooLarge() - { - populate(); - Assert.Throws(() => Console.WriteLine(array[4])); - } - - - [Test] - public void IndexTooSmall() - { - populate(); - Assert.Throws(() => Console.WriteLine(array[-1])); - } - + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.WeakSuccessor(6), Is.EqualTo(6)); + Assert.That(tree.WeakSuccessor(7), Is.EqualTo(8)); - [Test] - public void FilledTreeOutsideInput() - { - populate(); - Assert.Multiple(() => - { - Assert.That(array.CountFrom(90), Is.EqualTo(0)); - Assert.That(array.CountFromTo(-20, 0), Is.EqualTo(0)); - Assert.That(array.CountFromTo(80, 100), Is.EqualTo(0)); - Assert.That(array.CountTo(0), Is.EqualTo(0)); - Assert.That(array.CountTo(90), Is.EqualTo(4)); - Assert.That(array.CountFromTo(-20, 90), Is.EqualTo(4)); - Assert.That(array.CountFrom(0), Is.EqualTo(4)); - }); - } + //The bottom + Assert.That(tree.WeakSuccessor(-1), Is.EqualTo(0)); + Assert.That(tree.WeakSuccessor(0), Is.EqualTo(0)); + //The top + Assert.That(tree.WeakSuccessor(37), Is.EqualTo(38)); + Assert.That(tree.WeakSuccessor(38), Is.EqualTo(38)); + }); + } - [Test] - public void FilledTreeIntermediateInput() - { - populate(); - Assert.Multiple(() => + [Test] + public void WeakSuccessorTooHigh1() { - Assert.That(array.CountFrom(20), Is.EqualTo(3)); - Assert.That(array.CountFromTo(20, 40), Is.EqualTo(1)); - Assert.That(array.CountTo(40), Is.EqualTo(2)); - }); - } - - - [Test] - public void FilledTreeMatchingInput() - { - populate(); - Assert.Multiple(() => - { - Assert.That(array.CountFrom(30), Is.EqualTo(3)); - Assert.That(array.CountFromTo(30, 70), Is.EqualTo(2)); - Assert.That(array.CountFromTo(50, 30), Is.EqualTo(0)); - Assert.That(array.CountFromTo(50, 50), Is.EqualTo(0)); - Assert.That(array.CountTo(10), Is.EqualTo(0)); - Assert.That(array.CountTo(50), Is.EqualTo(2)); - }); - } + Assert.Throws(() => tree.WeakSuccessor(39)); + } - [Test] - public void CountEmptyTree() - { - Assert.Multiple(() => + [TearDown] + public void Dispose() { - Assert.That(array.CountFrom(20), Is.EqualTo(0)); - Assert.That(array.CountFromTo(20, 40), Is.EqualTo(0)); - Assert.That(array.CountTo(40), Is.EqualTo(0)); - }); - } - - - [TearDown] - public void Dispose() - { - array = null; + tree = null; + } } -} - -namespace ModificationCheck -{ [TestFixture] - public class Enumerator + public class PriorityQueue { private SortedArray tree; - private SCG.IEnumerator e; - [SetUp] public void Init() { tree = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) + } + + + private void loadup() + { + foreach (int i in new int[] { 1, 2, 3, 4 }) { tree.Add(i); } - e = tree.GetEnumerator(); } [Test] - public void CurrentAfterModification() + public void Normal() { - e.MoveNext(); - tree.Add(34); - Assert.That(e.Current, Is.EqualTo(0)); + loadup(); + Assert.Multiple(() => + { + Assert.That(tree.FindMin(), Is.EqualTo(1)); + Assert.That(tree.FindMax(), Is.EqualTo(4)); + Assert.That(tree.DeleteMin(), Is.EqualTo(1)); + Assert.That(tree.DeleteMax(), Is.EqualTo(4)); + Assert.That(tree.Check(), Is.True, "Bad tree"); + Assert.That(tree.FindMin(), Is.EqualTo(2)); + Assert.That(tree.FindMax(), Is.EqualTo(3)); + Assert.That(tree.DeleteMin(), Is.EqualTo(2)); + Assert.That(tree.DeleteMax(), Is.EqualTo(3)); + Assert.That(tree.Check(), Is.True, "Bad tree"); + }); } [Test] - public void MoveNextAfterAdd() + public void Empty1() { - e.MoveNext(); - tree.Add(34); - - Assert.Throws(() => e.MoveNext()); + Assert.Throws(() => tree.FindMin()); } + [Test] - public void MoveNextAfterRemove() + public void Empty2() { - e.MoveNext(); - tree.Remove(34); - - Assert.Throws(() => e.MoveNext()); + Assert.Throws(() => tree.FindMax()); } [Test] - public void MoveNextAfterClear() + public void Empty3() { - e.MoveNext(); - tree.Clear(); + Assert.Throws(() => tree.DeleteMin()); + } - Assert.Throws(() => e.MoveNext()); + + [Test] + public void Empty4() + { + Assert.Throws(() => tree.DeleteMax()); } @@ -1513,1284 +1287,1510 @@ public void MoveNextAfterClear() public void Dispose() { tree = null; - e.Dispose(); } } + + [TestFixture] - public class RangeEnumerator + public class IndexingAndCounting { - private SortedArray tree; - - private SCG.IEnumerator e; + private SortedArray array; [SetUp] public void Init() { - tree = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) - { - tree.Add(i); - } + array = new SortedArray(new IC()); + } - e = tree.RangeFromTo(3, 7).GetEnumerator(); + + private void populate() + { + array.Add(30); + array.Add(50); + array.Add(10); + array.Add(70); } [Test] - public void CurrentAfterModification() + public void ToArray() { - e.MoveNext(); - tree.Add(34); - Assert.That(e.Current, Is.EqualTo(3)); + populate(); + + int[] a = [.. array]; + + Assert.Multiple(() => + { + Assert.That(a, Has.Length.EqualTo(4)); + Assert.That(a[0], Is.EqualTo(10)); + Assert.That(a[1], Is.EqualTo(30)); + Assert.That(a[2], Is.EqualTo(50)); + Assert.That(a[3], Is.EqualTo(70)); + }); } [Test] - public void MoveNextAfterAdd() + public void GoodIndex() { - tree.Add(34); + Assert.Multiple(() => + { + Assert.That(array.IndexOf(20), Is.EqualTo(~0)); + Assert.That(array.LastIndexOf(20), Is.EqualTo(~0)); + }); + populate(); + Assert.Multiple(() => + { + Assert.That(array[0], Is.EqualTo(10)); + Assert.That(array[1], Is.EqualTo(30)); + Assert.That(array[2], Is.EqualTo(50)); + Assert.That(array[3], Is.EqualTo(70)); + Assert.That(array.IndexOf(10), Is.EqualTo(0)); + Assert.That(array.IndexOf(30), Is.EqualTo(1)); + Assert.That(array.IndexOf(50), Is.EqualTo(2)); + Assert.That(array.IndexOf(70), Is.EqualTo(3)); + Assert.That(array.IndexOf(20), Is.EqualTo(~1)); + Assert.That(array.IndexOf(0), Is.EqualTo(~0)); + Assert.That(array.IndexOf(90), Is.EqualTo(~4)); + Assert.That(array.LastIndexOf(10), Is.EqualTo(0)); + Assert.That(array.LastIndexOf(30), Is.EqualTo(1)); + Assert.That(array.LastIndexOf(50), Is.EqualTo(2)); + Assert.That(array.LastIndexOf(70), Is.EqualTo(3)); + Assert.That(array.LastIndexOf(20), Is.EqualTo(~1)); + Assert.That(array.LastIndexOf(0), Is.EqualTo(~0)); + Assert.That(array.LastIndexOf(90), Is.EqualTo(~4)); + }); + } - Assert.Throws(() => e.MoveNext()); + + [Test] + public void IndexTooLarge() + { + populate(); + Assert.Throws(() => Console.WriteLine(array[4])); } + [Test] + public void IndexTooSmall() + { + populate(); + Assert.Throws(() => Console.WriteLine(array[-1])); + } [Test] - public void MoveNextAfterRemove() + public void FilledTreeOutsideInput() { - tree.Remove(34); + populate(); + Assert.Multiple(() => + { + Assert.That(array.CountFrom(90), Is.EqualTo(0)); + Assert.That(array.CountFromTo(-20, 0), Is.EqualTo(0)); + Assert.That(array.CountFromTo(80, 100), Is.EqualTo(0)); + Assert.That(array.CountTo(0), Is.EqualTo(0)); + Assert.That(array.CountTo(90), Is.EqualTo(4)); + Assert.That(array.CountFromTo(-20, 90), Is.EqualTo(4)); + Assert.That(array.CountFrom(0), Is.EqualTo(4)); + }); + } - Assert.Throws(() => e.MoveNext()); + + [Test] + public void FilledTreeIntermediateInput() + { + populate(); + Assert.Multiple(() => + { + Assert.That(array.CountFrom(20), Is.EqualTo(3)); + Assert.That(array.CountFromTo(20, 40), Is.EqualTo(1)); + Assert.That(array.CountTo(40), Is.EqualTo(2)); + }); } [Test] - public void MoveNextAfterClear() + public void FilledTreeMatchingInput() { - tree.Clear(); + populate(); + Assert.Multiple(() => + { + Assert.That(array.CountFrom(30), Is.EqualTo(3)); + Assert.That(array.CountFromTo(30, 70), Is.EqualTo(2)); + Assert.That(array.CountFromTo(50, 30), Is.EqualTo(0)); + Assert.That(array.CountFromTo(50, 50), Is.EqualTo(0)); + Assert.That(array.CountTo(10), Is.EqualTo(0)); + Assert.That(array.CountTo(50), Is.EqualTo(2)); + }); + } - Assert.Throws(() => e.MoveNext()); + + [Test] + public void CountEmptyTree() + { + Assert.Multiple(() => + { + Assert.That(array.CountFrom(20), Is.EqualTo(0)); + Assert.That(array.CountFromTo(20, 40), Is.EqualTo(0)); + Assert.That(array.CountTo(40), Is.EqualTo(0)); + }); } [TearDown] public void Dispose() { - tree = null; - e.Dispose(); + array = null; } } -} -namespace HigherOrder -{ - internal class CubeRoot : IComparable - { - private readonly int c; - internal CubeRoot(int c) { this.c = c; } + namespace ModificationCheck + { + [TestFixture] + public class Enumerator + { + private SortedArray tree; - public int CompareTo(int that) { return c - that * that * that; } + private SCG.IEnumerator e; - public bool Equals(int that) { return c == that * that * that; } - } + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + for (int i = 0; i < 10; i++) + { + tree.Add(i); + } + e = tree.GetEnumerator(); + } - internal class Interval : IComparable - { - private readonly int b, t; + [Test] + public void CurrentAfterModification() + { + e.MoveNext(); + tree.Add(34); + Assert.That(e.Current, Is.EqualTo(0)); + } - internal Interval(int b, int t) { this.b = b; this.t = t; } + [Test] + public void MoveNextAfterAdd() + { + e.MoveNext(); + tree.Add(34); - public int CompareTo(int that) { return that < b ? 1 : that > t ? -1 : 0; } + Assert.Throws(() => e.MoveNext()); + } - public bool Equals(int that) { return that >= b && that <= t; } - } + [Test] + public void MoveNextAfterRemove() + { + e.MoveNext(); + tree.Remove(34); + Assert.Throws(() => e.MoveNext()); + } - [TestFixture] - public class Simple - { - private SortedArray array; + [Test] + public void MoveNextAfterClear() + { + e.MoveNext(); + tree.Clear(); - private SCG.IComparer ic; + Assert.Throws(() => e.MoveNext()); + } - [SetUp] - public void Init() - { - ic = new IC(); - array = new SortedArray(ic); + [TearDown] + public void Dispose() + { + tree = null; + e.Dispose(); + } } + [TestFixture] + public class RangeEnumerator + { + private SortedArray tree; - private bool never(int i) { return false; } - + private SCG.IEnumerator e; - private bool always(int i) { return true; } + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + for (int i = 0; i < 10; i++) + { + tree.Add(i); + } - private bool even(int i) { return i % 2 == 0; } + e = tree.RangeFromTo(3, 7).GetEnumerator(); + } - private string themap(int i) { return string.Format("AA {0,4} BB", i); } + [Test] + public void CurrentAfterModification() + { + e.MoveNext(); + tree.Add(34); + Assert.That(e.Current, Is.EqualTo(3)); + } - private string badmap(int i) { return string.Format("AA {0} BB", i); } + [Test] + public void MoveNextAfterAdd() + { + tree.Add(34); + Assert.Throws(() => e.MoveNext()); + } - private int appfield1; - private int appfield2; - private void apply(int i) { appfield1++; appfield2 += i * i; } + [Test] + public void MoveNextAfterRemove() + { + tree.Remove(34); + Assert.Throws(() => e.MoveNext()); + } - [Test] - public void Apply() - { - Simple simple1 = new(); - array.Apply(new Action(simple1.apply)); - Assert.Multiple(() => + [Test] + public void MoveNextAfterClear() { - Assert.That(simple1.appfield1, Is.EqualTo(0)); - Assert.That(simple1.appfield2, Is.EqualTo(0)); - }); - - Simple simple2 = new(); + tree.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i); + Assert.Throws(() => e.MoveNext()); } - array.Apply(new Action(simple2.apply)); - Assert.Multiple(() => + + [TearDown] + public void Dispose() { - Assert.That(simple2.appfield1, Is.EqualTo(10)); - Assert.That(simple2.appfield2, Is.EqualTo(285)); - }); + tree = null; + e.Dispose(); + } } + } - - [Test] - public void All() + namespace HigherOrder + { + internal class CubeRoot : IComparable { - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.True); - Assert.That(array.All(new Func(even)), Is.True); - Assert.That(array.All(new Func(always)), Is.True); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } + private readonly int c; - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.False); - Assert.That(array.All(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2); - } - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.True); - Assert.That(array.All(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2 + 1); - } + internal CubeRoot(int c) { this.c = c; } - Assert.Multiple(() => - { - Assert.That(array.All(new Func(never)), Is.False); - Assert.That(array.All(new Func(even)), Is.False); - Assert.That(array.All(new Func(always)), Is.True); - }); - } + public int CompareTo(int that) { return c - that * that * that; } - [Test] - public void Exists() + public bool Equals(int that) { return c == that * that * that; } + + } + + internal class Interval : IComparable { - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.False); - Assert.That(array.Exists(new Func(always)), Is.False); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } + private readonly int b, t; - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.True); - Assert.That(array.Exists(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2); - } - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.True); - Assert.That(array.Exists(new Func(always)), Is.True); - }); - array.Clear(); - for (int i = 0; i < 10; i++) - { - array.Add(i * 2 + 1); - } + internal Interval(int b, int t) { this.b = b; this.t = t; } - Assert.Multiple(() => - { - Assert.That(array.Exists(new Func(never)), Is.False); - Assert.That(array.Exists(new Func(even)), Is.False); - Assert.That(array.Exists(new Func(always)), Is.True); - }); + + public int CompareTo(int that) { return that < b ? 1 : that > t ? -1 : 0; } + + public bool Equals(int that) { return that >= b && that <= t; } } - [Test] - public void FindAll() + + [TestFixture] + public class Simple { - Assert.That(array.FindAll(new Func(never)), Is.Empty); - for (int i = 0; i < 10; i++) + private SortedArray array; + + private SCG.IComparer ic; + + + [SetUp] + public void Init() { - array.Add(i); + ic = new IC(); + array = new SortedArray(ic); } - Assert.Multiple(() => - { - Assert.That(array.FindAll(new Func(never)), Is.Empty); - Assert.That(array.FindAll(new Func(always)), Has.Count.EqualTo(10)); - Assert.That(array.FindAll(new Func(even)), Has.Count.EqualTo(5)); - Assert.That(((SortedArray)array.FindAll(new Func(even))).Check(), Is.True); - }); - } + private bool never(int i) { return false; } - [Test] - public void Map() - { - Assert.That(array.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); - for (int i = 0; i < 11; i++) + + private bool always(int i) { return true; } + + + private bool even(int i) { return i % 2 == 0; } + + + private string themap(int i) { return string.Format("AA {0,4} BB", i); } + + + private string badmap(int i) { return string.Format("AA {0} BB", i); } + + + private int appfield1; + + private int appfield2; + + + private void apply(int i) { appfield1++; appfield2 += i * i; } + + + [Test] + public void Apply() { - array.Add(i * i * i); + Simple simple1 = new(); + + array.Apply(new Action(simple1.apply)); + Assert.Multiple(() => + { + Assert.That(simple1.appfield1, Is.EqualTo(0)); + Assert.That(simple1.appfield2, Is.EqualTo(0)); + }); + + Simple simple2 = new(); + + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + + array.Apply(new Action(simple2.apply)); + Assert.Multiple(() => + { + Assert.That(simple2.appfield1, Is.EqualTo(10)); + Assert.That(simple2.appfield2, Is.EqualTo(285)); + }); } - var res = array.Map(new Func(themap), StringComparer.InvariantCulture); - Assert.Multiple(() => + [Test] + public void All() { - Assert.That(((SortedArray)res).Check(), Is.True); - Assert.That(res, Has.Count.EqualTo(11)); - 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")); - Assert.That(res[10], Is.EqualTo("AA 1000 BB")); - }); - } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.True); + Assert.That(array.All(new Func(even)), Is.True); + Assert.That(array.All(new Func(always)), Is.True); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } - [Test] - public void BadMap() - { - for (int i = 0; i < 11; i++) - { - array.Add(i * i * i); - } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.False); + Assert.That(array.All(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2); + } - var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), StringComparer.InvariantCulture); }); - Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); - } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.True); + Assert.That(array.All(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2 + 1); + } + Assert.Multiple(() => + { + Assert.That(array.All(new Func(never)), Is.False); + Assert.That(array.All(new Func(even)), Is.False); + Assert.That(array.All(new Func(always)), Is.True); + }); + } - [Test] - public void Cut() - { - for (int i = 0; i < 10; i++) + + [Test] + public void Exists() { - array.Add(i); + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.False); + Assert.That(array.Exists(new Func(always)), Is.False); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.True); + Assert.That(array.Exists(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2); + } + + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.True); + Assert.That(array.Exists(new Func(always)), Is.True); + }); + array.Clear(); + for (int i = 0; i < 10; i++) + { + array.Add(i * 2 + 1); + } + + Assert.Multiple(() => + { + Assert.That(array.Exists(new Func(never)), Is.False); + Assert.That(array.Exists(new Func(even)), Is.False); + Assert.That(array.Exists(new Func(always)), Is.True); + }); } - Assert.Multiple(() => + + [Test] + public void FindAll() { - Assert.That(array.Cut(new CubeRoot(27), out int low, out bool lval, out int high, out bool hval), Is.True); - Assert.That(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(4)); - Assert.That(low, Is.EqualTo(2)); - Assert.That(array.Cut(new CubeRoot(30), out low, out lval, out high, out hval), Is.False); - Assert.That(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(4)); - Assert.That(low, Is.EqualTo(3)); - }); - } + Assert.That(array.FindAll(new Func(never)), Is.Empty); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + Assert.Multiple(() => + { + Assert.That(array.FindAll(new Func(never)), Is.Empty); + Assert.That(array.FindAll(new Func(always)), Has.Count.EqualTo(10)); + Assert.That(array.FindAll(new Func(even)), Has.Count.EqualTo(5)); + Assert.That(((SortedArray)array.FindAll(new Func(even))).Check(), Is.True); + }); + } - [Test] - public void CutInt() - { - for (int i = 0; i < 10; i++) + + [Test] + public void Map() { - array.Add(2 * i); + Assert.That(array.Map(new Func(themap), StringComparer.InvariantCulture), Is.Empty); + for (int i = 0; i < 11; i++) + { + array.Add(i * i * i); + } + + 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.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")); + Assert.That(res[10], Is.EqualTo("AA 1000 BB")); + }); } - Assert.Multiple(() => + [Test] + public void BadMap() { - Assert.That(array.Cut(new IC(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(lval && hval, Is.True); - Assert.That(high, Is.EqualTo(8)); - Assert.That(low, Is.EqualTo(4)); - }); - } + for (int i = 0; i < 11; i++) + { + array.Add(i * i * i); + } + var exception = Assert.Throws(() => { ISorted res = array.Map(new Func(badmap), StringComparer.InvariantCulture); }); + Assert.That(exception.Message, Is.EqualTo("mapper not monotonic")); + } - [Test] - public void CutInterval() - { - for (int i = 0; i < 10; i++) + + [Test] + public void Cut() { - array.Add(2 * i); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + + Assert.Multiple(() => + { + Assert.That(array.Cut(new CubeRoot(27), out int low, out bool lval, out int high, out bool hval), Is.True); + Assert.That(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(4)); + Assert.That(low, Is.EqualTo(2)); + Assert.That(array.Cut(new CubeRoot(30), out low, out lval, out high, out hval), Is.False); + Assert.That(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(4)); + Assert.That(low, Is.EqualTo(3)); + }); } - Assert.That(array.Cut(new Interval(5, 9), out int lo, out bool lv, out int hi, out bool hv), Is.True); - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(10)); - Assert.That(lo, Is.EqualTo(4)); - Assert.That(array.Cut(new Interval(6, 10), out lo, out lv, out hi, out hv), Is.True); - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(12)); - Assert.That(lo, Is.EqualTo(4)); - for (int i = 0; i < 100; i++) + [Test] + public void CutInt() { - array.Add(2 * i); + for (int i = 0; i < 10; i++) + { + array.Add(2 * i); + } + + 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(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(lval && hval, Is.True); + Assert.That(high, Is.EqualTo(8)); + Assert.That(low, Is.EqualTo(4)); + }); } - array.Cut(new Interval(77, 105), out lo, out lv, out hi, out hv); - Assert.Multiple(() => - { - Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(106)); - Assert.That(lo, Is.EqualTo(76)); - }); - array.Cut(new Interval(5, 7), out lo, out lv, out hi, out hv); - Assert.Multiple(() => + + [Test] + public void CutInterval() { + for (int i = 0; i < 10; i++) + { + array.Add(2 * i); + } + + Assert.That(array.Cut(new Interval(5, 9), out int lo, out bool lv, out int hi, out bool hv), Is.True); Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(8)); + Assert.That(hi, Is.EqualTo(10)); Assert.That(lo, Is.EqualTo(4)); - }); - array.Cut(new Interval(80, 110), out lo, out lv, out hi, out hv); - Assert.Multiple(() => - { + Assert.That(array.Cut(new Interval(6, 10), out lo, out lv, out hi, out hv), Is.True); Assert.That(lv && hv, Is.True); - Assert.That(hi, Is.EqualTo(112)); - Assert.That(lo, Is.EqualTo(78)); - }); - } + Assert.That(hi, Is.EqualTo(12)); + Assert.That(lo, Is.EqualTo(4)); + for (int i = 0; i < 100; i++) + { + array.Add(2 * i); + } - [Test] - public void UpperCut() - { - for (int i = 0; i < 10; i++) - { - array.Add(i); + array.Cut(new Interval(77, 105), out lo, out lv, out hi, out hv); + Assert.Multiple(() => + { + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(106)); + Assert.That(lo, Is.EqualTo(76)); + }); + array.Cut(new Interval(5, 7), out lo, out lv, out hi, out hv); + Assert.Multiple(() => + { + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(8)); + Assert.That(lo, Is.EqualTo(4)); + }); + array.Cut(new Interval(80, 110), out lo, out lv, out hi, out hv); + Assert.Multiple(() => + { + Assert.That(lv && hv, Is.True); + Assert.That(hi, Is.EqualTo(112)); + Assert.That(lo, Is.EqualTo(78)); + }); } - Assert.Multiple(() => + + [Test] + public void UpperCut() { - Assert.That(array.Cut(new CubeRoot(1000), out int l, out bool lv, out _, out bool hv), Is.False); - Assert.That(lv && !hv, Is.True); - Assert.That(l, Is.EqualTo(9)); - Assert.That(array.Cut(new CubeRoot(-50), out _, out lv, out int h, out hv), Is.False); - Assert.That(!lv && hv, Is.True); - Assert.That(h, Is.EqualTo(0)); - }); - } + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + Assert.Multiple(() => + { + Assert.That(array.Cut(new CubeRoot(1000), out int l, out bool lv, out _, out bool hv), Is.False); + Assert.That(lv && !hv, Is.True); + Assert.That(l, Is.EqualTo(9)); + Assert.That(array.Cut(new CubeRoot(-50), out _, out lv, out int h, out hv), Is.False); + Assert.That(!lv && hv, Is.True); + Assert.That(h, Is.EqualTo(0)); + }); + } - [TearDown] - public void Dispose() { ic = null; array = null; } + + [TearDown] + public void Dispose() { ic = null; array = null; } + } } -} -namespace MultiOps -{ - [TestFixture] - public class AddAll + namespace MultiOps { - private int sqr(int i) { return i * i; } - - private SortedArray array; - - - [SetUp] - public void Init() { array = new SortedArray(new IC()); } - - - [Test] - public void EmptyEmpty() + [TestFixture] + public class AddAll { - array.AddAll(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - } + private int sqr(int i) { return i * i; } + private SortedArray array; - [Test] - public void SomeEmpty() - { - for (int i = 4; i < 9; i++) - { - array.Add(i); - } - array.AddAll(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(5)); - Assert.That(array.Check(), Is.True); - } + [SetUp] + public void Init() { array = new SortedArray(new IC()); } - [Test] - public void EmptySome() - { - array.AddAll(new FunEnumerable(4, new Func(sqr))); - Assert.Multiple(() => + [Test] + public void EmptyEmpty() { - Assert.That(array, Has.Count.EqualTo(4)); + array.AddAll(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); - Assert.That(array[0], Is.EqualTo(0)); - Assert.That(array[1], Is.EqualTo(1)); - Assert.That(array[2], Is.EqualTo(4)); - Assert.That(array[3], Is.EqualTo(9)); - }); - } + } - [Test] - public void SomeSome() - { - for (int i = 3; i < 9; i++) + [Test] + public void SomeEmpty() { - array.Add(i); - } + for (int i = 4; i < 9; i++) + { + array.Add(i); + } - array.AddAll(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(9)); - Assert.Multiple(() => - { + array.AddAll(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(5)); Assert.That(array.Check(), Is.True); - Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); - }); - } - - - [TearDown] - public void Dispose() { array = null; } - } + } + [Test] + public void EmptySome() + { + array.AddAll(new FunEnumerable(4, new Func(sqr))); + Assert.Multiple(() => + { + Assert.That(array, Has.Count.EqualTo(4)); + Assert.That(array.Check(), Is.True); + Assert.That(array[0], Is.EqualTo(0)); + Assert.That(array[1], Is.EqualTo(1)); + Assert.That(array[2], Is.EqualTo(4)); + Assert.That(array[3], Is.EqualTo(9)); + }); + } - [TestFixture] - public class AddSorted - { - private int sqr(int i) { return i * i; } + [Test] + public void SomeSome() + { + for (int i = 3; i < 9; i++) + { + array.Add(i); + } - private int bad(int i) { return i * (5 - i); } + array.AddAll(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(9)); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); + }); + } - private SortedArray array; + [TearDown] + public void Dispose() { array = null; } + } - [SetUp] - public void Init() { array = new SortedArray(new IC()); } - [Test] - public void EmptyEmpty() + [TestFixture] + public class AddSorted { - array.AddSorted(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - } + private int sqr(int i) { return i * i; } + private int bad(int i) { return i * (5 - i); } - [Test] - public void SomeEmpty() - { - for (int i = 4; i < 9; i++) - { - array.Add(i); - } + private SortedArray array; - array.AddSorted(new FunEnumerable(0, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(5)); - Assert.That(array.Check(), Is.True); - } + [SetUp] + public void Init() { array = new SortedArray(new IC()); } - [Test] - public void EmptySome() - { - array.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(4)); - Assert.Multiple(() => + [Test] + public void EmptyEmpty() { + array.AddSorted(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Is.Empty); Assert.That(array.Check(), Is.True); - Assert.That(array[0], Is.EqualTo(0)); - Assert.That(array[1], Is.EqualTo(1)); - Assert.That(array[2], Is.EqualTo(4)); - Assert.That(array[3], Is.EqualTo(9)); - }); - } + } - [Test] - public void SomeSome() - { - for (int i = 3; i < 9; i++) + [Test] + public void SomeEmpty() { - array.Add(i); - } + for (int i = 4; i < 9; i++) + { + array.Add(i); + } - array.AddSorted(new FunEnumerable(4, new Func(sqr))); - Assert.That(array, Has.Count.EqualTo(9)); - Assert.Multiple(() => - { + array.AddSorted(new FunEnumerable(0, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(5)); Assert.That(array.Check(), 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)))); - Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); - } - [TearDown] - public void Dispose() { array = null; } - } + [Test] + public void EmptySome() + { + array.AddSorted(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(4)); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array[0], Is.EqualTo(0)); + Assert.That(array[1], Is.EqualTo(1)); + Assert.That(array[2], Is.EqualTo(4)); + Assert.That(array[3], Is.EqualTo(9)); + }); + } - [TestFixture] - public class Rest - { - private SortedArray array, array2; - [SetUp] - public void Init() - { - array = new SortedArray(new IC()); - array2 = new SortedArray(new IC()); - for (int i = 0; i < 10; i++) + [Test] + public void SomeSome() { - array.Add(i); - } + for (int i = 3; i < 9; i++) + { + array.Add(i); + } - for (int i = 0; i < 10; i++) - { - array2.Add(2 * i); + array.AddSorted(new FunEnumerable(4, new Func(sqr))); + Assert.That(array, Has.Count.EqualTo(9)); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.EqualTo(new[] { 0, 1, 3, 4, 5, 6, 7, 8, 9 })); + }); } - } - - [Test] - public void RemoveAll() - { - array.RemoveAll(array2.RangeFromTo(3, 7)); - Assert.Multiple(() => - { - Assert.That(array, Has.Count.EqualTo(8)); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 8, 9 })); - }); - array.RemoveAll(array2.RangeFromTo(3, 7)); - Assert.Multiple(() => + [Test] + public void EmptyBad() { - Assert.That(array, Has.Count.EqualTo(8)); - Assert.That(array.Check(), 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(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(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); - }); - for (int i = 0; i < 10; i++) - { - array2.Add(i); + var exception = Assert.Throws(() => array.AddSorted(new FunEnumerable(9, new Func(bad)))); + Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); } - array.RemoveAll(array2.RangeFromTo(-1, 10)); - Assert.Multiple(() => - { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); - } + [TearDown] + public void Dispose() { array = null; } + } - [Test] - public void RetainAll() + [TestFixture] + public class Rest { - array.RetainAll(array2.RangeFromTo(3, 17)); - Assert.Multiple(() => - { - Assert.That(array, Has.Count.EqualTo(3)); - Assert.That(array.Check(), 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(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(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(array, Is.Empty); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } + private SortedArray array, array2; - array.RetainAll(array2.RangeFromTo(5, 5)); - Assert.Multiple(() => - { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); - for (int i = 0; i < 10; i++) - { - array.Add(i); - } - array.RetainAll(array2.RangeFromTo(15, 25)); - Assert.Multiple(() => + [SetUp] + public void Init() { - Assert.That(array, Is.Empty); - Assert.That(array.Check(), Is.True); - Assert.That(array, Is.Empty); - }); - } + array = new SortedArray(new IC()); + array2 = new SortedArray(new IC()); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + for (int i = 0; i < 10; i++) + { + array2.Add(2 * i); + } + } - [Test] - public void ContainsAll() - { - Assert.Multiple(() => + + [Test] + public void RemoveAll() { - Assert.That(array.ContainsAll(array2), Is.False); - Assert.That(array.ContainsAll(array), Is.True); - }); - array2.Clear(); - Assert.That(array.ContainsAll(array2), Is.True); - array.Clear(); - Assert.That(array.ContainsAll(array2), Is.True); - array2.Add(8); - Assert.That(array.ContainsAll(array2), Is.False); - } + array.RemoveAll(array2.RangeFromTo(3, 7)); + Assert.Multiple(() => + { + Assert.That(array, Has.Count.EqualTo(8)); + Assert.That(array.Check(), 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(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(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(array, Is.EqualTo(new[] { 0, 1, 2, 3, 5, 7, 9 })); + }); + for (int i = 0; i < 10; i++) + { + array2.Add(i); + } + array.RemoveAll(array2.RangeFromTo(-1, 10)); + Assert.Multiple(() => + { + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + } - [Test] - public void RemoveInterval() - { - array.RemoveInterval(3, 4); - Assert.Multiple(() => - { - Assert.That(array.Check(), Is.True); - Assert.That(array, Has.Count.EqualTo(6)); - Assert.That(array, Is.EqualTo(new[] { 0, 1, 2, 7, 8, 9 })); - }); - array.RemoveInterval(2, 3); - Assert.Multiple(() => + + [Test] + public void RetainAll() { - Assert.That(array.Check(), Is.True); + array.RetainAll(array2.RangeFromTo(3, 17)); + Assert.Multiple(() => + { + Assert.That(array, Has.Count.EqualTo(3)); + Assert.That(array.Check(), 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.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.Multiple(() => + { + Assert.That(array.Check(), 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(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(array, Is.Empty); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } - [Test] - public void RemoveRangeBad1() - { - Assert.Throws(() => array.RemoveInterval(-3, 8)); - } + array.RetainAll(array2.RangeFromTo(5, 5)); + Assert.Multiple(() => + { + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + for (int i = 0; i < 10; i++) + { + array.Add(i); + } + array.RetainAll(array2.RangeFromTo(15, 25)); + Assert.Multiple(() => + { + Assert.That(array, Is.Empty); + Assert.That(array.Check(), Is.True); + Assert.That(array, Is.Empty); + }); + } - [Test] - public void RemoveRangeBad2() - { - Assert.Throws(() => array.RemoveInterval(3, -8)); - } + [Test] + public void ContainsAll() + { + Assert.Multiple(() => + { + Assert.That(array.ContainsAll(array2), Is.False); + Assert.That(array.ContainsAll(array), Is.True); + }); + array2.Clear(); + Assert.That(array.ContainsAll(array2), Is.True); + array.Clear(); + Assert.That(array.ContainsAll(array2), Is.True); + array2.Add(8); + Assert.That(array.ContainsAll(array2), Is.False); + } - [Test] - public void RemoveRangeBad3() - { - Assert.Throws(() => array.RemoveInterval(3, 8)); - } + [Test] + public void RemoveInterval() + { + array.RemoveInterval(3, 4); + Assert.Multiple(() => + { + Assert.That(array.Check(), Is.True); + Assert.That(array, Has.Count.EqualTo(6)); + 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(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(array, Is.Empty); + }); + } - [Test] - public void GetRange() - { - SCG.IEnumerable e = array[3, 3]; - Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); - e = array[3, 0]; - Assert.That(e, Is.Empty); - } + [Test] + public void RemoveRangeBad1() + { + Assert.Throws(() => array.RemoveInterval(-3, 8)); + } - [Test] - public void GetRangeBad1() - { - Assert.Throws(() => { object foo = array[-3, 0]; }); - } - [Test] - public void GetRangeBad2() - { - Assert.Throws(() => { object foo = array[3, -1]; }); - } + [Test] + public void RemoveRangeBad2() + { + Assert.Throws(() => array.RemoveInterval(3, -8)); + } - [Test] - public void GetRangeBad3() - { - Assert.Throws(() => { object foo = array[3, 8]; }); - } - [TearDown] - public void Dispose() { array = null; array2 = null; } - } -} + [Test] + public void RemoveRangeBad3() + { + Assert.Throws(() => array.RemoveInterval(3, 8)); + } + [Test] + public void GetRange() + { + SCG.IEnumerable e = array[3, 3]; + Assert.That(e, Is.EqualTo(new[] { 3, 4, 5 })); + e = array[3, 0]; + Assert.That(e, Is.Empty); + } -namespace Sync -{ - [TestFixture] - public class SyncRoot - { - private SortedArray tree; - private readonly object mySyncRoot = new(); - private readonly int sz = 5000; + [Test] + public void GetRangeBad1() + { + Assert.Throws(() => { object foo = array[-3, 0]; }); + } + [Test] + public void GetRangeBad2() + { + Assert.Throws(() => { object foo = array[3, -1]; }); + } - [Test] - public void Safe() - { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(safe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(safe2)); + [Test] + public void GetRangeBad3() + { + Assert.Throws(() => { object foo = array[3, 8]; }); + } - t1.Start(); - t2.Start(); - t1.Join(); - t2.Join(); - Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); - Assert.That(tree.Check(), Is.True); + [TearDown] + public void Dispose() { array = null; array2 = null; } } + } - //[Test] - public void UnSafe() + + + namespace Sync + { + [TestFixture] + public class SyncRoot { - bool bad = false; + private SortedArray tree; + private readonly object mySyncRoot = new(); + private readonly int sz = 5000; - for (int i = 0; i < 10; i++) + + [Test] + public void Safe() { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(safe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(safe2)); t1.Start(); t2.Start(); t1.Join(); t2.Join(); - if (bad = 2 * sz + 1 != tree.Count) - { - Console.WriteLine("{0}::Unsafe(): bad at {1}", GetType(), i); - break; - } + Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); + Assert.That(tree.Check(), Is.True); } - Assert.That(bad, Is.True, "No sync problems!"); - } - - - [Test] - public void SafeUnSafe() - { - System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); - System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); - t1.Start(); - t1.Join(); - t2.Start(); - t2.Join(); - Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); - } + //[Test] + public void UnSafe() + { + bool bad = false; + for (int i = 0; i < 10; i++) + { + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); + + t1.Start(); + t2.Start(); + t1.Join(); + t2.Join(); + if (bad = 2 * sz + 1 != tree.Count) + { + Console.WriteLine("{0}::Unsafe(): bad at {1}", GetType(), i); + break; + } + } - [SetUp] - public void Init() { tree = new SortedArray(new IC()); } + Assert.That(bad, Is.True, "No sync problems!"); + } - private void unsafe1() - { - for (int i = 0; i < 2 * sz; i++) + [Test] + public void SafeUnSafe() { - tree.Add(i * 2); - } + System.Threading.Thread t1 = new(new System.Threading.ThreadStart(unsafe1)); + System.Threading.Thread t2 = new(new System.Threading.ThreadStart(unsafe2)); - for (int i = 1; i < sz; i++) - { - tree.Remove(i * 4); + t1.Start(); + t1.Join(); + t2.Start(); + t2.Join(); + Assert.That(tree, Has.Count.EqualTo(2 * sz + 1)); } - } - private void safe1() - { - for (int i = 0; i < 2 * sz; i++) + [SetUp] + public void Init() { tree = new SortedArray(new IC()); } + + + private void unsafe1() { - lock (mySyncRoot) + for (int i = 0; i < 2 * sz; i++) { tree.Add(i * 2); } - } - for (int i = 1; i < sz; i++) - { - lock (mySyncRoot) + for (int i = 1; i < sz; i++) { tree.Remove(i * 4); } } - } - private void unsafe2() - { - for (int i = 2 * sz; i > 0; i--) + private void safe1() { - tree.Add(i * 2 + 1); - } + for (int i = 0; i < 2 * sz; i++) + { + lock (mySyncRoot) + { + tree.Add(i * 2); + } + } - for (int i = sz; i > 0; i--) - { - tree.Remove(i * 4 + 1); + for (int i = 1; i < sz; i++) + { + lock (mySyncRoot) + { + tree.Remove(i * 4); + } + } } - } - private void safe2() - { - for (int i = 2 * sz; i > 0; i--) + private void unsafe2() { - lock (mySyncRoot) + for (int i = 2 * sz; i > 0; i--) { tree.Add(i * 2 + 1); } - } - for (int i = sz; i > 0; i--) - { - lock (mySyncRoot) + for (int i = sz; i > 0; i--) { tree.Remove(i * 4 + 1); } } - } - [TearDown] - public void Dispose() { tree = null; } - } + private void safe2() + { + for (int i = 2 * sz; i > 0; i--) + { + lock (mySyncRoot) + { + tree.Add(i * 2 + 1); + } + } + for (int i = sz; i > 0; i--) + { + lock (mySyncRoot) + { + tree.Remove(i * 4 + 1); + } + } + } - //[TestFixture] - public class ConcurrentQueries - { - private SortedArray tree; - private readonly int sz = 500000; + [TearDown] + public void Dispose() { tree = null; } + } - [SetUp] - public void Init() - { - tree = new SortedArray(new IC()); - for (int i = 0; i < sz; i++) - { - tree.Add(i); - } - } - private class A + //[TestFixture] + public class ConcurrentQueries { - public int count = 0; - private readonly SortedArray t; + private SortedArray tree; + private readonly int sz = 500000; - public A(SortedArray t) { this.t = t; } + [SetUp] + public void Init() + { + tree = new SortedArray(new IC()); + for (int i = 0; i < sz; i++) + { + tree.Add(i); + } + } + private class A + { + public int count = 0; + private readonly SortedArray t; - public void a(int i) { count++; } + public A(SortedArray t) { this.t = t; } - public void traverse() { t.Apply(new Action(a)); } - } + public void a(int i) { count++; } + public void traverse() { t.Apply(new Action(a)); } + } - [Test] - public void Safe() - { - A a = new(tree); - a.traverse(); - Assert.That(a.count, Is.EqualTo(sz)); - } - [Test] - public void RegrettablyUnsafe() - { - System.Threading.Thread[] t = new System.Threading.Thread[10]; - A[] a = new A[10]; - for (int i = 0; i < 10; i++) + [Test] + public void Safe() { - a[i] = new A(tree); - t[i] = new System.Threading.Thread(new System.Threading.ThreadStart(a[i].traverse)); - } + A a = new(tree); - for (int i = 0; i < 10; i++) - { - t[i].Start(); + a.traverse(); + Assert.That(a.count, Is.EqualTo(sz)); } - for (int i = 0; i < 10; i++) - { - t[i].Join(); - } - for (int i = 0; i < 10; i++) + [Test] + public void RegrettablyUnsafe() { - Assert.That(a[i].count, Is.EqualTo(sz)); + System.Threading.Thread[] t = new System.Threading.Thread[10]; + A[] a = new A[10]; + for (int i = 0; i < 10; i++) + { + a[i] = new A(tree); + t[i] = new System.Threading.Thread(new System.Threading.ThreadStart(a[i].traverse)); + } + + for (int i = 0; i < 10; i++) + { + t[i].Start(); + } + + for (int i = 0; i < 10; i++) + { + t[i].Join(); + } + + for (int i = 0; i < 10; i++) + { + Assert.That(a[i].count, Is.EqualTo(sz)); + } } - } - [TearDown] - public void Dispose() { tree = null; } + [TearDown] + public void Dispose() { tree = null; } + } } -} -namespace Hashing -{ - [TestFixture] - public class ISequenced + namespace Hashing { - private ISequenced dit, dat, dut; + [TestFixture] + public class ISequenced + { + private ISequenced dit, dat, dut; - [SetUp] - 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 ReverseIntegerComparer(), EqualityComparer.Default); - } + [SetUp] + 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 ReverseIntegerComparer(), EqualityComparer.Default); + } - [Test] - public void EmptyEmpty() - { - Assert.That(dit.SequencedEquals(dat), Is.True); - } + [Test] + public void EmptyEmpty() + { + Assert.That(dit.SequencedEquals(dat), Is.True); + } - [Test] - public void EmptyNonEmpty() - { - dit.Add(3); - Assert.Multiple(() => + [Test] + public void EmptyNonEmpty() { - Assert.That(dit.SequencedEquals(dat), Is.False); - Assert.That(dat.SequencedEquals(dit), Is.False); - }); - } + dit.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.SequencedEquals(dat), Is.False); + Assert.That(dat.SequencedEquals(dit), Is.False); + }); + } - [Test] - public void HashVal() - { - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); - dit.Add(3); - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); - dit.Add(7); - Assert.Multiple(() => + [Test] + public void HashVal() { - Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3, 7))); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); - }); - dut.Add(3); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); - dut.Add(7); - Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(7, 3))); - } + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); + dit.Add(3); + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); + dit.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3, 7))); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode())); + }); + dut.Add(3); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(3))); + dut.Add(7); + Assert.That(dut.GetSequencedHashCode(), Is.EqualTo(CHC.SequencedHashCode(7, 3))); + } - [Test] - public void Normal() - { - dit.Add(3); - dit.Add(7); - dat.Add(3); - Assert.Multiple(() => + [Test] + public void Normal() { - Assert.That(dit.SequencedEquals(dat), Is.False); - Assert.That(dat.SequencedEquals(dit), Is.False); - }); - dat.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dat), Is.True); - Assert.That(dat.SequencedEquals(dit), Is.True); - }); - } + dit.Add(3); + dit.Add(7); + dat.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.SequencedEquals(dat), Is.False); + Assert.That(dat.SequencedEquals(dit), Is.False); + }); + dat.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.SequencedEquals(dat), Is.True); + Assert.That(dat.SequencedEquals(dit), Is.True); + }); + } - [Test] - public void WrongOrder() - { - dit.Add(3); - dut.Add(3); - Assert.Multiple(() => + [Test] + public void WrongOrder() { - Assert.That(dit.SequencedEquals(dut), Is.True); - Assert.That(dut.SequencedEquals(dit), Is.True); - }); - dit.Add(7); - dut.Add(7); - Assert.Multiple(() => - { - Assert.That(dit.SequencedEquals(dut), Is.False); - Assert.That(dut.SequencedEquals(dit), Is.False); - }); - } + dit.Add(3); + dut.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.SequencedEquals(dut), Is.True); + Assert.That(dut.SequencedEquals(dit), Is.True); + }); + dit.Add(7); + dut.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.SequencedEquals(dut), Is.False); + Assert.That(dut.SequencedEquals(dit), Is.False); + }); + } - [Test] - public void Reflexive() - { - Assert.That(dit.SequencedEquals(dit), Is.True); - dit.Add(3); - Assert.That(dit.SequencedEquals(dit), Is.True); - dit.Add(7); - Assert.That(dit.SequencedEquals(dit), Is.True); - } + [Test] + public void Reflexive() + { + Assert.That(dit.SequencedEquals(dit), Is.True); + dit.Add(3); + Assert.That(dit.SequencedEquals(dit), Is.True); + dit.Add(7); + Assert.That(dit.SequencedEquals(dit), Is.True); + } - [TearDown] - public void Dispose() - { - dit = null; - dat = null; - dut = null; + [TearDown] + public void Dispose() + { + dit = null; + dat = null; + dut = null; + } } - } - - [TestFixture] - public class IEditableCollection - { - private ICollection dit, dat, dut; - - [SetUp] - public void Init() + [TestFixture] + public class IEditableCollection { - dit = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); - dat = new SortedArray(8, SCG.Comparer.Default, EqualityComparer.Default); - dut = new SortedArray(8, new ReverseIntegerComparer(), EqualityComparer.Default); - } + private ICollection dit, dat, dut; - [Test] - public void EmptyEmpty() - { - Assert.That(dit.UnsequencedEquals(dat), Is.True); - } + [SetUp] + 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 ReverseIntegerComparer(), EqualityComparer.Default); + } - [Test] - public void EmptyNonEmpty() - { - dit.Add(3); - Assert.Multiple(() => + [Test] + public void EmptyEmpty() { - Assert.That(dit.UnsequencedEquals(dat), Is.False); - Assert.That(dat.UnsequencedEquals(dit), Is.False); - }); - } + Assert.That(dit.UnsequencedEquals(dat), Is.True); + } - [Test] - public void HashVal() - { - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); - dit.Add(3); - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); - dit.Add(7); - Assert.Multiple(() => + [Test] + public void EmptyNonEmpty() { - Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3, 7))); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); - }); - dut.Add(3); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); - dut.Add(7); - Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(7, 3))); - } + dit.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dat), Is.False); + Assert.That(dat.UnsequencedEquals(dit), Is.False); + }); + } - [Test] - public void Normal() - { - dit.Add(3); - dit.Add(7); - dat.Add(3); - Assert.Multiple(() => - { - Assert.That(dit.UnsequencedEquals(dat), Is.False); - Assert.That(dat.UnsequencedEquals(dit), Is.False); - }); - dat.Add(7); - Assert.Multiple(() => + [Test] + public void HashVal() { - Assert.That(dit.UnsequencedEquals(dat), Is.True); - Assert.That(dat.UnsequencedEquals(dit), Is.True); - }); - } + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); + dit.Add(3); + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); + dit.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3, 7))); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode())); + }); + dut.Add(3); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(3))); + dut.Add(7); + Assert.That(dut.GetUnsequencedHashCode(), Is.EqualTo(CHC.UnsequencedHashCode(7, 3))); + } - [Test] - public void WrongOrder() - { - dit.Add(3); - dut.Add(3); - Assert.Multiple(() => + [Test] + public void Normal() { - Assert.That(dit.UnsequencedEquals(dut), Is.True); - Assert.That(dut.UnsequencedEquals(dit), Is.True); - }); - dit.Add(7); - dut.Add(7); - Assert.Multiple(() => + dit.Add(3); + dit.Add(7); + dat.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dat), Is.False); + Assert.That(dat.UnsequencedEquals(dit), Is.False); + }); + dat.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dat), Is.True); + Assert.That(dat.UnsequencedEquals(dit), Is.True); + }); + } + + + [Test] + public void WrongOrder() { - Assert.That(dit.UnsequencedEquals(dut), Is.True); - Assert.That(dut.UnsequencedEquals(dit), Is.True); - }); - } + dit.Add(3); + dut.Add(3); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dut), Is.True); + Assert.That(dut.UnsequencedEquals(dit), Is.True); + }); + dit.Add(7); + dut.Add(7); + Assert.Multiple(() => + { + Assert.That(dit.UnsequencedEquals(dut), Is.True); + Assert.That(dut.UnsequencedEquals(dit), Is.True); + }); + } - [Test] - public void Reflexive() - { - Assert.That(dit.UnsequencedEquals(dit), Is.True); - dit.Add(3); - Assert.That(dit.UnsequencedEquals(dit), Is.True); - dit.Add(7); - Assert.That(dit.UnsequencedEquals(dit), Is.True); - } + [Test] + public void Reflexive() + { + Assert.That(dit.UnsequencedEquals(dit), Is.True); + dit.Add(3); + Assert.That(dit.UnsequencedEquals(dit), Is.True); + dit.Add(7); + Assert.That(dit.UnsequencedEquals(dit), Is.True); + } - [TearDown] - public void Dispose() - { - dit = null; - dat = null; - dut = null; + [TearDown] + public void Dispose() + { + dit = null; + dat = null; + dut = null; + } } - } -} + } } \ No newline at end of file diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 77be2703..e32c3593 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -2201,7 +2201,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!"); }); } @@ -2217,14 +2217,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!"); }); } @@ -2247,7 +2247,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 @@ -2256,13 +2256,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 @@ -2272,26 +2272,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); @@ -2301,7 +2301,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); @@ -2310,7 +2310,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++) @@ -2326,7 +2326,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); @@ -2351,14 +2351,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!"); } @@ -2371,21 +2371,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!"); }); @@ -2394,7 +2394,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 @@ -2403,7 +2403,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++) { @@ -2413,7 +2413,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!"); }); @@ -2422,7 +2422,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!"); }); } @@ -2439,7 +2439,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); }); } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index f7b59aed..895dc617 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -1807,7 +1807,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!"); }); } @@ -1823,14 +1823,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!"); }); } @@ -1852,14 +1852,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 @@ -1869,26 +1869,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); @@ -1898,7 +1898,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); @@ -1907,7 +1907,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++) @@ -1923,7 +1923,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); @@ -1948,14 +1948,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!"); } @@ -1968,21 +1968,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!"); }); @@ -1992,7 +1992,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++) { @@ -2002,7 +2002,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!"); }); @@ -2011,12 +2011,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() { @@ -2028,7 +2027,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); }); } From f1cd82dfeb234cfa2e7adf139087c92be50c3a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 16:41:30 +0200 Subject: [PATCH 12/14] more --- C5.Tests/Arrays/ArrayListTest.cs | 7 +++--- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 22 +++++++------------ C5.Tests/LinkedLists/LinkedListTest.cs | 23 +++++++------------- C5.Tests/SupportClasses.cs | 2 +- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index 9ff39c06..593c4fb2 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -2395,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); @@ -2403,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 })); }); } diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index a4c90858..42678cf8 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -1639,7 +1639,7 @@ public void Shuffle() 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); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 6, 7 }), "Contents " + i); } } } @@ -1718,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); @@ -1738,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() { @@ -1757,13 +1752,12 @@ public void Backwards() Assert.Multiple(() => { Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); - 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[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() { diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index 7fc4feef..5558b32b 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -1638,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() { @@ -1662,13 +1660,12 @@ public void Shuffle() 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); + Assert.That(lst2, Is.EqualTo(new[] { 3, 5, 5, 6, 7 }), "Contents " + i); } } } } - namespace IStackQueue { [TestFixture] @@ -1752,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); @@ -1772,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 })); }); } @@ -1798,9 +1791,9 @@ public void Backwards() Assert.Multiple(() => { Assert.That(lst.Backwards(), Is.EqualTo(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })); - 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[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 })); }); } diff --git a/C5.Tests/SupportClasses.cs b/C5.Tests/SupportClasses.cs index 438ddae9..00494d72 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -11,7 +11,7 @@ internal class TenEqualityComparer : SCG.IEqualityComparer, SCG.IComparer new(); + public static TenEqualityComparer Instance { get; } = new(); public int GetHashCode(int item) { return (item / 10).GetHashCode(); } From c21ef33405fb1fdcaef10df347eee06ac51983a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 17:07:01 +0200 Subject: [PATCH 13/14] more --- C5.Tests/Trees/Bag.cs | 185 +++++++++++-------------- C5.Tests/Trees/RedBlackTreeSetTests.cs | 107 +++++++------- C5.Tests/WrappersTest.cs | 12 +- 3 files changed, 138 insertions(+), 166 deletions(-) diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index e32c3593..07d4fe9b 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -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,14 +646,11 @@ public void Dispose() } } - - [TestFixture] public class BagItf { private TreeBag tree; - [SetUp] public void Init() { @@ -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()); } - 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() { @@ -775,7 +762,6 @@ public void Add() Assert.That(tree, Is.EqualTo(new[] { 17, 17, 18, 18 })); } - [TearDown] public void Dispose() { @@ -1926,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); @@ -1969,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() { @@ -2514,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); @@ -2552,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); }); @@ -3322,22 +3301,22 @@ 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 })); }); } @@ -3362,21 +3341,21 @@ 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 })); }); } diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index 895dc617..c0aaa22e 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -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 })); }); } @@ -1541,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); @@ -1586,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); } @@ -2109,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); @@ -2147,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); }); diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index a4993a49..a98e48a2 100644 --- a/C5.Tests/WrappersTest.cs +++ b/C5.Tests/WrappersTest.cs @@ -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; } @@ -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(() => @@ -812,7 +810,7 @@ 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("[ ... ]")); Assert.That(outerwrapped, Is.EqualTo(wrapped.Underlying)); Assert.That(wrapped.UniqueItems(), Is.EquivalentTo(new[] { 4, 5, 6 })); From 19611e29578390053e44e398e6ec646371a152b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Lystr=C3=B8m?= Date: Sat, 8 Jun 2024 17:22:25 +0200 Subject: [PATCH 14/14] more --- C5.Tests/Arrays/ArrayListTest.cs | 12 ++-- C5.Tests/Arrays/HashedArrayListTest.cs | 10 +-- C5.Tests/Arrays/SortedArrayTests.cs | 60 +++++++++--------- C5.Tests/LinkedLists/HashedLinkedListTest.cs | 10 +-- C5.Tests/LinkedLists/LinkedListTest.cs | 12 ++-- C5.Tests/Sorting.cs | 16 ++--- C5.Tests/SupportClasses.cs | 44 ++----------- C5.Tests/Trees/Bag.cs | 66 ++++++++++---------- C5.Tests/Trees/RedBlackTreeSetTests.cs | 66 ++++++++++---------- C5.Tests/WrappersTest.cs | 4 +- 10 files changed, 134 insertions(+), 166 deletions(-) diff --git a/C5.Tests/Arrays/ArrayListTest.cs b/C5.Tests/Arrays/ArrayListTest.cs index 593c4fb2..fbe3e19c 100644 --- a/C5.Tests/Arrays/ArrayListTest.cs +++ b/C5.Tests/Arrays/ArrayListTest.cs @@ -2197,12 +2197,12 @@ 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(lst.IsSorted(new IntegerComparer()), Is.True); Assert.That(lst, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -2212,7 +2212,7 @@ public void Sort() public void Stability() { IList> lst2 = new ArrayList>(); - 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")); @@ -2897,8 +2897,8 @@ 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(() => { diff --git a/C5.Tests/Arrays/HashedArrayListTest.cs b/C5.Tests/Arrays/HashedArrayListTest.cs index 7cd9fd5e..f29f2753 100644 --- a/C5.Tests/Arrays/HashedArrayListTest.cs +++ b/C5.Tests/Arrays/HashedArrayListTest.cs @@ -2187,12 +2187,12 @@ 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(lst.IsSorted(new IntegerComparer()), Is.True); Assert.That(lst, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } @@ -2710,8 +2710,8 @@ 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(() => { diff --git a/C5.Tests/Arrays/SortedArrayTests.cs b/C5.Tests/Arrays/SortedArrayTests.cs index 57268605..c7eb9260 100644 --- a/C5.Tests/Arrays/SortedArrayTests.cs +++ b/C5.Tests/Arrays/SortedArrayTests.cs @@ -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++) { @@ -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] @@ -383,7 +383,7 @@ public class FindOrAdd [SetUp] public void Init() { - bag = new SortedArray>(new KeyValuePairComparer(new IC())); + bag = new SortedArray>(new KeyValuePairComparer(new IntegerComparer())); } @@ -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++) { @@ -593,7 +593,7 @@ public class Combined [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 SCG.KeyValuePair(i, i + 30)); @@ -748,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); @@ -959,7 +959,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); } @@ -1222,7 +1222,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new SortedArray(new IC()); + tree = new SortedArray(new IntegerComparer()); } @@ -1301,7 +1301,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - array = new SortedArray(new IC()); + array = new SortedArray(new IntegerComparer()); } @@ -1462,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); @@ -1528,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); @@ -1627,7 +1627,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); array = new SortedArray(ic); } @@ -1863,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)); @@ -1960,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); } @@ -1980,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); } @@ -1989,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)); @@ -2010,7 +2010,7 @@ 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(() => { @@ -2038,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); } @@ -2059,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); } @@ -2069,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(() => { @@ -2091,7 +2091,7 @@ 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(() => { @@ -2103,7 +2103,7 @@ public void SomeSome() [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")); } @@ -2121,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); @@ -2405,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() @@ -2492,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); diff --git a/C5.Tests/LinkedLists/HashedLinkedListTest.cs b/C5.Tests/LinkedLists/HashedLinkedListTest.cs index 42678cf8..11696931 100644 --- a/C5.Tests/LinkedLists/HashedLinkedListTest.cs +++ b/C5.Tests/LinkedLists/HashedLinkedListTest.cs @@ -1603,13 +1603,13 @@ 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(lst.IsSorted(new IntegerComparer()), Is.True); Assert.That(lst, Is.EqualTo(new[] { 3, 5, 6, 7, 55 })); }); } @@ -2198,8 +2198,8 @@ 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(() => { diff --git a/C5.Tests/LinkedLists/LinkedListTest.cs b/C5.Tests/LinkedLists/LinkedListTest.cs index 5558b32b..d95e3c25 100644 --- a/C5.Tests/LinkedLists/LinkedListTest.cs +++ b/C5.Tests/LinkedLists/LinkedListTest.cs @@ -1563,13 +1563,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.Check(), Is.True); Assert.That(lst.IsSorted(), Is.True); - Assert.That(lst.IsSorted(new IC()), Is.True); + Assert.That(lst.IsSorted(new IntegerComparer()), Is.True); Assert.That(lst, Is.EqualTo(new[] { 3, 5, 5, 6, 7 })); }); } @@ -1579,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")); @@ -2244,8 +2244,8 @@ 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(() => { diff --git a/C5.Tests/Sorting.cs b/C5.Tests/Sorting.cs index 310ff8fb..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]; @@ -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]; @@ -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++) @@ -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++) diff --git a/C5.Tests/SupportClasses.cs b/C5.Tests/SupportClasses.cs index 00494d72..ec4b2514 100644 --- a/C5.Tests/SupportClasses.cs +++ b/C5.Tests/SupportClasses.cs @@ -20,50 +20,19 @@ 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; } - public int I { get; set; } + public IntegerComparer() { } - public IC() { } - - 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; - } } internal class ReverseIntegerComparer : SCG.IComparer @@ -71,12 +40,12 @@ internal class ReverseIntegerComparer : SCG.IComparer 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; } @@ -89,7 +58,6 @@ public SCG.IEnumerator GetEnumerator() } } - #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() diff --git a/C5.Tests/Trees/Bag.cs b/C5.Tests/Trees/Bag.cs index 07d4fe9b..07f58738 100644 --- a/C5.Tests/Trees/Bag.cs +++ b/C5.Tests/Trees/Bag.cs @@ -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)); @@ -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())); } @@ -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++) { @@ -654,7 +654,7 @@ public class BagItf [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); for (int i = 10; i < 20; i++) { tree.Add(i); @@ -691,7 +691,7 @@ public class Div [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } private void loadup() @@ -981,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); @@ -1064,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++) { @@ -1138,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); @@ -1371,7 +1371,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } private void loadup() @@ -1522,7 +1522,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } private void loadup() @@ -1602,7 +1602,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } @@ -1766,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); @@ -1832,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); @@ -1897,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++) { @@ -2094,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++) { @@ -2456,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++) { @@ -2587,7 +2587,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeBag(ic); } @@ -2842,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)); @@ -2939,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); } @@ -2959,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); } @@ -2968,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(() => { @@ -2991,7 +2991,7 @@ 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(() => { @@ -3015,13 +3015,13 @@ public class AddSorted [SetUp] public void Init() { - tree = new TreeBag(new IC()); + tree = new TreeBag(new IntegerComparer()); } [Test] public void EmptyEmpty() { - tree.AddSorted(new FunEnumerable(0, i => i * i)); + tree.AddSorted(new FuncEnumerable(0, i => i * i)); Assert.That(tree, Is.Empty); Assert.That(tree.Check(), Is.True); } @@ -3034,7 +3034,7 @@ public void SomeEmpty() tree.Add(i); } - tree.AddSorted(new FunEnumerable(0, i => i * i)); + tree.AddSorted(new FuncEnumerable(0, i => i * i)); Assert.That(tree, Has.Count.EqualTo(5)); Assert.That(tree.Check(), Is.True); } @@ -3042,7 +3042,7 @@ public void SomeEmpty() [Test] public void EmptySome() { - tree.AddSorted(new FunEnumerable(4, i => i * i)); + tree.AddSorted(new FuncEnumerable(4, i => i * i)); Assert.Multiple(() => { @@ -3058,7 +3058,7 @@ public void EmptySome() [Test] public void EmptySome2() { - tree.AddSorted(new FunEnumerable(4, i => i / 3)); + tree.AddSorted(new FuncEnumerable(4, i => i / 3)); Assert.Multiple(() => { @@ -3080,7 +3080,7 @@ public void SomeSome() } tree.Add(1); - tree.AddSorted(new FunEnumerable(4, i => i * i)); + tree.AddSorted(new FuncEnumerable(4, i => i * i)); Assert.Multiple(() => { @@ -3095,7 +3095,7 @@ public void EmptyBad() { static int bad(int i) { return i * (5 - i); } - var exception = Assert.Throws(() => tree.AddSorted(new FunEnumerable(9, bad))); + var exception = Assert.Throws(() => tree.AddSorted(new FuncEnumerable(9, bad))); Assert.That(exception.Message, Is.EqualTo("Argument not sorted")); } @@ -3111,8 +3111,8 @@ public class Rest [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); diff --git a/C5.Tests/Trees/RedBlackTreeSetTests.cs b/C5.Tests/Trees/RedBlackTreeSetTests.cs index c0aaa22e..4a3a27fa 100644 --- a/C5.Tests/Trees/RedBlackTreeSetTests.cs +++ b/C5.Tests/Trees/RedBlackTreeSetTests.cs @@ -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++) { @@ -374,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); @@ -414,7 +414,7 @@ public class Div [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } @@ -507,7 +507,7 @@ public class FindOrAdd [SetUp] public void Init() { - bag = new TreeSet>(new KeyValuePairComparer(new IC())); + bag = new TreeSet>(new KeyValuePairComparer(new IntegerComparer())); } @@ -637,7 +637,7 @@ public class ArrayTest [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++) { @@ -704,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); @@ -914,7 +914,7 @@ public class PredecessorStructure [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } @@ -1175,7 +1175,7 @@ public class PriorityQueue [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } private void loadup() @@ -1244,7 +1244,7 @@ public class IndexingAndCounting [SetUp] public void Init() { - tree = new TreeSet(new IC()); + tree = new TreeSet(new IntegerComparer()); } private void populate() @@ -1398,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); @@ -1461,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); @@ -1526,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++) { @@ -1779,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++) { @@ -2068,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++) { @@ -2198,7 +2198,7 @@ public class Simple [SetUp] public void Init() { - ic = new IC(); + ic = new IntegerComparer(); tree = new TreeSet(ic); } @@ -2440,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)); @@ -2536,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); } @@ -2556,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); } @@ -2565,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(() => { @@ -2586,7 +2586,7 @@ 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(() => { @@ -2614,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); } @@ -2635,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); } @@ -2645,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(() => { @@ -2667,7 +2667,7 @@ 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(() => { @@ -2679,7 +2679,7 @@ public void SomeSome() [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")); } @@ -2697,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); @@ -2989,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() @@ -3076,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); diff --git a/C5.Tests/WrappersTest.cs b/C5.Tests/WrappersTest.cs index a98e48a2..8561bfca 100644 --- a/C5.Tests/WrappersTest.cs +++ b/C5.Tests/WrappersTest.cs @@ -816,9 +816,9 @@ public void View() 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(wrapped.Span(outerwrapped.ViewOf(7)), Is.EquivalentTo(new[] { 4, 5, 6, 7 })); });