1
0
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:
Oliver Booth 2022-04-21 22:35:06 +01:00
parent 118eeae46a
commit 0fb01726db
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
4 changed files with 93 additions and 1 deletions

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

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

View File

@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Collections;
namespace X10D.Tests.Core;

View File

@ -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.