mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 01:18:46 +00:00
[ci skip] Reduce chance of Shuffle tests failing
A list containing 5 elements has a 1/(5!) (1/120) chance of being shuffled to the same order. This was causing unit tests to fail locally by pure fluke. Tests now generate a list from 1-52, which has a 1/(52!) chance of shuffling to the same order, so the chance is basically 0. If these tests ran once per second, it would take 1.9x10^50 * age of the universe to hit a collision. This still can happen. Randomness does not guarantee we won't hit the same order. The odds are just so astronomically small that it's not worth considering. And if the CI run fails due to these tests failing, just re-run them anyway and call it a day
This commit is contained in:
parent
224e465915
commit
68d1ea6f4d
@ -9,14 +9,7 @@ public class EnumerableTests
|
||||
[TestMethod]
|
||||
public void EnumerableShuffledShouldBeDifferentOrder()
|
||||
{
|
||||
var list = new List<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
||||
var shuffled = new List<int>(list);
|
||||
|
||||
CollectionAssert.AreEqual(list, shuffled);
|
||||
|
@ -9,14 +9,7 @@ public class ListTests
|
||||
[TestMethod]
|
||||
public void ListShuffleShouldReorder()
|
||||
{
|
||||
var list = new List<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
||||
var shuffled = new List<int>(list);
|
||||
|
||||
CollectionAssert.AreEqual(list, shuffled);
|
||||
@ -29,15 +22,7 @@ public class ListTests
|
||||
[TestMethod]
|
||||
public void ListRandomShouldReturnExistingObject()
|
||||
{
|
||||
var list = new List<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
|
||||
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
||||
int random = list.Random();
|
||||
|
||||
Assert.IsTrue(list.Contains(random));
|
||||
|
Loading…
Reference in New Issue
Block a user