2022-04-21 21:35:06 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using X10D.Collections;
|
|
|
|
|
|
|
|
|
|
namespace X10D.Tests.Collections;
|
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ListTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ListShuffleShouldReorder()
|
|
|
|
|
{
|
2022-04-23 10:25:09 +00:00
|
|
|
|
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
2022-04-21 21:35:06 +00:00
|
|
|
|
var shuffled = new List<int>(list);
|
|
|
|
|
|
|
|
|
|
CollectionAssert.AreEqual(list, shuffled);
|
|
|
|
|
|
|
|
|
|
shuffled.Shuffle();
|
|
|
|
|
|
|
|
|
|
CollectionAssert.AreNotEqual(list, shuffled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ListRandomShouldReturnExistingObject()
|
|
|
|
|
{
|
2022-04-23 10:25:09 +00:00
|
|
|
|
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
2022-04-21 21:35:06 +00:00
|
|
|
|
int random = list.Random();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(list.Contains(random));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NullShuffleShouldThrow()
|
|
|
|
|
{
|
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Shuffle());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NullRandomShouldThrow()
|
|
|
|
|
{
|
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Random());
|
|
|
|
|
}
|
|
|
|
|
}
|