Skip to content

Commit

Permalink
test: use static random seed in tests
Browse files Browse the repository at this point in the history
this prevents the code coverage from varying depending on how
well the random data compresses
  • Loading branch information
piksel committed May 13, 2021
1 parent 232d690 commit 0fc736e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs
Expand Up @@ -12,6 +12,9 @@ namespace ICSharpCode.SharpZipLib.Tests.BZip2
[TestFixture]
public class BZip2Suite
{
// Use the same random seed to guarantee all the code paths are followed
const int RandomSeed = 4;

/// <summary>
/// Basic compress/decompress test BZip2
/// </summary>
Expand All @@ -23,7 +26,7 @@ public void BasicRoundTrip()
var outStream = new BZip2OutputStream(ms);

byte[] buf = new byte[10000];
var rnd = new Random();
var rnd = new Random(RandomSeed);
rnd.NextBytes(buf);

outStream.Write(buf, 0, buf.Length);
Expand Down
Expand Up @@ -16,6 +16,9 @@ namespace ICSharpCode.SharpZipLib.Tests.Base
[TestFixture]
public class InflaterDeflaterTestSuite
{
// Use the same random seed to guarantee all the code paths are followed
const int RandomSeed = 5;

private void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
{
byte[] buf2 = new byte[original.Length];
Expand Down Expand Up @@ -60,7 +63,7 @@ private MemoryStream Deflate(byte[] data, int level, bool zlib)
private static byte[] GetRandomTestData(int size)
{
byte[] buffer = new byte[size];
var rnd = new Random();
var rnd = new Random(RandomSeed);
rnd.NextBytes(buffer);

return buffer;
Expand Down Expand Up @@ -184,7 +187,7 @@ public async Task InflateDeflateZlibAsync([Range(0, 9)] int level)
private int runLevel;
private bool runZlib;
private long runCount;
private readonly Random runRandom = new Random(5);
private readonly Random runRandom = new Random(RandomSeed);

private void DeflateAndInflate(byte[] buffer)
{
Expand Down

0 comments on commit 0fc736e

Please sign in to comment.