X10D/X10D.Tests/src/Collections/ListTests.cs

43 lines
1.1 KiB
C#
Raw Normal View History

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()
{
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()
{
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());
}
}