Skip to content

Commit

Permalink
Improved quality of test to cover all branches
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Oct 16, 2023
1 parent 5a9fe75 commit 0133f99
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/DotNext.Tests/SpanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,11 @@ public static void SplitSpanByLength()
[Fact]
public static void SwapElements()
{
Span<int> array = stackalloc int[] { 1, 2, 3, 4, 5, 6 };
array[0..3].Swap(array[3..6]);
Equal(new int[] { 4, 5, 6, 1, 2, 3 }, array.ToArray());
Span<byte> expected = RandomBytes(MemoryRental<byte>.StackallocThreshold * 4 + 2);
Span<byte> actual = expected.ToArray();
var midpoint = actual.Length >> 1;
actual.Slice(0, midpoint).Swap(actual.Slice(midpoint));
Equal(expected.Slice(midpoint).ToArray(), actual.Slice(0, midpoint).ToArray());
Equal(expected.Slice(0, midpoint).ToArray(), actual.Slice(midpoint).ToArray());
}
}

0 comments on commit 0133f99

Please sign in to comment.