File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Algorithms.Tests/Shufflers Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static void ArrayShuffled_NewArraySameSize(
18
18
var ( correctArray , testArray ) = RandomHelper . GetArrays ( n ) ;
19
19
20
20
// Act
21
- shuffler . Shuffle ( testArray , testArray . Length - 1 ) ;
21
+ shuffler . Shuffle ( testArray ) ;
22
22
23
23
// Assert
24
24
testArray . Length . Should ( ) . Be ( correctArray . Length ) ;
@@ -34,7 +34,7 @@ public static void ArrayShuffled_NewArraySameValues(
34
34
var ( correctArray , testArray ) = RandomHelper . GetArrays ( n ) ;
35
35
36
36
// Act
37
- shuffler . Shuffle ( testArray , testArray . Length - 1 ) ;
37
+ shuffler . Shuffle ( testArray ) ;
38
38
39
39
// Assert
40
40
testArray . Should ( ) . BeEquivalentTo ( correctArray ) ;
@@ -50,8 +50,8 @@ public static void ArrayShuffled_NewArraySameShuffle(
50
50
var ( correctArray , testArray ) = RandomHelper . GetArrays ( n ) ;
51
51
52
52
// 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 ) ;
55
55
56
56
// Assert
57
57
correctArray . Should ( ) . BeEquivalentTo ( testArray , options => options . WithStrictOrdering ( ) ) ;
Original file line number Diff line number Diff line change @@ -8,8 +8,18 @@ namespace Algorithms.Shufflers
8
8
/// for educational purposes due to stack depth limits.
9
9
/// </summary>
10
10
/// <typeparam name="T">Type array input.</typeparam>
11
- public class RecursiveShuffler < T >
11
+ public class RecursiveShuffler < T > : IShuffler < T >
12
12
{
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
+
13
23
/// <summary>
14
24
/// First, it will check the length of the array on the base case.
15
25
/// Next, if there's still items left, it will shuffle the sub-array.
@@ -19,9 +29,9 @@ public class RecursiveShuffler<T>
19
29
/// <param name="array">Array to shuffle.</param>
20
30
/// <param name="items">Number of items in the array.</param>
21
31
/// <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 )
23
33
{
24
- if ( items <= 0 )
34
+ if ( items <= 0 )
25
35
{
26
36
return ;
27
37
}
You can’t perform that action at this time.
0 commit comments