2022-04-21 21:35:06 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using X10D.Collections;
|
|
|
|
|
|
|
|
|
|
namespace X10D.Tests.Collections;
|
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class EnumerableTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2022-04-25 16:09:49 +00:00
|
|
|
|
public void Shuffled_ShouldThrow_GivenNull()
|
2022-04-21 21:35:06 +00:00
|
|
|
|
{
|
2022-04-25 16:09:49 +00:00
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Shuffled());
|
2022-04-21 21:35:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2022-04-25 16:09:49 +00:00
|
|
|
|
public void Shuffled_ShouldReorder_GivenNotNull()
|
2022-04-21 21:35:06 +00:00
|
|
|
|
{
|
2022-04-25 16:09:49 +00:00
|
|
|
|
int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order
|
|
|
|
|
int[] shuffled = array[..];
|
|
|
|
|
|
|
|
|
|
CollectionAssert.AreEqual(array, shuffled);
|
|
|
|
|
|
|
|
|
|
shuffled = array.Shuffled().ToArray();
|
|
|
|
|
CollectionAssert.AreNotEqual(array, shuffled);
|
2022-04-21 21:35:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|