084eea9eea84 — Michael Johnson 1 year, 2 months ago
Improve RandomNumberGeneratorShim testing where holes were found with mutation testing with Stryker
M src/RandN/Compat/RandomNumberGeneratorShim.cs +1 -1
@@ 128,7 128,7 @@ public sealed class RandomNumberGenerato
             // The rest of the data needs to be regenerated, since those bytes were moved down. We'll end up
             // regenerating zeroCount bytes.
             span = span.Slice(span.Length - zeroCount);
-            Debug.Assert(data.Length == zeroCount);
+            Debug.Assert(span.Length == zeroCount);
         }
     }
 #endif

          
M src/Tests/Compat/RandomNumberGeneratorShimTests.cs +13 -0
@@ 15,14 15,27 @@ public sealed class RandomNumberGenerato
     {
         var rng = new SequenceRng(new UInt32[] { 0, 1, 2, 0, 1, 2, 0, 1 });
         var shim = RandomNumberGeneratorShim.Create(rng);
+        var expected = new Byte[]
+        {
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+            1, 2, 1, 2, 1,
+        };
 
         var buffer = new Byte[35];
         shim.GetNonZeroBytes(buffer);
         Assert.DoesNotContain((Byte)0, buffer);
+        Assert.Equal(expected, buffer);
 
 #if !NET48
+        Array.Fill(buffer, (Byte)0);
         shim.GetNonZeroBytes(buffer.AsSpan());
         Assert.DoesNotContain((Byte)0, buffer);
+        Assert.Equal(expected, buffer);
 #endif
     }