mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:18:46 +00:00
Add tests for Enumerable/List
This commit is contained in:
parent
118eeae46a
commit
0fb01726db
34
X10D.Tests/src/Collections/EnumerableTests.cs
Normal file
34
X10D.Tests/src/Collections/EnumerableTests.cs
Normal file
@ -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<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
var shuffled = new List<int>(list);
|
||||
|
||||
CollectionAssert.AreEqual(list, shuffled);
|
||||
|
||||
shuffled = new List<int>(list.Shuffled());
|
||||
|
||||
CollectionAssert.AreNotEqual(list, shuffled);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NullShuffledShouldThrow()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Shuffled());
|
||||
}
|
||||
}
|
57
X10D.Tests/src/Collections/ListTests.cs
Normal file
57
X10D.Tests/src/Collections/ListTests.cs
Normal file
@ -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<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
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>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Collections;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IEnumerable{T}" />.
|
||||
/// </summary>
|
||||
public static partial class EnumerableExtensions
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reorganizes the elements in an enumerable by implementing a Fisher-Yates shuffle, and returns th shuffled result.
|
||||
|
Loading…
Reference in New Issue
Block a user