|
| 1 | +using Algorithms.Shufflers; |
| 2 | +using Algorithms.Tests.Helpers; |
| 3 | +using FluentAssertions; |
| 4 | +using NUnit.Framework; |
| 5 | +using System; |
| 6 | + |
| 7 | +namespace Algorithms.Tests.Shufflers |
| 8 | +{ |
| 9 | + public static class LINQShufflerTests |
| 10 | + { |
| 11 | + [Test] |
| 12 | + public static void ArrayShuffled_NewArraySameSize( |
| 13 | + [Random(10, 1000, 100, Distinct = true)] |
| 14 | + int n) |
| 15 | + { |
| 16 | + // Arrange |
| 17 | + var shuffler = new LINQShuffler<int>(); |
| 18 | + var (correctArray, testArray) = RandomHelper.GetArrays(n); |
| 19 | + |
| 20 | + // Act |
| 21 | + shuffler.Shuffle(testArray); |
| 22 | + |
| 23 | + // Assert |
| 24 | + testArray.Length.Should().Be(correctArray.Length); |
| 25 | + } |
| 26 | + |
| 27 | + [Test] |
| 28 | + public static void ArrayShuffled_NewArraySameValues( |
| 29 | + [Random(10, 1000, 100, Distinct = true)] |
| 30 | + int n) |
| 31 | + { |
| 32 | + // Arrange |
| 33 | + var shuffler = new LINQShuffler<int>(); |
| 34 | + var (correctArray, testArray) = RandomHelper.GetArrays(n); |
| 35 | + |
| 36 | + // Act |
| 37 | + shuffler.Shuffle(testArray); |
| 38 | + |
| 39 | + // Assert |
| 40 | + testArray.Should().BeEquivalentTo(correctArray); |
| 41 | + } |
| 42 | + |
| 43 | + [Test] |
| 44 | + public static void ArrayShuffled_NewArraySameShuffle( |
| 45 | + [Random(0, 1000, 2, Distinct = true)] int n, |
| 46 | + [Random(1000, 10000, 5, Distinct = true)] int seed) |
| 47 | + { |
| 48 | + // Arrange |
| 49 | + var shuffle = new LINQShuffler<int>(); |
| 50 | + var (correctArray, testArray) = RandomHelper.GetArrays(n); |
| 51 | + |
| 52 | + // Act |
| 53 | + shuffle.Shuffle(testArray, seed); |
| 54 | + shuffle.Shuffle(correctArray, seed); |
| 55 | + |
| 56 | + // Assert |
| 57 | + correctArray.Should().BeEquivalentTo(testArray, options => options.WithStrictOrdering()); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments