|
| 1 | +using System; |
1 | 2 | using System.Globalization; |
2 | 3 | using NUnit.Framework; |
3 | 4 | using Unity.Collections; |
@@ -118,6 +119,35 @@ public void Utilities_IndexOfReference__IsUsingReferenceEqualsAndConstrainedBySt |
118 | 119 | Assert.AreEqual(2, arr.IndexOfReference(arr[2], 1, 3)); |
119 | 120 | } |
120 | 121 |
|
| 122 | + [Test] |
| 123 | + [Category("Utilities")] |
| 124 | + public void Utilities_HaveDuplicateReferences_DetectsDuplicatesInFullRange() |
| 125 | + { |
| 126 | + var withDup = new object[] { new object(), new object(), new object() }; |
| 127 | + withDup[2] = withDup[0]; // duplicate at 0 and 2 |
| 128 | + Assert.That(withDup.HaveDuplicateReferences(0, 3), Is.True); |
| 129 | + |
| 130 | + var noDup = new object[] { new object(), new object(), new object() }; |
| 131 | + Assert.That(noDup.HaveDuplicateReferences(0, 3), Is.False); |
| 132 | + |
| 133 | + // Regression test for ISXB-1792: inner loop was "n < count - i" so later pairs were never checked |
| 134 | + var dupAtEnd = new object[] { new object(), new object(), new object(), new object() }; |
| 135 | + dupAtEnd[3] = dupAtEnd[2]; // duplicate at 2 and 3 |
| 136 | + Assert.That(dupAtEnd.HaveDuplicateReferences(0, 4), Is.True); |
| 137 | + } |
| 138 | + |
| 139 | + [Test] |
| 140 | + [Category("Utilities")] |
| 141 | + public void Utilities_MergeWithComparer_UsesComparerToDeduplicate() |
| 142 | + { |
| 143 | + // Regression test for ISXB-1790: Merge(IEqualityComparer) was calling comparer.Equals(secondValue) |
| 144 | + // instead of comparer.Equals(x, secondValue), so it compared against the comparer instance. |
| 145 | + var first = new[] { "a", "b" }; |
| 146 | + var second = new[] { "A", "c" }; // "A" equals "a" with case-insensitive comparer |
| 147 | + var merged = ArrayHelpers.Merge(first, second, StringComparer.OrdinalIgnoreCase); |
| 148 | + Assert.That(merged, Is.EqualTo(new[] { "a", "b", "c" })); |
| 149 | + } |
| 150 | + |
121 | 151 | [Test] |
122 | 152 | [Category("Utilities")] |
123 | 153 | public void Utilities_IndexOfPredicate__IsUsingPredicateForEqualityAndConstraintedByStartIndexAndCount() |
|
0 commit comments