Skip to content

Commit 215c6fd

Browse files
committed
Added public overload (array, seed) and private overload (array, items, seed) on RecursiveShuffler.cs.
1 parent 00b9db0 commit 215c6fd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Algorithms.Tests/Shufflers/RecursiveShufflerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void ArrayShuffled_NewArraySameSize(
1818
var (correctArray, testArray) = RandomHelper.GetArrays(n);
1919

2020
// Act
21-
shuffler.Shuffle(testArray, testArray.Length - 1);
21+
shuffler.Shuffle(testArray);
2222

2323
// Assert
2424
testArray.Length.Should().Be(correctArray.Length);
@@ -34,7 +34,7 @@ public static void ArrayShuffled_NewArraySameValues(
3434
var (correctArray, testArray) = RandomHelper.GetArrays(n);
3535

3636
// Act
37-
shuffler.Shuffle(testArray, testArray.Length - 1);
37+
shuffler.Shuffle(testArray);
3838

3939
// Assert
4040
testArray.Should().BeEquivalentTo(correctArray);
@@ -50,8 +50,8 @@ public static void ArrayShuffled_NewArraySameShuffle(
5050
var (correctArray, testArray) = RandomHelper.GetArrays(n);
5151

5252
// Act
53-
shuffler.Shuffle(testArray, testArray.Length - 1, seed);
54-
shuffler.Shuffle(correctArray, correctArray.Length - 1, seed);
53+
shuffler.Shuffle(testArray, seed);
54+
shuffler.Shuffle(correctArray, seed);
5555

5656
// Assert
5757
correctArray.Should().BeEquivalentTo(testArray, options => options.WithStrictOrdering());

Algorithms/Shufflers/RecursiveShuffler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ namespace Algorithms.Shufflers
88
/// for educational purposes due to stack depth limits.
99
/// </summary>
1010
/// <typeparam name="T">Type array input.</typeparam>
11-
public class RecursiveShuffler<T>
11+
public class RecursiveShuffler<T> : IShuffler<T>
1212
{
13+
/// <summary>
14+
/// This is the public overload method that calls the private overload method.
15+
/// </summary>
16+
/// <param name="array">Array to shuffle.</param>
17+
/// <param name="seed">Random generator seed. Used to repeat the shuffle.</param>
18+
public void Shuffle(T[] array, int? seed = null)
19+
{
20+
Shuffle(array, array.Length - 1, seed);
21+
}
22+
1323
/// <summary>
1424
/// First, it will check the length of the array on the base case.
1525
/// Next, if there's still items left, it will shuffle the sub-array.
@@ -19,9 +29,9 @@ public class RecursiveShuffler<T>
1929
/// <param name="array">Array to shuffle.</param>
2030
/// <param name="items">Number of items in the array.</param>
2131
/// <param name="seed">Random generator seed. Used to repeat the shuffle.</param>
22-
public void Shuffle(T[] array, int items, int? seed = null)
32+
private void Shuffle(T[] array, int items, int? seed)
2333
{
24-
if(items <= 0)
34+
if (items <= 0)
2535
{
2636
return;
2737
}

0 commit comments

Comments
 (0)