From 0fc736e737e2466b3eeac572cf7ca72a6d8c4fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Thu, 13 May 2021 15:28:53 +0200 Subject: [PATCH] test: use static random seed in tests this prevents the code coverage from varying depending on how well the random data compresses --- test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs | 5 ++++- .../Base/InflaterDeflaterTests.cs | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs b/test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs index 34dc288b..8d6febc1 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs @@ -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; + /// /// Basic compress/decompress test BZip2 /// @@ -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); diff --git a/test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs index 6aff0a69..e6e3c412 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs @@ -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]; @@ -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; @@ -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) {