Created
January 25, 2016 11:18
-
-
Save rofr/fcabe8bc3316f58cae7f to your computer and use it in GitHub Desktop.
Is using a Random seed in unit tests a good idea?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Length() | |
{ | |
const string key = "a"; | |
const int limit = 100000; | |
//seed is random but included in output if test fails | |
var seed = new Random().Next(); | |
var r = new Random(seed); | |
int max = 0; | |
for (int i = 0; i < 1000; i++) | |
{ | |
int index = r.Next(limit); | |
max = Math.Max(index, max); | |
_target.SetBit(key, index); | |
var actual = _target.StrLength(key); | |
Assert.AreEqual(max + 1, actual, "failed at iteration " + i + "using seed " + seed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment