Skip to content

Commit

Permalink
RandomETest: Added tests for PopRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
BasmanovDaniil committed Jan 5, 2021
1 parent 8e9477f commit 8d6accd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Tests/Editor/RandomETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,41 @@ public void DictionaryContainsReturnedItem()
}
}
}

public class PopRandom_IList
{
private readonly List<int> nullList = null;
private readonly List<int> emptyList = new List<int>();
private MRandom random = new MRandom(1337);

[Test]
public void NullListThrowsException()
{
Assert.Catch<ArgumentNullException>(() => nullList.PopRandom());
Assert.Catch<ArgumentNullException>(() => nullList.PopRandom(ref random));
}

[Test]
public void EmptyListThrowsException()
{
Assert.Catch<ArgumentException>(() => emptyList.PopRandom());
Assert.Catch<ArgumentException>(() => emptyList.PopRandom(ref random));
}

[Test]
public void ListDoesNotContainReturnedItem()
{
var list = new List<int> {0, 1, 2, 3};
for (int i = 0; i < list.Count; i++)
{
Assert.False(list.Contains(list.PopRandom()));
}
list = new List<int> {0, 1, 2, 3};
for (int i = 0; i < list.Count; i++)
{
Assert.False(list.Contains(list.PopRandom(ref random)));
}
}
}
}
}

0 comments on commit 8d6accd

Please sign in to comment.