diff --git a/X10D.Tests/src/Collections/EnumerableTests.cs b/X10D.Tests/src/Collections/EnumerableTests.cs new file mode 100644 index 0000000..5cd9dc0 --- /dev/null +++ b/X10D.Tests/src/Collections/EnumerableTests.cs @@ -0,0 +1,34 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Collections; + +namespace X10D.Tests.Collections; + +[TestClass] +public class EnumerableTests +{ + [TestMethod] + public void EnumerableShuffledShouldBeDifferentOrder() + { + var list = new List + { + 1, + 2, + 3, + 4, + 5 + }; + var shuffled = new List(list); + + CollectionAssert.AreEqual(list, shuffled); + + shuffled = new List(list.Shuffled()); + + CollectionAssert.AreNotEqual(list, shuffled); + } + + [TestMethod] + public void NullShuffledShouldThrow() + { + Assert.ThrowsException(() => ((List?)null)!.Shuffled()); + } +} diff --git a/X10D.Tests/src/Collections/ListTests.cs b/X10D.Tests/src/Collections/ListTests.cs new file mode 100644 index 0000000..135a485 --- /dev/null +++ b/X10D.Tests/src/Collections/ListTests.cs @@ -0,0 +1,57 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Collections; + +namespace X10D.Tests.Collections; + +[TestClass] +public class ListTests +{ + [TestMethod] + public void ListShuffleShouldReorder() + { + var list = new List + { + 1, + 2, + 3, + 4, + 5 + }; + var shuffled = new List(list); + + CollectionAssert.AreEqual(list, shuffled); + + shuffled.Shuffle(); + + CollectionAssert.AreNotEqual(list, shuffled); + } + + [TestMethod] + public void ListRandomShouldReturnExistingObject() + { + var list = new List + { + 1, + 2, + 3, + 4, + 5 + }; + + int random = list.Random(); + + Assert.IsTrue(list.Contains(random)); + } + + [TestMethod] + public void NullShuffleShouldThrow() + { + Assert.ThrowsException(() => ((List?)null)!.Shuffle()); + } + + [TestMethod] + public void NullRandomShouldThrow() + { + Assert.ThrowsException(() => ((List?)null)!.Random()); + } +} diff --git a/X10D.Tests/src/Core/EnumerableTests.cs b/X10D.Tests/src/Core/EnumerableTests.cs index a048c0d..3e37d55 100644 --- a/X10D.Tests/src/Core/EnumerableTests.cs +++ b/X10D.Tests/src/Core/EnumerableTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Collections; namespace X10D.Tests.Core; diff --git a/X10D/src/Collections/EnumerableExtensions.cs b/X10D/src/Collections/EnumerableExtensions.cs index 02f4f66..64c770e 100644 --- a/X10D/src/Collections/EnumerableExtensions.cs +++ b/X10D/src/Collections/EnumerableExtensions.cs @@ -3,7 +3,7 @@ /// /// Extension methods for . /// -public static partial class EnumerableExtensions +public static class EnumerableExtensions { /// /// Reorganizes the elements in an enumerable by implementing a Fisher-Yates shuffle, and returns th shuffled result.