Skip to content

Commit 6bb9e5a

Browse files
committed
Improved some unit tests
1 parent 7a65a29 commit 6bb9e5a

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ReadOnlySpanExtensions.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,30 +272,42 @@ public void Test_ReadOnlySpanExtensions_Tokenize_CommaWithMissingValues()
272272
[TestMethod]
273273
public void Test_ReadOnlySpanExtensions_CopyTo_RefEnumerable()
274274
{
275-
int[,] array1 = new int[4, 5];
275+
int[,] array = new int[4, 5];
276276

277-
ReadOnlySpan<int> values = new[] { 10, 20, 30, 40, 50 };
277+
ReadOnlySpan<int>
278+
values1 = new[] { 10, 20, 30, 40, 50 },
279+
values2 = new[] { 11, 22, 33, 44, 55 };
278280

279281
// Copy a span to a target row and column with valid lengths
280-
values.CopyTo(array1.GetRow(0));
281-
values.Slice(0, 4).CopyTo(array1.GetColumn(1));
282+
values1.CopyTo(array.GetRow(0));
283+
values2.Slice(0, 4).CopyTo(array.GetColumn(1));
284+
285+
int[,] result =
286+
{
287+
{ 10, 11, 30, 40, 50 },
288+
{ 0, 22, 0, 0, 0 },
289+
{ 0, 33, 0, 0, 0 },
290+
{ 0, 44, 0, 0, 0 }
291+
};
292+
293+
CollectionAssert.AreEqual(array, result);
282294

283295
// Try to copy to a valid row and an invalid column (too short for the source span)
284-
bool shouldBeTrue = values.TryCopyTo(array1.GetRow(2));
285-
bool shouldBeFalse = values.TryCopyTo(array1.GetColumn(1));
296+
bool shouldBeTrue = values1.TryCopyTo(array.GetRow(2));
297+
bool shouldBeFalse = values2.TryCopyTo(array.GetColumn(3));
286298

287299
Assert.IsTrue(shouldBeTrue);
288300
Assert.IsFalse(shouldBeFalse);
289301

290-
int[,] result =
302+
result = new[,]
291303
{
292-
{ 10, 10, 30, 40, 50 },
293-
{ 0, 20, 0, 0, 0 },
304+
{ 10, 11, 30, 40, 50 },
305+
{ 0, 22, 0, 0, 0 },
294306
{ 10, 20, 30, 40, 50 },
295-
{ 0, 40, 0, 0, 0 }
307+
{ 0, 44, 0, 0, 0 }
296308
};
297309

298-
CollectionAssert.AreEqual(array1, result);
310+
CollectionAssert.AreEqual(array, result);
299311
}
300312
}
301313
}

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_SpanExtensions.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,30 +173,42 @@ public void Test_SpanExtensions_Enumerate_Empty()
173173
[TestMethod]
174174
public void Test_SpanExtensions_CopyTo_RefEnumerable()
175175
{
176-
int[,] array1 = new int[4, 5];
176+
int[,] array = new int[4, 5];
177177

178-
int[] values = { 10, 20, 30, 40, 50 };
178+
int[]
179+
values1 = { 10, 20, 30, 40, 50 },
180+
values2 = { 11, 22, 33, 44, 55 };
179181

180182
// Copy a span to a target row and column with valid lengths
181-
values.AsSpan().CopyTo(array1.GetRow(0));
182-
values.AsSpan(0, 4).CopyTo(array1.GetColumn(1));
183+
values1.AsSpan().CopyTo(array.GetRow(0));
184+
values2.AsSpan(0, 4).CopyTo(array.GetColumn(1));
185+
186+
int[,] result =
187+
{
188+
{ 10, 11, 30, 40, 50 },
189+
{ 0, 22, 0, 0, 0 },
190+
{ 0, 33, 0, 0, 0 },
191+
{ 0, 44, 0, 0, 0 }
192+
};
193+
194+
CollectionAssert.AreEqual(array, result);
183195

184196
// Try to copy to a valid row and an invalid column (too short for the source span)
185-
bool shouldBeTrue = values.AsSpan().TryCopyTo(array1.GetRow(2));
186-
bool shouldBeFalse = values.AsSpan().TryCopyTo(array1.GetColumn(1));
197+
bool shouldBeTrue = values1.AsSpan().TryCopyTo(array.GetRow(2));
198+
bool shouldBeFalse = values2.AsSpan().TryCopyTo(array.GetColumn(3));
187199

188200
Assert.IsTrue(shouldBeTrue);
189201
Assert.IsFalse(shouldBeFalse);
190202

191-
int[,] result =
203+
result = new[,]
192204
{
193-
{ 10, 10, 30, 40, 50 },
194-
{ 0, 20, 0, 0, 0 },
205+
{ 10, 11, 30, 40, 50 },
206+
{ 0, 22, 0, 0, 0 },
195207
{ 10, 20, 30, 40, 50 },
196-
{ 0, 40, 0, 0, 0 }
208+
{ 0, 44, 0, 0, 0 }
197209
};
198210

199-
CollectionAssert.AreEqual(array1, result);
211+
CollectionAssert.AreEqual(array, result);
200212
}
201213
}
202214
}

0 commit comments

Comments
 (0)