1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

chore: switch from MSTest to NUnit (#76)

This commit is contained in:
Oliver Booth 2023-04-05 22:26:31 +01:00
parent 5d2313fa20
commit ab62db2b37
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
163 changed files with 6604 additions and 5769 deletions

View File

@ -15,15 +15,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0"/> <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0"/> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0"/>
<PackageReference Include="Moq" Version="4.18.4"/> <PackageReference Include="Moq" Version="4.18.4"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2"/> <PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="MSTest.TestFramework" Version="3.0.2"/> <PackageReference Include="NUnit3TestAdapter" Version="4.4.2"/>
<PackageReference Include="coverlet.collector" Version="3.2.0"> <PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
<PrivateAssets>all</PrivateAssets> <PackageReference Include="coverlet.collector" Version="3.2.0"/>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,42 +1,42 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class ArrayTests public partial class ArrayTests
{ {
[TestClass] [TestFixture]
public class AsReadOnlyTests public class AsReadOnlyTests
{ {
[TestMethod] [Test]
public void AsReadOnly_ShouldReturnReadOnlyCollection_WhenArrayIsNotNull() public void AsReadOnly_ShouldReturnReadOnlyCollection_WhenArrayIsNotNull()
{ {
int[] array = {1, 2, 3}; int[] array = {1, 2, 3};
IReadOnlyCollection<int> result = array.AsReadOnly(); IReadOnlyCollection<int> result = array.AsReadOnly();
Assert.IsInstanceOfType(result, typeof(IReadOnlyCollection<int>)); Assert.That(result, Is.InstanceOf<IReadOnlyCollection<int>>());
} }
[TestMethod] [Test]
public void AsReadOnly_ShouldThrowArgumentNullException_WhenArrayIsNull() public void AsReadOnly_ShouldThrowArgumentNullException_WhenArrayIsNull()
{ {
int[]? array = null; int[] array = null!;
Assert.ThrowsException<ArgumentNullException>(() => array!.AsReadOnly()); Assert.Throws<ArgumentNullException>(() => _ = array.AsReadOnly());
} }
[TestMethod] [Test]
public void AsReadOnly_ShouldReturnCorrectCount_WhenArrayIsNotEmpty() public void AsReadOnly_ShouldReturnCorrectCount_WhenArrayIsNotEmpty()
{ {
int[] array = {1, 2, 3}; int[] array = {1, 2, 3};
IReadOnlyCollection<int> result = array.AsReadOnly(); IReadOnlyCollection<int> result = array.AsReadOnly();
Assert.AreEqual(array.Length, result.Count); Assert.That(result, Has.Count.EqualTo(array.Length));
} }
[TestMethod] [Test]
public void AsReadOnly_ShouldReturnEmptyCollection_WhenArrayIsEmpty() public void AsReadOnly_ShouldReturnEmptyCollection_WhenArrayIsEmpty()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
IReadOnlyCollection<int> result = array.AsReadOnly(); IReadOnlyCollection<int> result = array.AsReadOnly();
Assert.AreEqual(0, result.Count); Assert.That(result, Is.Empty);
} }
} }
} }

View File

@ -1,63 +1,63 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class ArrayTests public partial class ArrayTests
{ {
[TestClass] [TestFixture]
public class ClearTests public class ClearTests
{ {
[TestMethod] [Test]
public void Clear_ShouldClearTheArray() public void Clear_ShouldClearTheArray()
{ {
var array = new int?[] {1, 2, 3, null, 4}; var array = new int?[] {1, 2, 3, null, 4};
array.Clear(); array.Clear();
Assert.IsTrue(array.All(x => x == null)); Assert.That(array.All(x => x == null));
} }
[TestMethod] [Test]
public void Clear_ShouldDoNothing_WhenArrayIsEmpty() public void Clear_ShouldDoNothing_WhenArrayIsEmpty()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
array.Clear(); array.Clear();
} }
[TestMethod] [Test]
public void Clear_WithRange_ShouldClearTheSpecifiedRangeOfTheArray() public void Clear_WithRange_ShouldClearTheSpecifiedRangeOfTheArray()
{ {
var array = new int?[] {1, 2, 3, null, 4}; var array = new int?[] {1, 2, 3, null, 4};
array.Clear(1..4); array.Clear(1..4);
Assert.AreEqual(5, array.Length); Assert.That(array.Length, Is.EqualTo(5));
Assert.AreEqual(1, array[0]); Assert.That(array[0], Is.EqualTo(1));
Assert.AreEqual(4, array[4]); Assert.That(array[4], Is.EqualTo(4));
Assert.IsTrue(array[1..4].All(x => x == null)); Assert.That(array[1..4].All(x => x == null));
} }
[TestMethod] [Test]
public void Clear_WithIndexAndLength_ShouldClearTheSpecifiedRangeOfTheArray() public void Clear_WithIndexAndLength_ShouldClearTheSpecifiedRangeOfTheArray()
{ {
var array = new int?[] {1, 2, 3, null, 4}; var array = new int?[] {1, 2, 3, null, 4};
array.Clear(1, 3); array.Clear(1, 3);
Assert.AreEqual(5, array.Length); Assert.That(array.Length, Is.EqualTo(5));
Assert.AreEqual(1, array[0]); Assert.That(array[0], Is.EqualTo(1));
Assert.AreEqual(4, array[4]); Assert.That(array[4], Is.EqualTo(4));
Assert.IsTrue(array[1..4].All(x => x == null)); Assert.That(array[1..4].All(x => x == null));
} }
[TestMethod] [Test]
public void Clear_ShouldThrowArgumentNullException_WhenArrayIsNull() public void Clear_ShouldThrowArgumentNullException_WhenArrayIsNull()
{ {
int[] array = null!; int[] array = null!;
Assert.ThrowsException<ArgumentNullException>(() => array.Clear()); Assert.Throws<ArgumentNullException>(() => array.Clear());
Assert.ThrowsException<ArgumentNullException>(() => array.Clear(0, 1)); Assert.Throws<ArgumentNullException>(() => array.Clear(0, 1));
Assert.ThrowsException<ArgumentNullException>(() => array.Clear(..1)); Assert.Throws<ArgumentNullException>(() => array.Clear(..1));
} }
} }
} }

View File

@ -1,8 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public partial class ArrayTests public partial class ArrayTests
{ {
} }

View File

@ -1,56 +1,56 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class BoolListTests public class BoolListTests
{ {
[TestMethod] [Test]
public void PackByte_Should_Pack_Correctly() public void PackByte_Should_Pack_Correctly()
{ {
var array = new[] {true, false, true, false, true, false, true, false}; var array = new[] {true, false, true, false, true, false, true, false};
Assert.AreEqual(85, array.PackByte()); // 01010101 Assert.That(array.PackByte(), Is.EqualTo(85)); // 01010101
} }
[TestMethod] [Test]
public void Pack16Bit_Should_Pack_Correctly() public void Pack16Bit_Should_Pack_Correctly()
{ {
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true}; var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
Assert.AreEqual(2901, array.PackInt16()); // 101101010101 Assert.That(array.PackInt16(), Is.EqualTo(2901)); // 101101010101
} }
[TestMethod] [Test]
public void Pack32Bit_Should_Pack_Correctly() public void Pack32Bit_Should_Pack_Correctly()
{ {
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true}; var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
Assert.AreEqual(2901, array.PackInt32()); // 101101010101 Assert.That(array.PackInt32(), Is.EqualTo(2901)); // 101101010101
} }
[TestMethod] [Test]
public void Pack64Bit_Should_Pack_Correctly() public void Pack64Bit_Should_Pack_Correctly()
{ {
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true}; var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
Assert.AreEqual(2901, array.PackInt64()); // 101101010101 Assert.That(array.PackInt64(), Is.EqualTo(2901)); // 101101010101
} }
[TestMethod] [Test]
public void Pack_ShouldThrow_GivenLargeArray() public void Pack_ShouldThrow_GivenLargeArray()
{ {
bool[] array = Enumerable.Repeat(false, 65).ToArray(); bool[] array = Enumerable.Repeat(false, 65).ToArray();
Assert.ThrowsException<ArgumentException>(() => array.PackByte()); Assert.Throws<ArgumentException>(() => _ = array.PackByte());
Assert.ThrowsException<ArgumentException>(() => array.PackInt16()); Assert.Throws<ArgumentException>(() => _ = array.PackInt16());
Assert.ThrowsException<ArgumentException>(() => array.PackInt32()); Assert.Throws<ArgumentException>(() => _ = array.PackInt32());
Assert.ThrowsException<ArgumentException>(() => array.PackInt64()); Assert.Throws<ArgumentException>(() => _ = array.PackInt64());
} }
[TestMethod] [Test]
public void Pack_ShouldThrow_GivenNull() public void Pack_ShouldThrow_GivenNull()
{ {
bool[]? array = null; bool[] array = null!;
Assert.ThrowsException<ArgumentNullException>(() => array!.PackByte()); Assert.Throws<ArgumentNullException>(() => _ = array.PackByte());
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt16()); Assert.Throws<ArgumentNullException>(() => _ = array.PackInt16());
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt32()); Assert.Throws<ArgumentNullException>(() => _ = array.PackInt32());
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt64()); Assert.Throws<ArgumentNullException>(() => _ = array.PackInt64());
} }
} }

View File

@ -1,67 +1,74 @@
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class ByteTests public class ByteTests
{ {
[TestMethod] [Test]
public void Unpack_ShouldUnpackToArrayCorrectly() public void Unpack_ShouldUnpackToArrayCorrectly()
{ {
const byte value = 0b11010100; const byte value = 0b11010100;
bool[] bits = value.Unpack(); bool[] bits = value.Unpack();
Assert.AreEqual(8, bits.Length); Assert.That(bits, Has.Length.EqualTo(8));
Assert.Multiple(() =>
Assert.IsFalse(bits[0]); {
Assert.IsFalse(bits[1]); Assert.That(bits[0], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[1], Is.False);
Assert.IsFalse(bits[3]); Assert.That(bits[2], Is.True);
Assert.IsTrue(bits[4]); Assert.That(bits[3], Is.False);
Assert.IsFalse(bits[5]); Assert.That(bits[4], Is.True);
Assert.IsTrue(bits[6]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[7]); Assert.That(bits[6], Is.True);
Assert.That(bits[7], Is.True);
});
} }
[TestMethod] [Test]
public void Unpack_ShouldUnpackToSpanCorrectly() public void Unpack_ShouldUnpackToSpanCorrectly()
{ {
const byte value = 0b11010100; const byte value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[8]; Span<bool> bits = stackalloc bool[8];
value.Unpack(bits); value.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
});
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[Test]
[TestMethod]
public void UnpackInternal_Fallback_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Fallback_ShouldUnpackToSpanCorrectly()
{ {
const byte value = 0b11010100; const byte value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[8]; Span<bool> bits = stackalloc bool[8];
value.UnpackInternal_Fallback(bits); value.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
});
} }
[TestMethod] [Test]
public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly()
{ {
if (!Sse3.IsSupported) if (!Sse3.IsSupported)
@ -70,31 +77,34 @@ public class ByteTests
} }
const byte value = 0b11010100; const byte value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[8]; Span<bool> bits = stackalloc bool[8];
value.UnpackInternal_Ssse3(bits); value.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
});
} }
#endif #endif
[TestMethod] [Test]
public void Unpack_ShouldRepackEqually() public void Unpack_ShouldRepackEqually()
{ {
const byte value = 0b11010100; const byte value = 0b11010100;
Assert.AreEqual(value, value.Unpack().PackByte()); Assert.That(value.Unpack().PackByte(), Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Unpack_ShouldThrow_GivenTooSmallSpan() public void Unpack_ShouldThrow_GivenTooSmallSpan()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
const byte value = 0b11010100; const byte value = 0b11010100;
Span<bool> bits = stackalloc bool[0]; Span<bool> bits = stackalloc bool[0];

View File

@ -1,16 +1,16 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq; using Moq;
using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class CollectionTests public partial class CollectionTests
{ {
[TestClass] [TestFixture]
public class ClearAndDisposeAllTests public class ClearAndDisposeAllTests
{ {
[TestMethod] [Test]
public void ClearAndDisposeAll_ShouldClearAndDisposeAllItems_WhenCalledWithValidList() public void ClearAndDisposeAll_ShouldClearAndDisposeAllItems_WhenCalledWithValidList()
{ {
var mock1 = new Mock<IDisposable>(); var mock1 = new Mock<IDisposable>();
@ -23,23 +23,23 @@ public partial class CollectionTests
mock1.Verify(i => i.Dispose(), Times.Once); mock1.Verify(i => i.Dispose(), Times.Once);
mock2.Verify(i => i.Dispose(), Times.Once); mock2.Verify(i => i.Dispose(), Times.Once);
mock3.Verify(i => i.Dispose(), Times.Once); mock3.Verify(i => i.Dispose(), Times.Once);
Assert.AreEqual(0, list.Count); Assert.That(list, Is.Empty);
} }
[TestMethod] [Test]
public void ClearAndDisposeAll_ShouldThrowArgumentNullException_WhenCalledWithNullList() public void ClearAndDisposeAll_ShouldThrowArgumentNullException_WhenCalledWithNullList()
{ {
List<IDisposable>? list = null; List<IDisposable>? list = null;
Assert.ThrowsException<ArgumentNullException>(() => list!.ClearAndDisposeAll()); Assert.Throws<ArgumentNullException>(() => list!.ClearAndDisposeAll());
} }
[TestMethod] [Test]
public void ClearAndDisposeAll_ShouldThrowInvalidOperationException_WhenCalledWithReadOnlyList() public void ClearAndDisposeAll_ShouldThrowInvalidOperationException_WhenCalledWithReadOnlyList()
{ {
var mock = new Mock<IDisposable>(); var mock = new Mock<IDisposable>();
var list = new ReadOnlyCollection<IDisposable>(new List<IDisposable> {mock.Object}); var list = new ReadOnlyCollection<IDisposable>(new List<IDisposable> {mock.Object});
Assert.ThrowsException<InvalidOperationException>(() => list.ClearAndDisposeAll()); Assert.Throws<InvalidOperationException>(() => list.ClearAndDisposeAll());
} }
} }
} }

View File

@ -1,16 +1,16 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq; using Moq;
using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class CollectionTests public partial class CollectionTests
{ {
[TestClass] [TestFixture]
public class ClearAndDisposeAllAsyncTests public class ClearAndDisposeAllAsyncTests
{ {
[TestMethod] [Test]
public async Task ClearAndDisposeAllAsync_ShouldClearAndDisposeAllItems_WhenCalledWithValidList() public async Task ClearAndDisposeAllAsync_ShouldClearAndDisposeAllItems_WhenCalledWithValidList()
{ {
var mock1 = new Mock<IAsyncDisposable>(); var mock1 = new Mock<IAsyncDisposable>();
@ -23,23 +23,23 @@ public partial class CollectionTests
mock1.Verify(i => i.DisposeAsync(), Times.Once); mock1.Verify(i => i.DisposeAsync(), Times.Once);
mock2.Verify(i => i.DisposeAsync(), Times.Once); mock2.Verify(i => i.DisposeAsync(), Times.Once);
mock3.Verify(i => i.DisposeAsync(), Times.Once); mock3.Verify(i => i.DisposeAsync(), Times.Once);
Assert.AreEqual(0, list.Count); Assert.That(list, Is.Empty);
} }
[TestMethod] [Test]
public async Task ClearAndDisposeAllAsync_ShouldThrowArgumentNullException_WhenCalledWithNullList() public void ClearAndDisposeAllAsync_ShouldThrowArgumentNullException_WhenCalledWithNullList()
{ {
List<IAsyncDisposable>? list = null; List<IAsyncDisposable>? list = null;
await Assert.ThrowsExceptionAsync<ArgumentNullException>(list!.ClearAndDisposeAllAsync).ConfigureAwait(false); Assert.ThrowsAsync<ArgumentNullException>(list!.ClearAndDisposeAllAsync);
} }
[TestMethod] [Test]
public async Task ClearAndDisposeAllAsync_ShouldThrowInvalidOperationException_WhenCalledWithReadOnlyList() public void ClearAndDisposeAllAsync_ShouldThrowInvalidOperationException_WhenCalledWithReadOnlyList()
{ {
var mock = new Mock<IAsyncDisposable>(); var mock = new Mock<IAsyncDisposable>();
var list = new ReadOnlyCollection<IAsyncDisposable>(new List<IAsyncDisposable> {mock.Object}); var list = new ReadOnlyCollection<IAsyncDisposable>(new List<IAsyncDisposable> {mock.Object});
await Assert.ThrowsExceptionAsync<InvalidOperationException>(list.ClearAndDisposeAllAsync).ConfigureAwait(false); Assert.ThrowsAsync<InvalidOperationException>(list.ClearAndDisposeAllAsync);
} }
} }
} }

View File

@ -1,8 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public partial class CollectionTests public partial class CollectionTests
{ {
} }

View File

@ -1,176 +1,231 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class DictionaryTests public class DictionaryTests
{ {
[TestMethod] [Test]
public void AddOrUpdate_ShouldAddNewKey_IfNotExists_GivenConcreteDictionary() public void AddOrUpdate_ShouldAddNewKey_IfNotExists_GivenConcreteDictionary()
{ {
var dictionary = new Dictionary<int, string>(); var dictionary = new Dictionary<int, string>();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, "one", (_, _) => string.Empty); dictionary.AddOrUpdate(1, "one", (_, _) => string.Empty);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, _ => "one", (_, _) => string.Empty); dictionary.AddOrUpdate(1, _ => "one", (_, _) => string.Empty);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, (_, _) => "one", (_, _, _) => string.Empty, 0); dictionary.AddOrUpdate(1, (_, _) => "one", (_, _, _) => string.Empty, 0);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1), Is.True);
Assert.That(dictionary[1], Is.EqualTo("one"));
});
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldAddNewKey_IfNotExists_GivenIDictionary() public void AddOrUpdate_ShouldAddNewKey_IfNotExists_GivenIDictionary()
{ {
IDictionary<int, string> dictionary = new Dictionary<int, string>(); IDictionary<int, string> dictionary = new Dictionary<int, string>();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, "one", (_, _) => string.Empty); dictionary.AddOrUpdate(1, "one", (_, _) => string.Empty);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1), Is.True);
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, _ => "one", (_, _) => string.Empty); dictionary.AddOrUpdate(1, _ => "one", (_, _) => string.Empty);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1), Is.True);
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary.AddOrUpdate(1, (_, _) => "one", (_, _, _) => string.Empty, 0); dictionary.AddOrUpdate(1, (_, _) => "one", (_, _, _) => string.Empty, 0);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1), Is.True);
Assert.That(dictionary[1], Is.EqualTo("one"));
});
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldUpdateKey_IfExists_GivenConcreteDirection() public void AddOrUpdate_ShouldUpdateKey_IfExists_GivenConcreteDirection()
{ {
var dictionary = new Dictionary<int, string> {[1] = "one"}; var dictionary = new Dictionary<int, string> {[1] = "one"};
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.AddOrUpdate(1, string.Empty, (_, _) => "two"); dictionary.AddOrUpdate(1, string.Empty, (_, _) => "two");
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("two", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary[1] = "one"; dictionary[1] = "one";
dictionary.AddOrUpdate(1, _ => string.Empty, (_, _) => "two"); dictionary.AddOrUpdate(1, _ => string.Empty, (_, _) => "two");
Assert.IsTrue(dictionary.ContainsKey(1));
Assert.AreEqual("two", dictionary[1]); Assert.Multiple(() =>
{
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary[1] = "one"; dictionary[1] = "one";
dictionary.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => "two", 0); dictionary.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => "two", 0);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("two", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldUpdateKey_IfExists_GivenIDictionary() public void AddOrUpdate_ShouldUpdateKey_IfExists_GivenIDictionary()
{ {
IDictionary<int, string> dictionary = new Dictionary<int, string> {[1] = "one"}; IDictionary<int, string> dictionary = new Dictionary<int, string> {[1] = "one"};
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("one", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("one"));
});
dictionary.AddOrUpdate(1, string.Empty, (_, _) => "two"); dictionary.AddOrUpdate(1, string.Empty, (_, _) => "two");
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("two", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.Multiple(() =>
dictionary[1] = "one"; {
Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
});
dictionary[1] = "one";
dictionary.AddOrUpdate(1, _ => string.Empty, (_, _) => "two"); dictionary.AddOrUpdate(1, _ => string.Empty, (_, _) => "two");
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("two", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
dictionary.Clear(); dictionary.Clear();
Assert.IsFalse(dictionary.ContainsKey(1)); Assert.Multiple(() =>
{
Assert.That(dictionary, Is.Empty);
Assert.That(dictionary.ContainsKey(1), Is.False);
dictionary[1] = "one"; dictionary[1] = "one";
});
dictionary.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => "two", 0); dictionary.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => "two", 0);
Assert.IsTrue(dictionary.ContainsKey(1)); Assert.Multiple(() =>
Assert.AreEqual("two", dictionary[1]); {
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary[1], Is.EqualTo("two"));
});
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullDictionary_GivenConcreteDictionary() public void AddOrUpdate_ShouldThrow_GivenNullDictionary_GivenConcreteDictionary()
{ {
Dictionary<int, string>? dictionary = null; Dictionary<int, string>? dictionary = null;
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.AddOrUpdate(1, string.Empty, (_, _) => string.Empty)); Assert.Throws<ArgumentNullException>(() => dictionary!.AddOrUpdate(1, string.Empty, (_, _) => string.Empty));
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
dictionary!.AddOrUpdate(1, _ => string.Empty, (_, _) => string.Empty)); dictionary!.AddOrUpdate(1, _ => string.Empty, (_, _) => string.Empty));
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
dictionary!.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => string.Empty, 0)); dictionary!.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => string.Empty, 0));
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullDictionary_GivenIDictionary() public void AddOrUpdate_ShouldThrow_GivenNullDictionary_GivenIDictionary()
{ {
IDictionary<int, string>? dictionary = null; IDictionary<int, string>? dictionary = null;
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.AddOrUpdate(1, string.Empty, (_, _) => string.Empty)); Assert.Throws<ArgumentNullException>(() => dictionary!.AddOrUpdate(1, string.Empty, (_, _) => string.Empty));
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
dictionary!.AddOrUpdate(1, _ => string.Empty, (_, _) => string.Empty)); dictionary!.AddOrUpdate(1, _ => string.Empty, (_, _) => string.Empty));
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
dictionary!.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => string.Empty, 0)); dictionary!.AddOrUpdate(1, (_, _) => string.Empty, (_, _, _) => string.Empty, 0));
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullUpdateValueFactory_GivenConcreteDictionary() public void AddOrUpdate_ShouldThrow_GivenNullUpdateValueFactory_GivenConcreteDictionary()
{ {
var dictionary = new Dictionary<int, string>(); var dictionary = new Dictionary<int, string>();
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, string.Empty, null!)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, string.Empty, null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, _ => string.Empty, null!)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, _ => string.Empty, null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, (_, _) => string.Empty, null!, 0)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, (_, _) => string.Empty, null!, 0));
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullUpdateValueFactory_GivenIDictionary() public void AddOrUpdate_ShouldThrow_GivenNullUpdateValueFactory_GivenIDictionary()
{ {
IDictionary<int, string> dictionary = new Dictionary<int, string>(); IDictionary<int, string> dictionary = new Dictionary<int, string>();
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, string.Empty, null!)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, string.Empty, null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, _ => string.Empty, null!)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, _ => string.Empty, null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, (_, _) => string.Empty, null!, 0)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, (_, _) => string.Empty, null!, 0));
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullAddValueFactory_GivenConcreteDictionary() public void AddOrUpdate_ShouldThrow_GivenNullAddValueFactory_GivenConcreteDictionary()
{ {
var dictionary = new Dictionary<int, string>(); var dictionary = new Dictionary<int, string>();
Func<int, string>? addValueFactory = null; Func<int, string>? addValueFactory = null;
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one")); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one"));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0));
} }
[TestMethod] [Test]
public void AddOrUpdate_ShouldThrow_GivenNullAddValueFactory_GivenIDictionary() public void AddOrUpdate_ShouldThrow_GivenNullAddValueFactory_GivenIDictionary()
{ {
IDictionary<int, string> dictionary = new Dictionary<int, string>(); IDictionary<int, string> dictionary = new Dictionary<int, string>();
Func<int, string>? addValueFactory = null; Func<int, string>? addValueFactory = null;
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one")); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one"));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0)); Assert.Throws<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0));
} }
[TestMethod] [Test]
public void ToConnectionString_ShouldReturnConnectionString() public void ToConnectionString_ShouldReturnConnectionString()
{ {
var dictionary = new Dictionary<string, string?> var dictionary = new Dictionary<string, string?>
@ -179,10 +234,10 @@ public class DictionaryTests
}; };
string connectionString = dictionary.ToConnectionString(); string connectionString = dictionary.ToConnectionString();
Assert.AreEqual("Data Source=localhost;Initial Catalog=test;Integrated Security=True;Foobar=", connectionString); Assert.That(connectionString, Is.EqualTo("Data Source=localhost;Initial Catalog=test;Integrated Security=True;Foobar="));
} }
[TestMethod] [Test]
public void ToConnectionString_ShouldReturnTransformedValueConnectionString() public void ToConnectionString_ShouldReturnTransformedValueConnectionString()
{ {
var dictionary = new Dictionary<string, string?> var dictionary = new Dictionary<string, string?>
@ -191,10 +246,10 @@ public class DictionaryTests
}; };
string connectionString = dictionary.ToConnectionString(v => v?.ToUpperInvariant()); string connectionString = dictionary.ToConnectionString(v => v?.ToUpperInvariant());
Assert.AreEqual("Data Source=LOCALHOST;Initial Catalog=TEST;Integrated Security=TRUE;Foobar=", connectionString); Assert.That(connectionString, Is.EqualTo("Data Source=LOCALHOST;Initial Catalog=TEST;Integrated Security=TRUE;Foobar="));
} }
[TestMethod] [Test]
public void ToConnectionString_ShouldReturnTransformedKeyValueConnectionString() public void ToConnectionString_ShouldReturnTransformedKeyValueConnectionString()
{ {
var dictionary = new Dictionary<string, string?> var dictionary = new Dictionary<string, string?>
@ -203,69 +258,69 @@ public class DictionaryTests
}; };
string connectionString = dictionary.ToConnectionString(k => k.ToUpper(), v => v?.ToUpperInvariant()); string connectionString = dictionary.ToConnectionString(k => k.ToUpper(), v => v?.ToUpperInvariant());
Assert.AreEqual("DATA SOURCE=LOCALHOST;INITIAL CATALOG=TEST;INTEGRATED SECURITY=TRUE;FOOBAR=", connectionString); Assert.That(connectionString, Is.EqualTo("DATA SOURCE=LOCALHOST;INITIAL CATALOG=TEST;INTEGRATED SECURITY=TRUE;FOOBAR="));
} }
[TestMethod] [Test]
public void ToConnectionString_ShouldThrow_GivenNullSource() public void ToConnectionString_ShouldThrow_GivenNullSource()
{ {
Dictionary<string, string>? dictionary = null; Dictionary<string, string> dictionary = null!;
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString()); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString());
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString(null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString(null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString(null!, null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString(null!, null!));
} }
[TestMethod] [Test]
public void ToConnectionString_ShouldThrow_GivenNullSelector() public void ToConnectionString_ShouldThrow_GivenNullSelector()
{ {
var dictionary = new Dictionary<string, string>(); var dictionary = new Dictionary<string, string>();
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString(null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(null!, _ => _)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString(null!, _ => _));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(_ => _, null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToConnectionString(_ => _, null!));
} }
[TestMethod] [Test]
public void ToGetParameters_ShouldReturnParameters() public void ToGetParameters_ShouldReturnParameters()
{ {
var dictionary = new Dictionary<string, string> {["id"] = "1", ["user"] = "hello world", ["foo"] = "bar"}; var dictionary = new Dictionary<string, string> {["id"] = "1", ["user"] = "hello world", ["foo"] = "bar"};
string queryString = dictionary.ToGetParameters(); string queryString = dictionary.ToGetParameters();
Assert.AreEqual("id=1&user=hello+world&foo=bar", queryString); Assert.That(queryString, Is.EqualTo("id=1&user=hello+world&foo=bar"));
} }
[TestMethod] [Test]
public void ToGetParameters_ShouldReturnTransformedValueParameters() public void ToGetParameters_ShouldReturnTransformedValueParameters()
{ {
var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null}; var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null};
string queryString = dictionary.ToGetParameters(v => v?.ToUpper()); string queryString = dictionary.ToGetParameters(v => v?.ToUpper());
Assert.AreEqual("id=1&user=HELLO+WORLD&foo=", queryString); Assert.That(queryString, Is.EqualTo("id=1&user=HELLO+WORLD&foo="));
} }
[TestMethod] [Test]
public void ToGetParameters_ShouldReturnTransformedKeyValueParameters() public void ToGetParameters_ShouldReturnTransformedKeyValueParameters()
{ {
var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null}; var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null};
string queryString = dictionary.ToGetParameters(k => k.ToUpper(), v => v?.ToUpper()); string queryString = dictionary.ToGetParameters(k => k.ToUpper(), v => v?.ToUpper());
Assert.AreEqual("ID=1&USER=HELLO+WORLD&FOO=", queryString); Assert.That(queryString, Is.EqualTo("ID=1&USER=HELLO+WORLD&FOO="));
} }
[TestMethod] [Test]
public void ToGetParameters_ShouldThrow_GivenNullSource() public void ToGetParameters_ShouldThrow_GivenNullSource()
{ {
Dictionary<string, string>? dictionary = null; Dictionary<string, string> dictionary = null!;
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters()); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters());
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters(null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters(null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters(null!, null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters(null!, null!));
} }
[TestMethod] [Test]
public void ToGetParameters_ShouldThrow_GivenNullSelector() public void ToGetParameters_ShouldThrow_GivenNullSelector()
{ {
var dictionary = new Dictionary<string, string>(); var dictionary = new Dictionary<string, string>();
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters(null!));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(null!, _ => _)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters(null!, _ => _));
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(_ => _, null!)); Assert.Throws<ArgumentNullException>(() => _ = dictionary.ToGetParameters(_ => _, null!));
} }
} }

View File

@ -1,15 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq;
using Moq; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class EnumerableTests public partial class EnumerableTests
{ {
[TestClass] [TestFixture]
public class DisposeAllTests public class DisposeAllTests
{ {
[TestMethod] [Test]
public void DisposeAll_ShouldDisposeAllItems_WhenCalledWithValidList() public void DisposeAll_ShouldDisposeAllItems_WhenCalledWithValidList()
{ {
var mock1 = new Mock<IDisposable>(); var mock1 = new Mock<IDisposable>();
@ -24,11 +24,11 @@ public partial class EnumerableTests
mock3.Verify(i => i.Dispose(), Times.Once); mock3.Verify(i => i.Dispose(), Times.Once);
} }
[TestMethod] [Test]
public void DisposeAll_ShouldThrowArgumentNullException_WhenCalledWithNullList() public void DisposeAll_ShouldThrowArgumentNullException_WhenCalledWithNullList()
{ {
List<IDisposable>? list = null; List<IDisposable> list = null!;
Assert.ThrowsException<ArgumentNullException>(() => list!.DisposeAll()); Assert.Throws<ArgumentNullException>(() => list.DisposeAll());
} }
} }
} }

View File

@ -1,15 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq;
using Moq; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
public partial class EnumerableTests public partial class EnumerableTests
{ {
[TestClass] [TestFixture]
public class DisposeAllAsyncTests public class DisposeAllAsyncTests
{ {
[TestMethod] [Test]
public async Task DisposeAllAsync_ShouldDisposeAllItems_WhenCalledWithValidList() public async Task DisposeAllAsync_ShouldDisposeAllItems_WhenCalledWithValidList()
{ {
var mock1 = new Mock<IAsyncDisposable>(); var mock1 = new Mock<IAsyncDisposable>();
@ -24,11 +24,11 @@ public partial class EnumerableTests
mock3.Verify(i => i.DisposeAsync(), Times.Once); mock3.Verify(i => i.DisposeAsync(), Times.Once);
} }
[TestMethod] [Test]
public async Task DisposeAllAsync_ShouldThrowArgumentNullException_WhenCalledWithNullList() public void DisposeAllAsync_ShouldThrowArgumentNullException_WhenCalledWithNullList()
{ {
List<IAsyncDisposable>? list = null; List<IAsyncDisposable> list = null!;
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() => list!.DisposeAllAsync()).ConfigureAwait(false); Assert.ThrowsAsync<ArgumentNullException>(() => list.DisposeAllAsync());
} }
} }
} }

View File

@ -1,33 +1,33 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public partial class EnumerableTests public partial class EnumerableTests
{ {
[TestMethod] [Test]
public void CountWhereNot_ShouldReturnCorrectCount_GivenSequence() public void CountWhereNot_ShouldReturnCorrectCount_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
int count = enumerable.CountWhereNot(x => x % 2 == 0); int count = enumerable.CountWhereNot(x => x % 2 == 0);
Assert.AreEqual(2, count); Assert.That(count, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void CountWhereNot_ShouldThrowArgumentNullException_GivenNullSource() public void CountWhereNot_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.CountWhereNot(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.CountWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void CountWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate() public void CountWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().CountWhereNot(null!)); Assert.Throws<ArgumentNullException>(() => Enumerable.Empty<int>().CountWhereNot(null!));
} }
[TestMethod] [Test]
public void CountWhereNot_ShouldThrowOverflowException_GivenLargeSource() public void CountWhereNot_ShouldThrowOverflowException_GivenLargeSource()
{ {
IEnumerable<byte> GetValues() IEnumerable<byte> GetValues()
@ -40,76 +40,76 @@ public partial class EnumerableTests
// ReSharper disable once IteratorNeverReturns // ReSharper disable once IteratorNeverReturns
} }
Assert.ThrowsException<OverflowException>(() => GetValues().CountWhereNot(x => x % 2 == 0)); Assert.Throws<OverflowException>(() => _ = GetValues().CountWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void FirstWhereNot_ShouldReturnCorrectElements_GivenSequence() public void FirstWhereNot_ShouldReturnCorrectElements_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
int result = enumerable.FirstWhereNot(x => x % 2 == 0); int result = enumerable.FirstWhereNot(x => x % 2 == 0);
Assert.AreEqual(7, result); Assert.That(result, Is.EqualTo(7));
} }
[TestMethod] [Test]
public void FirstWhereNot_ShouldThrowArgumentNullException_GivenNullSource() public void FirstWhereNot_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.FirstWhereNot(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => _ = ((IEnumerable<int>?)null)!.FirstWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void FirstWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate() public void FirstWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Range(0, 1).FirstWhereNot(null!)); Assert.Throws<ArgumentNullException>(() => _ = Enumerable.Range(0, 1).FirstWhereNot(null!));
} }
[TestMethod] [Test]
public void FirstWhereNot_ShouldThrowInvalidOperationException_GivenEmptySource() public void FirstWhereNot_ShouldThrowInvalidOperationException_GivenEmptySource()
{ {
Assert.ThrowsException<InvalidOperationException>(() => Enumerable.Empty<int>().FirstWhereNot(x => x % 2 == 0)); Assert.Throws<InvalidOperationException>(() => _ = Enumerable.Empty<int>().FirstWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void FirstWhereNot_ShouldThrowInvalidOperationException_GivenSourceWithNoMatchingElements() public void FirstWhereNot_ShouldThrowInvalidOperationException_GivenSourceWithNoMatchingElements()
{ {
Assert.ThrowsException<InvalidOperationException>(() => 2.AsArrayValue().FirstWhereNot(x => x % 2 == 0)); Assert.Throws<InvalidOperationException>(() => _ = 2.AsArrayValue().FirstWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void FirstWhereNotOrDefault_ShouldReturnCorrectElements_GivenSequence() public void FirstWhereNotOrDefault_ShouldReturnCorrectElements_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
int result = enumerable.FirstWhereNotOrDefault(x => x % 2 == 0); int result = enumerable.FirstWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(7, result); Assert.That(result, Is.EqualTo(7));
} }
[TestMethod] [Test]
public void FirstWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullSource() public void FirstWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.FirstWhereNotOrDefault(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => _ = ((IEnumerable<int>?)null)!.FirstWhereNotOrDefault(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void FirstWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullPredicate() public void FirstWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().FirstWhereNotOrDefault(null!)); Assert.Throws<ArgumentNullException>(() => _ = Enumerable.Empty<int>().FirstWhereNotOrDefault(null!));
} }
[TestMethod] [Test]
public void FirstWhereNotOrDefault_ShouldReturnDefault_GivenEmptySource() public void FirstWhereNotOrDefault_ShouldReturnDefault_GivenEmptySource()
{ {
int result = Enumerable.Empty<int>().FirstWhereNotOrDefault(x => x % 2 == 0); int result = Enumerable.Empty<int>().FirstWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(default, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void FirstWhereNotOrDefault_ShouldReturnDefault_GivenSourceWithNoMatchingElements() public void FirstWhereNotOrDefault_ShouldReturnDefault_GivenSourceWithNoMatchingElements()
{ {
int result = 2.AsArrayValue().FirstWhereNotOrDefault(x => x % 2 == 0); int result = 2.AsArrayValue().FirstWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(default, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void For_ShouldTransform_GivenTransformationDelegate() public void For_ShouldTransform_GivenTransformationDelegate()
{ {
var oneToTen = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var oneToTen = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@ -124,21 +124,21 @@ public partial class EnumerableTests
CollectionAssert.AreEqual(multipliedByIndex, values.ToArray()); CollectionAssert.AreEqual(multipliedByIndex, values.ToArray());
} }
[TestMethod] [Test]
public void For_ShouldThrow_GivenNullSource() public void For_ShouldThrow_GivenNullSource()
{ {
IEnumerable<object>? source = null; IEnumerable<object>? source = null;
Assert.ThrowsException<ArgumentNullException>(() => source!.For((_, _) => { })); Assert.Throws<ArgumentNullException>(() => source!.For((_, _) => { }));
} }
[TestMethod] [Test]
public void For_ShouldThrow_GivenNullAction() public void For_ShouldThrow_GivenNullAction()
{ {
IEnumerable<object> source = ArraySegment<object>.Empty; IEnumerable<object> source = ArraySegment<object>.Empty;
Assert.ThrowsException<ArgumentNullException>(() => source.For(null!)); Assert.Throws<ArgumentNullException>(() => source.For(null!));
} }
[TestMethod] [Test]
public void ForEach_ShouldTransform_GivenTransformationDelegate() public void ForEach_ShouldTransform_GivenTransformationDelegate()
{ {
var oneToTen = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var oneToTen = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@ -153,93 +153,93 @@ public partial class EnumerableTests
CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray()); CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray());
} }
[TestMethod] [Test]
public void ForEach_ShouldThrow_GivenNullSource() public void ForEach_ShouldThrow_GivenNullSource()
{ {
IEnumerable<object>? source = null; IEnumerable<object>? source = null;
Assert.ThrowsException<ArgumentNullException>(() => source!.ForEach(_ => { })); Assert.Throws<ArgumentNullException>(() => source!.ForEach(_ => { }));
} }
[TestMethod] [Test]
public void ForEach_ShouldThrow_GivenNullAction() public void ForEach_ShouldThrow_GivenNullAction()
{ {
IEnumerable<object> source = ArraySegment<object>.Empty; IEnumerable<object> source = ArraySegment<object>.Empty;
Assert.ThrowsException<ArgumentNullException>(() => source.ForEach(null!)); Assert.Throws<ArgumentNullException>(() => source.ForEach(null!));
} }
[TestMethod] [Test]
public void LastWhereNot_ShouldReturnCorrectElements_GivenSequence() public void LastWhereNot_ShouldReturnCorrectElements_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
int result = enumerable.LastWhereNot(x => x % 2 == 0); int result = enumerable.LastWhereNot(x => x % 2 == 0);
Assert.AreEqual(9, result); Assert.That(result, Is.EqualTo(9));
} }
[TestMethod] [Test]
public void LastWhereNot_ShouldThrowArgumentNullException_GivenNullSource() public void LastWhereNot_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.LastWhereNot(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => _ = ((IEnumerable<int>?)null)!.LastWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void LastWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate() public void LastWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Array.Empty<int>().LastWhereNot(null!)); Assert.Throws<ArgumentNullException>(() => _ = Array.Empty<int>().LastWhereNot(null!));
} }
[TestMethod] [Test]
public void LastWhereNot_ShouldThrowInvalidOperationException_GivenEmptySource() public void LastWhereNot_ShouldThrowInvalidOperationException_GivenEmptySource()
{ {
Assert.ThrowsException<InvalidOperationException>(() => Array.Empty<int>().LastWhereNot(x => x % 2 == 0)); Assert.Throws<InvalidOperationException>(() => _ = Array.Empty<int>().LastWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void LastWhereNot_ShouldThrowInvalidOperationException_GivenSourceWithNoMatchingElements() public void LastWhereNot_ShouldThrowInvalidOperationException_GivenSourceWithNoMatchingElements()
{ {
Assert.ThrowsException<InvalidOperationException>(() => 2.AsArrayValue().LastWhereNot(x => x % 2 == 0)); Assert.Throws<InvalidOperationException>(() => _ = 2.AsArrayValue().LastWhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void LastWhereNotOrDefault_ShouldReturnCorrectElements_GivenSequence() public void LastWhereNotOrDefault_ShouldReturnCorrectElements_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
int result = enumerable.LastWhereNotOrDefault(x => x % 2 == 0); int result = enumerable.LastWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(9, result); Assert.That(result, Is.EqualTo(9));
} }
[TestMethod] [Test]
public void LastWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullSource() public void LastWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.LastWhereNotOrDefault(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => _ = ((IEnumerable<int>?)null)!.LastWhereNotOrDefault(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void LastWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullPredicate() public void LastWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Array.Empty<int>().LastWhereNotOrDefault(null!)); Assert.Throws<ArgumentNullException>(() => _ = Array.Empty<int>().LastWhereNotOrDefault(null!));
} }
[TestMethod] [Test]
public void LastWhereNotOrDefault_ShouldReturnDefault_GivenEmptySource() public void LastWhereNotOrDefault_ShouldReturnDefault_GivenEmptySource()
{ {
int result = Array.Empty<int>().LastWhereNotOrDefault(x => x % 2 == 0); int result = Array.Empty<int>().LastWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(default, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void LastWhereNotOrDefault_ShouldReturnDefault_GivenSourceWithNoMatchingElements() public void LastWhereNotOrDefault_ShouldReturnDefault_GivenSourceWithNoMatchingElements()
{ {
int result = 2.AsArrayValue().LastWhereNotOrDefault(x => x % 2 == 0); int result = 2.AsArrayValue().LastWhereNotOrDefault(x => x % 2 == 0);
Assert.AreEqual(default, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void Shuffled_ShouldThrow_GivenNull() public void Shuffled_ShouldThrow_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Shuffled()); Assert.Throws<ArgumentNullException>(() => _ = ((List<int>?)null)!.Shuffled());
} }
[TestMethod] [Test]
public void Shuffled_ShouldReorder_GivenNotNull() public void Shuffled_ShouldReorder_GivenNotNull()
{ {
int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order
@ -251,7 +251,7 @@ public partial class EnumerableTests
CollectionAssert.AreNotEqual(array, shuffled); CollectionAssert.AreNotEqual(array, shuffled);
} }
[TestMethod] [Test]
public void WhereNot_ShouldReturnCorrectElements_GivenSequence() public void WhereNot_ShouldReturnCorrectElements_GivenSequence()
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
@ -259,19 +259,19 @@ public partial class EnumerableTests
CollectionAssert.AreEqual(new[] {7, 9}, result.ToArray()); CollectionAssert.AreEqual(new[] {7, 9}, result.ToArray());
} }
[TestMethod] [Test]
public void WhereNot_ShouldThrowArgumentNullException_GivenNullSource() public void WhereNot_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.WhereNot(x => x % 2 == 0)); Assert.Throws<ArgumentNullException>(() => _ = ((IEnumerable<int>?)null)!.WhereNot(x => x % 2 == 0));
} }
[TestMethod] [Test]
public void WhereNot_ShouldThrowArgumentNullException_GivenNullPredicate() public void WhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().WhereNot(null!)); Assert.Throws<ArgumentNullException>(() => _ = Enumerable.Empty<int>().WhereNot(null!));
} }
[TestMethod] [Test]
public void WhereNotNull_ShouldContainNoNullElements() public void WhereNotNull_ShouldContainNoNullElements()
{ {
object?[] array = Enumerable.Repeat(new object(), 10).ToArray(); object?[] array = Enumerable.Repeat(new object(), 10).ToArray();
@ -289,14 +289,14 @@ public partial class EnumerableTests
actualCount++; actualCount++;
} }
Assert.AreEqual(expectedCount, actualCount); Assert.That(actualCount, Is.EqualTo(expectedCount));
} }
[TestMethod] [Test]
public void WhereNotNull_ShouldThrowArgumentNullException_GivenNullSource() public void WhereNotNull_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<string> source = null!; IEnumerable<string> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.WhereNotNull()); Assert.Throws<ArgumentNullException>(() => source.WhereNotNull());
} }
private class DummyClass private class DummyClass

View File

@ -1,119 +1,131 @@
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class Int16Tests public class Int16Tests
{ {
[TestMethod] [Test]
public void Unpack_ShouldUnpackToArrayCorrectly() public void Unpack_ShouldUnpackToArrayCorrectly()
{
Assert.Multiple(() =>
{ {
const short value = 0b11010100; const short value = 0b11010100;
bool[] bits = value.Unpack(); bool[] bits = value.Unpack();
Assert.AreEqual(16, bits.Length); Assert.That(bits, Has.Length.EqualTo(16));
Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[0]); Assert.That(bits[1], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[2], Is.True);
Assert.IsTrue(bits[2]); Assert.That(bits[3], Is.False);
Assert.IsFalse(bits[3]); Assert.That(bits[4], Is.True);
Assert.IsTrue(bits[4]); Assert.That(bits[5], Is.False);
Assert.IsFalse(bits[5]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[6]); Assert.That(bits[7], Is.True);
Assert.IsTrue(bits[7]);
for (var index = 8; index < 16; index++) for (var index = 8; index < 16; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
[TestMethod] [Test]
public void Unpack_ShouldUnpackToSpanCorrectly() public void Unpack_ShouldUnpackToSpanCorrectly()
{ {
const short value = 0b11010100; const short value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[16]; Span<bool> bits = stackalloc bool[16];
value.Unpack(bits); value.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 16; index++) for (var index = 8; index < 16; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
[TestMethod] [Test]
public void Unpack_ShouldUnpackToSpanCorrectly_GivenFallbackImplementation() public void Unpack_ShouldUnpackToSpanCorrectly_GivenFallbackImplementation()
{ {
const short value = 0b11010100; const short value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[16]; Span<bool> bits = stackalloc bool[16];
value.UnpackInternal_Fallback(bits); value.UnpackInternal_Fallback(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 16; index++) for (var index = 8; index < 16; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[TestMethod] [Test]
public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly()
{ {
if (!Sse3.IsSupported) if (!Sse3.IsSupported)
{ {
Assert.Pass();
return; return;
} }
const short value = 0b11010100; const short value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[16]; Span<bool> bits = stackalloc bool[16];
value.UnpackInternal_Ssse3(bits); value.UnpackInternal_Ssse3(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 16; index++) for (var index = 8; index < 16; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
#endif #endif
[TestMethod] [Test]
public void Unpack_ShouldRepackEqually() public void Unpack_ShouldRepackEqually()
{ {
const short value = 0b11010100; const short value = 0b11010100;
Assert.AreEqual(value, value.Unpack().PackInt16()); Assert.That(value.Unpack().PackInt16(), Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Unpack_ShouldThrow_GivenTooSmallSpan() public void Unpack_ShouldThrow_GivenTooSmallSpan()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
const short value = 0b11010100; const short value = 0b11010100;
Span<bool> bits = stackalloc bool[0]; Span<bool> bits = stackalloc bool[0];

View File

@ -1,81 +1,90 @@
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class Int32Tests public class Int32Tests
{ {
[TestMethod] [Test]
public void Unpack_ShouldUnpackToArrayCorrectly() public void Unpack_ShouldUnpackToArrayCorrectly()
{ {
const int value = 0b11010100; const int value = 0b11010100;
Assert.Multiple(() =>
{
bool[] bits = value.Unpack(); bool[] bits = value.Unpack();
Assert.That(bits, Has.Length.EqualTo(32));
Assert.AreEqual(32, bits.Length); Assert.That(bits[0], Is.False);
Assert.That(bits[1], Is.False);
Assert.IsFalse(bits[0]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[1]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[6], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[7], Is.True);
Assert.IsTrue(bits[6]);
Assert.IsTrue(bits[7]);
for (var index = 8; index < 32; index++) for (var index = 8; index < 32; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
[TestMethod] [Test]
public void Unpack_ShouldUnpackToSpanCorrectly() public void Unpack_ShouldUnpackToSpanCorrectly()
{ {
const int value = 0b11010100; const int value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[32]; Span<bool> bits = stackalloc bool[32];
value.Unpack(bits); value.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 32; index++) for (var index = 8; index < 32; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
[TestMethod] [Test]
public void UnpackInternal_Fallback_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Fallback_ShouldUnpackToSpanCorrectly()
{ {
const int value = 0b11010100; const int value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[32]; Span<bool> bits = stackalloc bool[32];
value.UnpackInternal_Fallback(bits); value.UnpackInternal_Fallback(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 32; index++) for (var index = 8; index < 32; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[TestMethod] [Test]
public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Ssse3_ShouldUnpackToSpanCorrectly()
{ {
if (!Ssse3.IsSupported) if (!Ssse3.IsSupported)
@ -84,25 +93,28 @@ public class Int32Tests
} }
const int value = 0b11010100; const int value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[32]; Span<bool> bits = stackalloc bool[32];
value.UnpackInternal_Ssse3(bits); value.UnpackInternal_Ssse3(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 32; index++) for (var index = 8; index < 32; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
[TestMethod] [Test]
public void UnpackInternal_Avx2_ShouldUnpackToSpanCorrectly() public void UnpackInternal_Avx2_ShouldUnpackToSpanCorrectly()
{ {
if (!Avx2.IsSupported) if (!Avx2.IsSupported)
@ -111,36 +123,39 @@ public class Int32Tests
} }
const int value = 0b11010100; const int value = 0b11010100;
Assert.Multiple(() =>
{
Span<bool> bits = stackalloc bool[32]; Span<bool> bits = stackalloc bool[32];
value.UnpackInternal_Avx2(bits); value.UnpackInternal_Avx2(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 32; index++) for (var index = 8; index < 32; index++)
{ {
Assert.IsFalse(bits[index]); Assert.That(bits[index], Is.False);
} }
});
} }
#endif #endif
[TestMethod] [Test]
public void Unpack_ShouldRepackEqually() public void Unpack_ShouldRepackEqually()
{ {
const int value = 0b11010100; const int value = 0b11010100;
Assert.AreEqual(value, value.Unpack().PackInt32()); Assert.That(value.Unpack().PackInt32(), Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Unpack_ShouldThrow_GivenTooSmallSpan() public void Unpack_ShouldThrow_GivenTooSmallSpan()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
const int value = 0b11010100; const int value = 0b11010100;
Span<bool> bits = stackalloc bool[0]; Span<bool> bits = stackalloc bool[0];

View File

@ -1,68 +1,73 @@
using System.Diagnostics; using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class Int64Tests public class Int64Tests
{ {
[TestMethod] [Test]
public void UnpackBits_ShouldUnpackToArrayCorrectly() public void UnpackBits_ShouldUnpackToArrayCorrectly()
{ {
bool[] bits = 0b11010100L.Unpack(); bool[] bits = 0b11010100L.Unpack();
Assert.AreEqual(64, bits.Length); Assert.That(bits, Has.Length.EqualTo(64));
Trace.WriteLine(Convert.ToString(0b11010100L, 2)); Trace.WriteLine(Convert.ToString(0b11010100L, 2));
Trace.WriteLine(string.Join("", bits.Select(b => b ? "1" : "0"))); Trace.WriteLine(string.Join("", bits.Select(b => b ? "1" : "0")));
Assert.Multiple(() =>
Assert.IsFalse(bits[0]); {
Assert.IsFalse(bits[1]); Assert.That(bits[0], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[1], Is.False);
Assert.IsFalse(bits[3]); Assert.That(bits[2], Is.True);
Assert.IsTrue(bits[4]); Assert.That(bits[3], Is.False);
Assert.IsFalse(bits[5]); Assert.That(bits[4], Is.True);
Assert.IsTrue(bits[6]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[7]); Assert.That(bits[6], Is.True);
Assert.That(bits[7], Is.True);
for (var index = 8; index < 64; index++) for (var index = 8; index < 64; index++)
{ {
Assert.IsFalse(bits[index], index.ToString()); Assert.That(bits[index], Is.False, index.ToString());
} }
});
} }
[TestMethod] [Test]
public void UnpackBits_ShouldUnpackToSpanCorrectly() public void UnpackBits_ShouldUnpackToSpanCorrectly()
{
Assert.Multiple(() =>
{ {
Span<bool> bits = stackalloc bool[64]; Span<bool> bits = stackalloc bool[64];
0b11010100L.Unpack(bits); 0b11010100L.Unpack(bits);
Assert.IsFalse(bits[0]); Assert.That(bits[0], Is.False);
Assert.IsFalse(bits[1]); Assert.That(bits[1], Is.False);
Assert.IsTrue(bits[2]); Assert.That(bits[2], Is.True);
Assert.IsFalse(bits[3]); Assert.That(bits[3], Is.False);
Assert.IsTrue(bits[4]); Assert.That(bits[4], Is.True);
Assert.IsFalse(bits[5]); Assert.That(bits[5], Is.False);
Assert.IsTrue(bits[6]); Assert.That(bits[6], Is.True);
Assert.IsTrue(bits[7]); Assert.That(bits[7], Is.True);
for (var index = 8; index < 64; index++) for (var index = 8; index < 64; index++)
{ {
Assert.IsFalse(bits[index], index.ToString()); Assert.That(bits[index], Is.False, index.ToString());
} }
});
} }
[TestMethod] [Test]
public void UnpackBits_ShouldRepackEqually() public void UnpackBits_ShouldRepackEqually()
{ {
Assert.AreEqual(0b11010100L, 0b11010100L.Unpack().PackInt64()); Assert.That(0b11010100L.Unpack().PackInt64(), Is.EqualTo(0b11010100L));
} }
[TestMethod] [Test]
public void UnpackBits_ShouldThrow_GivenTooSmallSpan() public void UnpackBits_ShouldThrow_GivenTooSmallSpan()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
Span<bool> bits = stackalloc bool[0]; Span<bool> bits = stackalloc bool[0];
0b11010100L.Unpack(bits); 0b11010100L.Unpack(bits);

View File

@ -1,16 +1,16 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class ListTests public class ListTests
{ {
[CLSCompliant(false)] [CLSCompliant(false)]
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow(1, 2, 3)] [TestCase(1, 2, 3)]
[DataRow(1, 2, 3, 4, 5)] [TestCase(1, 2, 3, 4, 5)]
public void Fill_ShouldGiveHomogenousList_GivenValue(params int[] args) public void Fill_ShouldGiveHomogenousList_GivenValue(params int[] args)
{ {
int[] all42 = Enumerable.Repeat(42, args.Length).ToArray(); int[] all42 = Enumerable.Repeat(42, args.Length).ToArray();
@ -27,154 +27,169 @@ public class ListTests
} }
[CLSCompliant(false)] [CLSCompliant(false)]
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow(1, 2, 3)] [TestCase(1, 2, 3)]
[DataRow(1, 2, 3, 4, 5)] [TestCase(1, 2, 3, 4, 5)]
public void SlicedFill_ShouldLeaveFirstElement_GivenStartIndex1(params int[] args) public void SlicedFill_ShouldLeaveFirstElement_GivenStartIndex1(params int[] args)
{ {
int first = args[0]; int first = args[0];
args.Fill(1, 1, args.Length - 1); args.Fill(1, 1, args.Length - 1);
int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray(); int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray();
Assert.AreEqual(first, args[0]); Assert.That(args[0], Is.EqualTo(first));
CollectionAssert.AreEqual(comparison, args[1..]); CollectionAssert.AreEqual(comparison, args[1..]);
} }
[TestMethod] [Test]
public void Fill_ShouldThrow_GivenExceededCount() public void Fill_ShouldThrow_GivenExceededCount()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
var list = new List<int>(); var list = new List<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Fill(0, 0, 1)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, 0, 1));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => list.Fill(0, 0, 1)); Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, 0, 1));
} }
[TestMethod] [Test]
public void Fill_ShouldThrow_GivenNegativeCount() public void Fill_ShouldThrow_GivenNegativeCount()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
var list = new List<int>(); var list = new List<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Fill(0, 0, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, 0, -1));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => list.Fill(0, 0, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, 0, -1));
} }
[TestMethod] [Test]
public void Fill_ShouldThrow_GivenNegativeStartIndex() public void Fill_ShouldThrow_GivenNegativeStartIndex()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
var list = new List<int>(); var list = new List<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Fill(0, -1, 0)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, -1, 0));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => list.Fill(0, -1, 0)); Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, -1, 0));
} }
[TestMethod] [Test]
public void Fill_ShouldThrow_GivenNull() public void Fill_ShouldThrow_GivenNull()
{ {
int[]? array = null; int[]? array = null;
List<int>? list = null; List<int>? list = null;
Assert.ThrowsException<ArgumentNullException>(() => array!.Fill(0)); Assert.Throws<ArgumentNullException>(() => array!.Fill(0));
Assert.ThrowsException<ArgumentNullException>(() => list!.Fill(0)); Assert.Throws<ArgumentNullException>(() => list!.Fill(0));
Assert.ThrowsException<ArgumentNullException>(() => array!.Fill(0, 0, 0)); Assert.Throws<ArgumentNullException>(() => array!.Fill(0, 0, 0));
Assert.ThrowsException<ArgumentNullException>(() => list!.Fill(0, 0, 0)); Assert.Throws<ArgumentNullException>(() => list!.Fill(0, 0, 0));
} }
[TestMethod] [Test]
public void IndexOf_ShouldReturnCorrectValue_FromStartOfList() public void IndexOf_ShouldReturnCorrectValue_FromStartOfList()
{ {
int[] array = {0, 1, 2, 3, 4}; int[] array = {0, 1, 2, 3, 4};
Assert.AreEqual(2, array.IndexOf(2)); Assert.Multiple(() =>
Assert.AreEqual(2, array.IndexOf(2, 0)); {
Assert.AreEqual(2, array.IndexOf(2, 0, 5)); Assert.That(array.IndexOf(2), Is.EqualTo(2));
Assert.That(array.IndexOf(2, 0), Is.EqualTo(2));
Assert.That(array.IndexOf(2, 0, 5), Is.EqualTo(2));
});
} }
[TestMethod] [Test]
public void IndexOf_ShouldReturnCorrectValue_GivenSubRange() public void IndexOf_ShouldReturnCorrectValue_GivenSubRange()
{ {
int[] array = {0, 1, 2, 3, 4, 0}; int[] array = {0, 1, 2, 3, 4, 0};
Assert.AreEqual(0, array.IndexOf(0)); Assert.Multiple(() =>
Assert.AreEqual(0, array.IndexOf(0, 0)); {
Assert.AreEqual(0, array.IndexOf(0, 0, 5)); Assert.That(array.IndexOf(0), Is.Zero);
Assert.That(array.IndexOf(0, 0), Is.Zero);
Assert.That(array.IndexOf(0, 0, 5), Is.Zero);
Assert.AreEqual(5, array.IndexOf(0, 1)); Assert.That(array.IndexOf(0, 1), Is.EqualTo(5));
Assert.AreEqual(5, array.IndexOf(0, 1, 5)); Assert.That(array.IndexOf(0, 1, 5), Is.EqualTo(5));
});
} }
[TestMethod] [Test]
public void IndexOf_ShouldReturnNegative1_ForEmptyList() public void IndexOf_ShouldReturnNegative1_ForEmptyList()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
Assert.AreEqual(-1, array.IndexOf(0)); Assert.Multiple(() =>
Assert.AreEqual(-1, array.IndexOf(0, 0)); {
Assert.AreEqual(-1, array.IndexOf(0, 0, 0)); Assert.That(array.IndexOf(0), Is.EqualTo(-1));
Assert.That(array.IndexOf(0, 0), Is.EqualTo(-1));
Assert.That(array.IndexOf(0, 0, 0), Is.EqualTo(-1));
});
} }
[TestMethod] [Test]
public void IndexOf_ShouldThrowArgumentNullException_GivenNullList() public void IndexOf_ShouldThrowArgumentNullException_GivenNullList()
{ {
int[]? array = null; int[]? array = null;
Assert.ThrowsException<ArgumentNullException>(() => array!.IndexOf(0)); Assert.Multiple(() =>
Assert.ThrowsException<ArgumentNullException>(() => array!.IndexOf(0, 0)); {
Assert.ThrowsException<ArgumentNullException>(() => array!.IndexOf(0, 0, 0)); Assert.Throws<ArgumentNullException>(() => array!.IndexOf(0));
Assert.Throws<ArgumentNullException>(() => array!.IndexOf(0, 0));
Assert.Throws<ArgumentNullException>(() => array!.IndexOf(0, 0, 0));
});
} }
[TestMethod] [Test]
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount() public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.IndexOf(0, 0, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 0, -1));
} }
[TestMethod] [Test]
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex() public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.IndexOf(0, -1)); Assert.Multiple(() =>
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.IndexOf(0, -1, 0)); {
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, -1, 0));
});
} }
[TestMethod] [Test]
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{ {
int[] array = {0, 1, 2}; int[] array = {0, 1, 2};
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4)); Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4));
} }
[TestMethod] [Test]
public void Random_ShouldReturnContainedObject_GivenNotNull() public void Random_ShouldReturnContainedObject_GivenNotNull()
{ {
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
int random = list.Random(); int random = list.Random();
Assert.IsTrue(list.Contains(random)); Assert.That(list, Does.Contain(random));
} }
[TestMethod] [Test]
public void Random_ShouldThrow_GivenNull() public void Random_ShouldThrow_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Random()); Assert.Throws<ArgumentNullException>(() => _ = ((List<int>?)null)!.Random());
} }
[TestMethod] [Test]
public void RemoveRange_ShouldThrowArgumentNullException_GivenNull() public void RemoveRange_ShouldThrowArgumentNullException_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.RemoveRange(new Range())); Assert.Throws<ArgumentNullException>(() => ((List<int>?)null)!.RemoveRange(new Range()));
} }
[TestMethod] [Test]
public void RemoveRange_ShouldThrowArgumentException_GivenEndIndexLessThanStart() public void RemoveRange_ShouldThrowArgumentException_GivenEndIndexLessThanStart()
{ {
Assert.ThrowsException<ArgumentException>(() => new List<int>().RemoveRange(2..0)); Assert.Throws<ArgumentException>(() => new List<int>().RemoveRange(2..0));
} }
[TestMethod] [Test]
public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount() public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount()
{ {
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0)); Assert.Throws<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new List<int> {1}.RemoveRange(..2)); Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> {1}.RemoveRange(..2));
} }
[TestMethod] [Test]
public void RemoveRange_ShouldRemoveElements_GivenList() public void RemoveRange_ShouldRemoveElements_GivenList()
{ {
var list = new List<int> var list = new List<int>
@ -191,13 +206,14 @@ public class ListTests
10 10
}; };
Assert.AreEqual(10, list.Count); Assert.That(list, Has.Count.EqualTo(10));
list.RemoveRange(2..5); list.RemoveRange(2..5);
Assert.AreEqual(6, list.Count);
Assert.That(list, Has.Count.EqualTo(6));
CollectionAssert.AreEqual(new[] {1, 2, 7, 8, 9, 10}, list); CollectionAssert.AreEqual(new[] {1, 2, 7, 8, 9, 10}, list);
} }
[TestMethod] [Test]
public void Shuffle_ShouldReorder_GivenNotNull() public void Shuffle_ShouldReorder_GivenNotNull()
{ {
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
@ -210,27 +226,27 @@ public class ListTests
CollectionAssert.AreNotEqual(list, shuffled); CollectionAssert.AreNotEqual(list, shuffled);
} }
[TestMethod] [Test]
public void Shuffle_ShouldThrow_GivenNull() public void Shuffle_ShouldThrow_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((List<int>?)null)!.Shuffle()); Assert.Throws<ArgumentNullException>(() => ((List<int>?)null)!.Shuffle());
} }
[TestMethod] [Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndex() public void Slice_ShouldReturnCorrectValue_GivenStartIndex()
{ {
int[] array = {0, 1, 2, 3, 4, 5}; int[] array = {0, 1, 2, 3, 4, 5};
CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray()); CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray());
} }
[TestMethod] [Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength() public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength()
{ {
int[] array = {0, 1, 2, 3, 4, 5}; int[] array = {0, 1, 2, 3, 4, 5};
CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray()); CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray());
} }
[TestMethod] [Test]
public void Slice_ShouldReturnEmptyList_ForEmptyList() public void Slice_ShouldReturnEmptyList_ForEmptyList()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
@ -238,49 +254,49 @@ public class ListTests
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0, 0).ToArray()); CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0, 0).ToArray());
} }
[TestMethod] [Test]
public void Slice_ShouldThrowArgumentNullException_GivenNullList() public void Slice_ShouldThrowArgumentNullException_GivenNullList()
{ {
int[]? array = null; int[]? array = null;
Assert.ThrowsException<ArgumentNullException>(() => array!.Slice(0)); Assert.Throws<ArgumentNullException>(() => array!.Slice(0));
Assert.ThrowsException<ArgumentNullException>(() => array!.Slice(0, 0)); Assert.Throws<ArgumentNullException>(() => array!.Slice(0, 0));
} }
[TestMethod] [Test]
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount() public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Slice(0, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(0, -1));
} }
[TestMethod] [Test]
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex() public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Slice(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(-1));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Slice(-1, 0)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(-1, 0));
} }
[TestMethod] [Test]
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{ {
int[] array = {0, 1, 2}; int[] array = {0, 1, 2};
Assert.ThrowsException<ArgumentOutOfRangeException>(() => array.Slice(2, 4)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(2, 4));
} }
[TestMethod] [Test]
public void Swap_ShouldThrowArgumentNullException_GivenNullSource() public void Swap_ShouldThrowArgumentNullException_GivenNullSource()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((IList<int>?)null)!.Swap(new List<int>())); Assert.Throws<ArgumentNullException>(() => ((IList<int>?)null)!.Swap(new List<int>()));
} }
[TestMethod] [Test]
public void Swap_ShouldThrowArgumentNullException_GivenNullTarget() public void Swap_ShouldThrowArgumentNullException_GivenNullTarget()
{ {
Assert.ThrowsException<ArgumentNullException>(() => new List<int>().Swap(null!)); Assert.Throws<ArgumentNullException>(() => new List<int>().Swap(null!));
} }
[TestMethod] [Test]
public void Swap_ShouldSwapElements_GivenMatchingElementCount() public void Swap_ShouldSwapElements_GivenMatchingElementCount()
{ {
var first = new List<int> {1, 2, 3}; var first = new List<int> {1, 2, 3};
@ -297,7 +313,7 @@ public class ListTests
CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second)); CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second));
} }
[TestMethod] [Test]
public void Swap_ShouldSwapElements_GivenDifferentElementCount() public void Swap_ShouldSwapElements_GivenDifferentElementCount()
{ {
var first = new List<int> var first = new List<int>

View File

@ -1,52 +1,52 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
namespace X10D.Tests.Collections; namespace X10D.Tests.Collections;
[TestClass] [TestFixture]
public class SpanTest public class SpanTest
{ {
[TestMethod] [Test]
public void Count_ShouldReturn0_GivenEmptySpan() public void Count_ShouldReturn0_GivenEmptySpan()
{ {
Span<int> span = Span<int>.Empty; Span<int> span = Span<int>.Empty;
int count = span.Count(2); int count = span.Count(2);
Assert.AreEqual(0, count); Assert.That(count, Is.Zero);
} }
[TestMethod] [Test]
public void Count_ShouldReturn0_GivenEmptyReadOnlySpan() public void Count_ShouldReturn0_GivenEmptyReadOnlySpan()
{ {
ReadOnlySpan<int> span = ReadOnlySpan<int>.Empty; ReadOnlySpan<int> span = ReadOnlySpan<int>.Empty;
int count = span.Count(2); int count = span.Count(2);
Assert.AreEqual(0, count); Assert.That(count, Is.Zero);
} }
[TestMethod] [Test]
public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() public void Count_ShouldReturn8_GivenSpanWith8MatchingElements()
{ {
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
int count = span.Count(2); int count = span.Count(2);
Assert.AreEqual(8, count); Assert.That(count, Is.EqualTo(8));
} }
[TestMethod] [Test]
public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements()
{ {
ReadOnlySpan<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; ReadOnlySpan<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
int count = span.Count(2); int count = span.Count(2);
Assert.AreEqual(8, count); Assert.That(count, Is.EqualTo(8));
} }
[TestMethod] [Test]
public void Split_OnEmptySpan_ShouldYieldNothing_UsingCharDelimiter_GivenReadOnlySpan() public void Split_OnEmptySpan_ShouldYieldNothing_UsingCharDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = ReadOnlySpan<char>.Empty; ReadOnlySpan<char> span = ReadOnlySpan<char>.Empty;
@ -57,10 +57,10 @@ public class SpanTest
index++; index++;
} }
Assert.AreEqual(0, index); Assert.That(index, Is.Zero);
} }
[TestMethod] [Test]
public void Split_OnEmptySpan_ShouldYieldNothing_UsingCharDelimiter_GivenSpan() public void Split_OnEmptySpan_ShouldYieldNothing_UsingCharDelimiter_GivenSpan()
{ {
Span<char> span = Span<char>.Empty; Span<char> span = Span<char>.Empty;
@ -71,10 +71,10 @@ public class SpanTest
index++; index++;
} }
Assert.AreEqual(0, index); Assert.That(index, Is.Zero);
} }
[TestMethod] [Test]
public void Split_OnEmptySpan_ShouldYieldNothing_UsingStringDelimiter_GivenReadOnlySpan() public void Split_OnEmptySpan_ShouldYieldNothing_UsingStringDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = ReadOnlySpan<char>.Empty; ReadOnlySpan<char> span = ReadOnlySpan<char>.Empty;
@ -85,10 +85,10 @@ public class SpanTest
index++; index++;
} }
Assert.AreEqual(0, index); Assert.That(index, Is.Zero);
} }
[TestMethod] [Test]
public void Split_OnEmptySpan_ShouldYieldNothing_UsingStringDelimiter_GivenSpan() public void Split_OnEmptySpan_ShouldYieldNothing_UsingStringDelimiter_GivenSpan()
{ {
Span<char> span = Span<char>.Empty; Span<char> span = Span<char>.Empty;
@ -99,10 +99,10 @@ public class SpanTest
index++; index++;
} }
Assert.AreEqual(0, index); Assert.That(index, Is.Zero);
} }
[TestMethod] [Test]
public void Split_OnOneWord_ShouldYieldLength1_UsingCharDelimiter_GivenReadOnlySpan() public void Split_OnOneWord_ShouldYieldLength1_UsingCharDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello ".AsSpan(); ReadOnlySpan<char> span = "Hello ".AsSpan();
@ -112,16 +112,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWord_ShouldYieldLength1_UsingCharDelimiter_GivenSpan() public void Split_OnOneWord_ShouldYieldLength1_UsingCharDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello ".AsSpan(); ReadOnlySpan<char> source = "Hello ".AsSpan();
@ -133,16 +133,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWord_ShouldYieldLength1_UsingStringDelimiter_GivenReadOnlySpan() public void Split_OnOneWord_ShouldYieldLength1_UsingStringDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello ".AsSpan(); ReadOnlySpan<char> span = "Hello ".AsSpan();
@ -152,16 +152,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWord_ShouldYieldLength1_UsingStringDelimiter_GivenSpan() public void Split_OnOneWord_ShouldYieldLength1_UsingStringDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello ".AsSpan(); ReadOnlySpan<char> source = "Hello ".AsSpan();
@ -173,16 +173,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingCharDelimiter_GivenReadOnlySpan() public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingCharDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello".AsSpan(); ReadOnlySpan<char> span = "Hello".AsSpan();
@ -192,16 +192,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingCharDelimiter_GivenSpan() public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingCharDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello".AsSpan(); ReadOnlySpan<char> source = "Hello".AsSpan();
@ -213,16 +213,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingStringDelimiter_GivenReadOnlySpan() public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingStringDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello".AsSpan(); ReadOnlySpan<char> span = "Hello".AsSpan();
@ -232,16 +232,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingStringDelimiter_GivenSpan() public void Split_OnOneWordWithoutDelimiter_ShouldYieldLength1_UsingStringDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello".AsSpan(); ReadOnlySpan<char> source = "Hello".AsSpan();
@ -253,16 +253,16 @@ public class SpanTest
{ {
if (index == 0) if (index == 0)
{ {
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
} }
index++; index++;
} }
Assert.AreEqual(1, index); Assert.That(index, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Split_OnTwoWords_ShouldYieldLength2_UsingCharDelimiter_GivenReadOnlySpan() public void Split_OnTwoWords_ShouldYieldLength2_UsingCharDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello World ".AsSpan(); ReadOnlySpan<char> span = "Hello World ".AsSpan();
@ -273,20 +273,20 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
break; break;
case 1: case 1:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(2, index); Assert.That(index, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Split_OnTwoWords_ShouldYieldLength2_UsingCharDelimiter_GivenSpan() public void Split_OnTwoWords_ShouldYieldLength2_UsingCharDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello World ".AsSpan(); ReadOnlySpan<char> source = "Hello World ".AsSpan();
@ -299,20 +299,20 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
break; break;
case 1: case 1:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(2, index); Assert.That(index, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Split_OnTwoWords_ShouldYieldLength2_UsingStringDelimiter_GivenReadOnlySpan() public void Split_OnTwoWords_ShouldYieldLength2_UsingStringDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello World ".AsSpan(); ReadOnlySpan<char> span = "Hello World ".AsSpan();
@ -323,20 +323,20 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
break; break;
case 1: case 1:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(2, index); Assert.That(index, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Split_OnTwoWords_ShouldYieldLength2_UsingStringDelimiter_GivenSpan() public void Split_OnTwoWords_ShouldYieldLength2_UsingStringDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello World ".AsSpan(); ReadOnlySpan<char> source = "Hello World ".AsSpan();
@ -349,20 +349,20 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello"));
break; break;
case 1: case 1:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(2, index); Assert.That(index, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Split_OnThreeWords_ShouldYieldLength3_UsingCharDelimiter_GivenReadOnlySpan() public void Split_OnThreeWords_ShouldYieldLength3_UsingCharDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello, the World ".AsSpan(); ReadOnlySpan<char> span = "Hello, the World ".AsSpan();
@ -373,23 +373,23 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello,", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello,"));
break; break;
case 1: case 1:
Assert.AreEqual("the", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("the"));
break; break;
case 2: case 2:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(3, index); Assert.That(index, Is.EqualTo(3));
} }
[TestMethod] [Test]
public void Split_OnThreeWords_ShouldYieldLength3_UsingCharDelimiter_GivenSpan() public void Split_OnThreeWords_ShouldYieldLength3_UsingCharDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello, the World ".AsSpan(); ReadOnlySpan<char> source = "Hello, the World ".AsSpan();
@ -402,23 +402,23 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello,", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello,"));
break; break;
case 1: case 1:
Assert.AreEqual("the", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("the"));
break; break;
case 2: case 2:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(3, index); Assert.That(index, Is.EqualTo(3));
} }
[TestMethod] [Test]
public void Split_OnThreeWords_ShouldYieldLength3_UsingStringDelimiter_GivenReadOnlySpan() public void Split_OnThreeWords_ShouldYieldLength3_UsingStringDelimiter_GivenReadOnlySpan()
{ {
ReadOnlySpan<char> span = "Hello, the World ".AsSpan(); ReadOnlySpan<char> span = "Hello, the World ".AsSpan();
@ -429,23 +429,23 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello,", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello,"));
break; break;
case 1: case 1:
Assert.AreEqual("the", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("the"));
break; break;
case 2: case 2:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(3, index); Assert.That(index, Is.EqualTo(3));
} }
[TestMethod] [Test]
public void Split_OnThreeWords_ShouldYieldLength3_UsingStringDelimiter_GivenSpan() public void Split_OnThreeWords_ShouldYieldLength3_UsingStringDelimiter_GivenSpan()
{ {
ReadOnlySpan<char> source = "Hello, the World ".AsSpan(); ReadOnlySpan<char> source = "Hello, the World ".AsSpan();
@ -458,19 +458,19 @@ public class SpanTest
switch (index) switch (index)
{ {
case 0: case 0:
Assert.AreEqual("Hello,", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("Hello,"));
break; break;
case 1: case 1:
Assert.AreEqual("the", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("the"));
break; break;
case 2: case 2:
Assert.AreEqual("World", subSpan.ToString()); Assert.That(subSpan.ToString(), Is.EqualTo("World"));
break; break;
} }
index++; index++;
} }
Assert.AreEqual(3, index); Assert.That(index, Is.EqualTo(3));
} }
} }

View File

@ -1,76 +1,78 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class CoreTests public class CoreTests
{ {
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void AsArrayValue_ShouldBeLength1_GivenValue(object o) public void AsArrayValue_ShouldBeLength1_GivenValue(object o)
{ {
object[] array = o.AsArrayValue()!; object[] array = o.AsArrayValue();
Assert.IsNotNull(array); Assert.That(array, Is.Not.Null);
Assert.IsTrue(array.Length == 1); Assert.That(array, Has.Length.EqualTo(1));
} }
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void AsArrayValue_ShouldContainValue_Given_Value(object o) public void AsArrayValue_ShouldContainValue_Given_Value(object o)
{ {
object[] array = o.AsArrayValue()!; object[] array = o.AsArrayValue();
Assert.IsNotNull(array); Assert.That(array, Is.Not.Null);
Assert.AreEqual(o, array[0]); Assert.That(array[0], Is.EqualTo(o));
} }
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void AsEnumerableValue_ShouldBeLength1_GivenValue(object o) public void AsEnumerableValue_ShouldBeLength1_GivenValue(object o)
{ {
IEnumerable<object> enumerable = o.AsEnumerableValue()!; object[] enumerable = o.AsEnumerableValue().ToArray();
Assert.IsNotNull(enumerable); Assert.That(enumerable, Is.Not.Null);
Assert.IsTrue(enumerable.Count() == 1); Assert.That(enumerable, Has.Length.EqualTo(1));
} }
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void AsEnumerableValue_ShouldContainValue_Given_Value(object o) public void AsEnumerableValue_ShouldContainValue_Given_Value(object o)
{ {
IEnumerable<object> enumerable = o.AsEnumerableValue()!; object[] enumerable = o.AsEnumerableValue().ToArray();
Assert.IsNotNull(enumerable); Assert.That(enumerable, Is.Not.Null);
Assert.AreEqual(o, enumerable.ElementAt(0)); Assert.That(enumerable.ElementAt(0), Is.EqualTo(o));
} }
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void RepeatValue_ShouldContainRepeatedValue_GivenValue(object o) public void RepeatValue_ShouldContainRepeatedValue_GivenValue(object o)
{ {
IEnumerable<object> enumerable = o.RepeatValue(10); IEnumerable<object> enumerable = o.RepeatValue(10);
Assert.IsNotNull(enumerable); // ReSharper disable once PossibleMultipleEnumeration
Assert.That(enumerable, Is.Not.Null);
// ReSharper disable once PossibleMultipleEnumeration
object[] array = enumerable.ToArray(); object[] array = enumerable.ToArray();
Assert.AreEqual(10, array.Length); Assert.That(array, Has.Length.EqualTo(10));
CollectionAssert.AreEqual(new[] {o, o, o, o, o, o, o, o, o, o}, array); CollectionAssert.AreEqual(new[] {o, o, o, o, o, o, o, o, o, o}, array);
} }
[TestMethod] [Test]
[DataRow(1)] [TestCase(1)]
[DataRow("f")] [TestCase("f")]
[DataRow(true)] [TestCase(true)]
public void RepeatValue_ShouldThrow_GivenNegativeCount(object o) public void RepeatValue_ShouldThrow_GivenNegativeCount(object o)
{ {
// we must force enumeration via ToArray() to ensure the exception is thrown // we must force enumeration via ToArray() to ensure the exception is thrown
Assert.ThrowsException<ArgumentOutOfRangeException>(() => o.RepeatValue(-1).ToArray()); Assert.Throws<ArgumentOutOfRangeException>(() => _ = o.RepeatValue(-1).ToArray());
} }
} }

View File

@ -1,9 +1,9 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class EnumTests public class EnumTests
{ {
// Microsoft wrongfully decided to have Sunday be 0, Monday be 1, etc. // Microsoft wrongfully decided to have Sunday be 0, Monday be 1, etc.
@ -12,51 +12,63 @@ public class EnumTests
// but Microsoft can't fix this without breaking compatibility. // but Microsoft can't fix this without breaking compatibility.
// I have feelings... // I have feelings...
[TestMethod] [Test]
public void Next() public void Next()
{ {
Assert.AreEqual(DayOfWeek.Monday, DayOfWeek.Sunday.Next()); Assert.Multiple(() =>
Assert.AreEqual(DayOfWeek.Tuesday, DayOfWeek.Monday.Next()); {
Assert.AreEqual(DayOfWeek.Wednesday, DayOfWeek.Tuesday.Next()); Assert.That(DayOfWeek.Sunday.Next(), Is.EqualTo(DayOfWeek.Monday));
Assert.AreEqual(DayOfWeek.Thursday, DayOfWeek.Wednesday.Next()); Assert.That(DayOfWeek.Monday.Next(), Is.EqualTo(DayOfWeek.Tuesday));
Assert.AreEqual(DayOfWeek.Friday, DayOfWeek.Thursday.Next()); Assert.That(DayOfWeek.Tuesday.Next(), Is.EqualTo(DayOfWeek.Wednesday));
Assert.AreEqual(DayOfWeek.Saturday, DayOfWeek.Friday.Next()); Assert.That(DayOfWeek.Wednesday.Next(), Is.EqualTo(DayOfWeek.Thursday));
Assert.AreEqual(DayOfWeek.Sunday, DayOfWeek.Saturday.Next()); // Saturday is the "last" day. wrap to "first" Assert.That(DayOfWeek.Thursday.Next(), Is.EqualTo(DayOfWeek.Friday));
Assert.That(DayOfWeek.Friday.Next(), Is.EqualTo(DayOfWeek.Saturday));
Assert.That(DayOfWeek.Saturday.Next(), Is.EqualTo(DayOfWeek.Sunday)); // Saturday is the "last" day. wrap to "first"
});
} }
[TestMethod] [Test]
public void NextUnchecked() public void NextUnchecked()
{ {
Assert.AreEqual(DayOfWeek.Monday, DayOfWeek.Sunday.NextUnchecked()); Assert.Multiple(() =>
Assert.AreEqual(DayOfWeek.Tuesday, DayOfWeek.Monday.NextUnchecked()); {
Assert.AreEqual(DayOfWeek.Wednesday, DayOfWeek.Tuesday.NextUnchecked()); Assert.That(DayOfWeek.Sunday.NextUnchecked(), Is.EqualTo(DayOfWeek.Monday));
Assert.AreEqual(DayOfWeek.Thursday, DayOfWeek.Wednesday.NextUnchecked()); Assert.That(DayOfWeek.Monday.NextUnchecked(), Is.EqualTo(DayOfWeek.Tuesday));
Assert.AreEqual(DayOfWeek.Friday, DayOfWeek.Thursday.NextUnchecked()); Assert.That(DayOfWeek.Tuesday.NextUnchecked(), Is.EqualTo(DayOfWeek.Wednesday));
Assert.AreEqual(DayOfWeek.Saturday, DayOfWeek.Friday.NextUnchecked()); Assert.That(DayOfWeek.Wednesday.NextUnchecked(), Is.EqualTo(DayOfWeek.Thursday));
Assert.ThrowsException<IndexOutOfRangeException>(() => DayOfWeek.Saturday.NextUnchecked()); Assert.That(DayOfWeek.Thursday.NextUnchecked(), Is.EqualTo(DayOfWeek.Friday));
Assert.That(DayOfWeek.Friday.NextUnchecked(), Is.EqualTo(DayOfWeek.Saturday));
});
Assert.Throws<IndexOutOfRangeException>(() => _ = DayOfWeek.Saturday.NextUnchecked());
} }
[TestMethod] [Test]
public void Previous() public void Previous()
{ {
Assert.AreEqual(DayOfWeek.Saturday, DayOfWeek.Sunday.Previous()); // Sunday is the "first" day. wrap to "last" Assert.Multiple(() =>
Assert.AreEqual(DayOfWeek.Sunday, DayOfWeek.Monday.Previous()); {
Assert.AreEqual(DayOfWeek.Monday, DayOfWeek.Tuesday.Previous()); Assert.That(DayOfWeek.Sunday.Previous(), Is.EqualTo(DayOfWeek.Saturday)); // Sunday is the "first" day. wrap to "last"
Assert.AreEqual(DayOfWeek.Tuesday, DayOfWeek.Wednesday.Previous()); Assert.That(DayOfWeek.Monday.Previous(), Is.EqualTo(DayOfWeek.Sunday));
Assert.AreEqual(DayOfWeek.Wednesday, DayOfWeek.Thursday.Previous()); Assert.That(DayOfWeek.Tuesday.Previous(), Is.EqualTo(DayOfWeek.Monday));
Assert.AreEqual(DayOfWeek.Thursday, DayOfWeek.Friday.Previous()); Assert.That(DayOfWeek.Wednesday.Previous(), Is.EqualTo(DayOfWeek.Tuesday));
Assert.AreEqual(DayOfWeek.Friday, DayOfWeek.Saturday.Previous()); Assert.That(DayOfWeek.Thursday.Previous(), Is.EqualTo(DayOfWeek.Wednesday));
Assert.That(DayOfWeek.Friday.Previous(), Is.EqualTo(DayOfWeek.Thursday));
Assert.That(DayOfWeek.Saturday.Previous(), Is.EqualTo(DayOfWeek.Friday));
});
} }
[TestMethod] [Test]
public void PreviousUnchecked() public void PreviousUnchecked()
{ {
Assert.AreEqual(DayOfWeek.Sunday, DayOfWeek.Monday.PreviousUnchecked()); Assert.Multiple(() =>
Assert.AreEqual(DayOfWeek.Monday, DayOfWeek.Tuesday.PreviousUnchecked()); {
Assert.AreEqual(DayOfWeek.Tuesday, DayOfWeek.Wednesday.PreviousUnchecked()); Assert.That(DayOfWeek.Monday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Sunday));
Assert.AreEqual(DayOfWeek.Wednesday, DayOfWeek.Thursday.PreviousUnchecked()); Assert.That(DayOfWeek.Tuesday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Monday));
Assert.AreEqual(DayOfWeek.Thursday, DayOfWeek.Friday.PreviousUnchecked()); Assert.That(DayOfWeek.Wednesday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Tuesday));
Assert.AreEqual(DayOfWeek.Friday, DayOfWeek.Saturday.PreviousUnchecked()); Assert.That(DayOfWeek.Thursday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Wednesday));
Assert.ThrowsException<IndexOutOfRangeException>(() => DayOfWeek.Sunday.PreviousUnchecked()); Assert.That(DayOfWeek.Friday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Thursday));
Assert.That(DayOfWeek.Saturday.PreviousUnchecked(), Is.EqualTo(DayOfWeek.Friday));
});
Assert.Throws<IndexOutOfRangeException>(() => _ = DayOfWeek.Sunday.PreviousUnchecked());
} }
} }

View File

@ -1,15 +1,15 @@
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class IntrinsicTests public class IntrinsicTests
{ {
[TestMethod] [Test]
public void CorrectBoolean_ShouldReturnExpectedVector64Result_GivenInputVector() public void CorrectBoolean_ShouldReturnExpectedVector64Result_GivenInputVector()
{ {
var inputVector = Vector64.Create(0, 1, 2, 0, 3, 0, 0, (byte)4); var inputVector = Vector64.Create(0, 1, 2, 0, 3, 0, 0, (byte)4);
@ -17,10 +17,10 @@ public class IntrinsicTests
Vector64<byte> result = inputVector.CorrectBoolean(); Vector64<byte> result = inputVector.CorrectBoolean();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void CorrectBooleanInternal_Fallback_ShouldReturnExpectedVector128Result_GivenInputVector() public void CorrectBooleanInternal_Fallback_ShouldReturnExpectedVector128Result_GivenInputVector()
{ {
var inputVector = Vector128.Create(0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0, 0, 7, (byte)8); var inputVector = Vector128.Create(0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0, 0, 7, (byte)8);
@ -28,10 +28,10 @@ public class IntrinsicTests
Vector128<byte> result = inputVector.CorrectBooleanInternal_Fallback(); Vector128<byte> result = inputVector.CorrectBooleanInternal_Fallback();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void CorrectBooleanInternal_Sse2_ShouldReturnExpectedVector128Result_GivenInputVector() public void CorrectBooleanInternal_Sse2_ShouldReturnExpectedVector128Result_GivenInputVector()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -44,10 +44,10 @@ public class IntrinsicTests
Vector128<byte> result = inputVector.CorrectBooleanInternal_Sse2(); Vector128<byte> result = inputVector.CorrectBooleanInternal_Sse2();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void CorrectBooleanInternal_Avx2_ShouldReturnExpectedVector256Result_GivenInputVector() public void CorrectBooleanInternal_Avx2_ShouldReturnExpectedVector256Result_GivenInputVector()
{ {
if (!Avx2.IsSupported) if (!Avx2.IsSupported)
@ -62,10 +62,10 @@ public class IntrinsicTests
Vector256<byte> result = inputVector.CorrectBooleanInternal_Avx2(); Vector256<byte> result = inputVector.CorrectBooleanInternal_Avx2();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void CorrectBooleanInternal_Fallback_ShouldReturnExpectedVector256Result_GivenInputVector() public void CorrectBooleanInternal_Fallback_ShouldReturnExpectedVector256Result_GivenInputVector()
{ {
var inputVector = Vector256.Create(0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0, 0, 7, 8, 0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0, var inputVector = Vector256.Create(0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0, 0, 7, 8, 0, 1, 2, 0, 3, 0, 0, 4, 5, 0, 0, 6, 0,
@ -75,10 +75,10 @@ public class IntrinsicTests
Vector256<byte> result = inputVector.CorrectBooleanInternal_Fallback(); Vector256<byte> result = inputVector.CorrectBooleanInternal_Fallback();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void HorizontalOr_ShouldReturnCombinedVector_GivenInputVector128OfUInt32() public void HorizontalOr_ShouldReturnCombinedVector_GivenInputVector128OfUInt32()
{ {
Vector128<uint> left = Vector128.Create(1U, 2U, 3U, 4U); Vector128<uint> left = Vector128.Create(1U, 2U, 3U, 4U);
@ -87,10 +87,10 @@ public class IntrinsicTests
Vector128<uint> expected = Vector128.Create(3U, 7U, 7U, 15U); Vector128<uint> expected = Vector128.Create(3U, 7U, 7U, 15U);
Vector128<uint> actual = IntrinsicUtility.HorizontalOr(left, right); Vector128<uint> actual = IntrinsicUtility.HorizontalOr(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void HorizontalOrInternal_Sse_ShouldReturnCombinedVector_GivenInputVector128OfInt32() public void HorizontalOrInternal_Sse_ShouldReturnCombinedVector_GivenInputVector128OfInt32()
{ {
Vector128<int> left = Vector128.Create(1, 2, 3, 4); Vector128<int> left = Vector128.Create(1, 2, 3, 4);
@ -99,10 +99,10 @@ public class IntrinsicTests
Vector128<int> expected = Vector128.Create(3, 7, 7, 15); Vector128<int> expected = Vector128.Create(3, 7, 7, 15);
Vector128<int> actual = IntrinsicUtility.HorizontalOr_Sse(left, right); Vector128<int> actual = IntrinsicUtility.HorizontalOr_Sse(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void HorizontalOrInternal_Fallback_ShouldReturnCombinedVector_GivenInputVector128OfInt32() public void HorizontalOrInternal_Fallback_ShouldReturnCombinedVector_GivenInputVector128OfInt32()
{ {
Vector128<int> left = Vector128.Create(1, 2, 3, 4); Vector128<int> left = Vector128.Create(1, 2, 3, 4);
@ -111,10 +111,10 @@ public class IntrinsicTests
Vector128<int> expected = Vector128.Create(3, 7, 7, 15); Vector128<int> expected = Vector128.Create(3, 7, 7, 15);
Vector128<int> actual = IntrinsicUtility.HorizontalOrInternal_Fallback(left, right); Vector128<int> actual = IntrinsicUtility.HorizontalOrInternal_Fallback(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void Multiply_ShouldReturnMultipliedVector_GivenInputVector128OfInt64() public void Multiply_ShouldReturnMultipliedVector_GivenInputVector128OfInt64()
{ {
Vector128<long> left = Vector128.Create(6L, 4L); Vector128<long> left = Vector128.Create(6L, 4L);
@ -123,10 +123,10 @@ public class IntrinsicTests
Vector128<long> expected = Vector128.Create(12L, 12L); Vector128<long> expected = Vector128.Create(12L, 12L);
Vector128<long> actual = IntrinsicUtility.Multiply(left, right); Vector128<long> actual = IntrinsicUtility.Multiply(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplyInternal_Sse2_ShouldReturnMultipliedVector_GivenInputVector128OfUInt64() public void MultiplyInternal_Sse2_ShouldReturnMultipliedVector_GivenInputVector128OfUInt64()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -140,10 +140,10 @@ public class IntrinsicTests
Vector128<ulong> expected = Vector128.Create(12UL, 12UL); Vector128<ulong> expected = Vector128.Create(12UL, 12UL);
Vector128<ulong> actual = IntrinsicUtility.MultiplyInternal_Sse2(left, right); Vector128<ulong> actual = IntrinsicUtility.MultiplyInternal_Sse2(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplyInternal_Fallback_ShouldReturnMultipliedVector_GivenInputVector128OfUInt64() public void MultiplyInternal_Fallback_ShouldReturnMultipliedVector_GivenInputVector128OfUInt64()
{ {
Vector128<ulong> left = Vector128.Create(6UL, 4UL); Vector128<ulong> left = Vector128.Create(6UL, 4UL);
@ -152,10 +152,10 @@ public class IntrinsicTests
Vector128<ulong> expected = Vector128.Create(12UL, 12UL); Vector128<ulong> expected = Vector128.Create(12UL, 12UL);
Vector128<ulong> actual = IntrinsicUtility.MultiplyInternal_Fallback(left, right); Vector128<ulong> actual = IntrinsicUtility.MultiplyInternal_Fallback(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void Multiply_ShouldReturnMultipliedVector_GivenInputVector256OfInt64() public void Multiply_ShouldReturnMultipliedVector_GivenInputVector256OfInt64()
{ {
Vector256<long> left = Vector256.Create(4L, 6L, 8L, 10L); Vector256<long> left = Vector256.Create(4L, 6L, 8L, 10L);
@ -164,10 +164,10 @@ public class IntrinsicTests
Vector256<long> expected = Vector256.Create(8L, 18L, 32L, 50L); Vector256<long> expected = Vector256.Create(8L, 18L, 32L, 50L);
Vector256<long> actual = IntrinsicUtility.Multiply(left, right); Vector256<long> actual = IntrinsicUtility.Multiply(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplyInternal_Avx2_ShouldReturnMultipliedVector_GivenInputVector256OfUInt64() public void MultiplyInternal_Avx2_ShouldReturnMultipliedVector_GivenInputVector256OfUInt64()
{ {
if (!Avx2.IsSupported) if (!Avx2.IsSupported)
@ -181,10 +181,10 @@ public class IntrinsicTests
Vector256<ulong> expected = Vector256.Create(8UL, 18UL, 32UL, 50UL); Vector256<ulong> expected = Vector256.Create(8UL, 18UL, 32UL, 50UL);
Vector256<ulong> actual = IntrinsicUtility.MultiplyInternal_Avx2(left, right); Vector256<ulong> actual = IntrinsicUtility.MultiplyInternal_Avx2(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplyInternal_Fallback_ShouldReturnMultipliedVector_GivenInputVector256OfUInt64() public void MultiplyInternal_Fallback_ShouldReturnMultipliedVector_GivenInputVector256OfUInt64()
{ {
Vector256<ulong> left = Vector256.Create(4UL, 6UL, 8UL, 10UL); Vector256<ulong> left = Vector256.Create(4UL, 6UL, 8UL, 10UL);
@ -193,10 +193,10 @@ public class IntrinsicTests
Vector256<ulong> expected = Vector256.Create(8UL, 18UL, 32UL, 50UL); Vector256<ulong> expected = Vector256.Create(8UL, 18UL, 32UL, 50UL);
Vector256<ulong> actual = IntrinsicUtility.MultiplyInternal_Fallback(left, right); Vector256<ulong> actual = IntrinsicUtility.MultiplyInternal_Fallback(left, right);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReverseElementsInternal_Fallback_ShouldReturnExpectedVector128Result_GivenInputVector() public void ReverseElementsInternal_Fallback_ShouldReturnExpectedVector128Result_GivenInputVector()
{ {
var inputVector = Vector128.Create(42UL, 69UL); var inputVector = Vector128.Create(42UL, 69UL);
@ -204,10 +204,10 @@ public class IntrinsicTests
Vector128<ulong> result = inputVector.ReverseElementsInternal_Fallback(); Vector128<ulong> result = inputVector.ReverseElementsInternal_Fallback();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestMethod] [Test]
public void ReverseElementsInternal_Sse2_ShouldReturnExpectedVector128Result_GivenInputVector() public void ReverseElementsInternal_Sse2_ShouldReturnExpectedVector128Result_GivenInputVector()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -220,7 +220,7 @@ public class IntrinsicTests
Vector128<ulong> result = inputVector.ReverseElementsInternal_Sse2(); Vector128<ulong> result = inputVector.ReverseElementsInternal_Sse2();
Assert.AreEqual(expectedResult, result); Assert.That(result, Is.EqualTo(expectedResult));
} }
} }
#endif #endif

View File

@ -1,24 +1,30 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class NullableTests public class NullableTests
{ {
[TestMethod] [Test]
public void TryGetValue_ShouldBeTrue_GivenValue() public void TryGetValue_ShouldBeTrue_GivenValue()
{ {
int? value = 42; int? value = 42;
Assert.IsTrue(value.TryGetValue(out int returnedValue)); Assert.Multiple(() =>
Assert.AreEqual(value, returnedValue); {
Assert.That(value.TryGetValue(out int returnedValue));
Assert.That(returnedValue, Is.EqualTo(value.Value));
});
} }
[TestMethod] [Test]
public void TryGetValue_ShouldBeFalse_GivenNull() public void TryGetValue_ShouldBeFalse_GivenNull()
{ {
int? value = null; int? value = null;
Assert.IsFalse(value.TryGetValue(out int returnedValue)); Assert.Multiple(() =>
Assert.AreEqual(default, returnedValue); {
Assert.That(value.TryGetValue(out int returnedValue), Is.False);
Assert.That(returnedValue, Is.Zero);
});
} }
} }

View File

@ -1,121 +1,121 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Collections; using X10D.Collections;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class RandomTests public class RandomTests
{ {
[TestMethod] [Test]
public void NextBoolean_ShouldBeFalse_GivenSeed1234() public void NextBoolean_ShouldBeFalse_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.IsFalse(random.NextBoolean()); Assert.That(random.NextBoolean(), Is.False);
} }
[TestMethod] [Test]
public void NextBoolean_ShouldThrow_GivenNull() public void NextBoolean_ShouldThrow_GivenNull()
{ {
Random? random = null; Random random = null!;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextBoolean()); Assert.Throws<ArgumentNullException>(() => random.NextBoolean());
} }
[TestMethod] [Test]
public void NextByte_ShouldBe101_GivenSeed1234() public void NextByte_ShouldBe101_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(101, random.NextByte()); Assert.That(random.NextByte(), Is.EqualTo(101));
} }
[TestMethod] [Test]
public void NextByte_WithMax10_ShouldBe3_GivenSeed1234() public void NextByte_WithMax10_ShouldBe3_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3, random.NextByte(10)); Assert.That(random.NextByte(10), Is.EqualTo(3));
} }
[TestMethod] [Test]
public void NextByte_WithMin0Max10_ShouldBe3_GivenSeed1234() public void NextByte_WithMin0Max10_ShouldBe3_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3, random.NextByte(0, 10)); Assert.That(random.NextByte(0, 10), Is.EqualTo(3));
} }
[TestMethod] [Test]
public void NextByte_ShouldThrow_GivenNull() public void NextByte_ShouldThrow_GivenNull()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextByte()); Assert.Throws<ArgumentNullException>(() => random!.NextByte());
Assert.ThrowsException<ArgumentNullException>(() => random!.NextByte(10)); Assert.Throws<ArgumentNullException>(() => random!.NextByte(10));
Assert.ThrowsException<ArgumentNullException>(() => random!.NextByte(0, 10)); Assert.Throws<ArgumentNullException>(() => random!.NextByte(0, 10));
} }
[TestMethod] [Test]
public void NextDouble_WithMax10_ShouldBe3point9908097935797695_GivenSeed1234() public void NextDouble_WithMax10_ShouldBe3point9908097935797695_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3.9908097935797695, random.NextDouble(10)); Assert.That(random.NextDouble(10), Is.EqualTo(3.9908097935797695));
} }
[TestMethod] [Test]
public void NextDouble_WithMin0Max10_ShouldBe3point9908097935797695_GivenSeed1234() public void NextDouble_WithMin0Max10_ShouldBe3point9908097935797695_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3.9908097935797695, random.NextDouble(0, 10)); Assert.That(random.NextDouble(0, 10), Is.EqualTo(3.9908097935797695));
} }
[TestMethod] [Test]
public void NextDouble_ShouldThrow_GivenNull() public void NextDouble_ShouldThrow_GivenNull()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextDouble(10)); Assert.Throws<ArgumentNullException>(() => random!.NextDouble(10));
Assert.ThrowsException<ArgumentNullException>(() => random!.NextDouble(0, 10)); Assert.Throws<ArgumentNullException>(() => random!.NextDouble(0, 10));
} }
[TestMethod] [Test]
public void NextDouble_ShouldThrow_GivenMaxLessThan0() public void NextDouble_ShouldThrow_GivenMaxLessThan0()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentOutOfRangeException>(() => random.NextDouble(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => random.NextDouble(-1));
} }
[TestMethod] [Test]
public void NextDouble_ShouldThrow_GivenMaxLessThanMin() public void NextDouble_ShouldThrow_GivenMaxLessThanMin()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentException>(() => random.NextDouble(0, -1)); Assert.Throws<ArgumentException>(() => random.NextDouble(0, -1));
} }
[TestMethod] [Test]
public void NextEnum_ShouldBeTuesday_GivenSeed1234() public void NextEnum_ShouldBeTuesday_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(DayOfWeek.Tuesday, random.Next<DayOfWeek>()); Assert.That(random.Next<DayOfWeek>(), Is.EqualTo(DayOfWeek.Tuesday));
} }
[TestMethod] [Test]
public void NextEnum_ShouldThrow_GivenNull() public void NextEnum_ShouldThrow_GivenNull()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.Next<DayOfWeek>()); Assert.Throws<ArgumentNullException>(() => random!.Next<DayOfWeek>());
} }
[TestMethod] [Test]
public void NextFrom_ShouldThrow_GivenNullRandom() public void NextFrom_ShouldThrow_GivenNullRandom()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextFrom("")); Assert.Throws<ArgumentNullException>(() => random!.NextFrom(""));
} }
[TestMethod] [Test]
public void NextFrom_ShouldThrow_GivenNullSource() public void NextFrom_ShouldThrow_GivenNullSource()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentNullException>(() => random.NextFrom((string?)null!)); Assert.Throws<ArgumentNullException>(() => random.NextFrom((string?)null!));
} }
[TestMethod] [Test]
public void NextFrom_ShouldEnumerate_GivenNonList() public void NextFrom_ShouldEnumerate_GivenNonList()
{ {
IEnumerable<int> Source() IEnumerable<int> Source()
@ -124,168 +124,168 @@ public class RandomTests
} }
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(0, random.NextFrom(Source())); Assert.That(random.NextFrom(Source()), Is.Zero);
} }
[TestMethod] [Test]
public void NextFromSpan_ShouldThrow_GivenNullRandom() public void NextFromSpan_ShouldThrow_GivenNullRandom()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
Span<int> span = stackalloc int[1]; Span<int> span = stackalloc int[1];
return random!.NextFrom(span); _ = random!.NextFrom(span);
}); });
} }
[TestMethod] [Test]
public void NextFromReadOnlySpan_ShouldThrow_GivenNullRandom() public void NextFromReadOnlySpan_ShouldThrow_GivenNullRandom()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
Span<int> span = stackalloc int[1]; Span<int> span = stackalloc int[1];
return random!.NextFrom(span.AsReadOnly()); _ = random!.NextFrom(span.AsReadOnly());
}); });
} }
[TestMethod] [Test]
public void NextFromSpan_ShouldReturnOnlyValue_GivenSpanWithLength1() public void NextFromSpan_ShouldReturnOnlyValue_GivenSpanWithLength1()
{ {
Span<int> span = stackalloc int[1]; Span<int> span = stackalloc int[1];
span[0] = 42; span[0] = 42;
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(42, random.NextFrom(span)); Assert.That(random.NextFrom(span), Is.EqualTo(42));
} }
[TestMethod] [Test]
public void NextFromReadOnlySpan_ShouldReturnOnlyValue_GivenSpanWithLength1() public void NextFromReadOnlySpan_ShouldReturnOnlyValue_GivenSpanWithLength1()
{ {
Span<int> span = stackalloc int[1]; Span<int> span = stackalloc int[1];
span[0] = 42; span[0] = 42;
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(42, random.NextFrom(span.AsReadOnly())); Assert.That(random.NextFrom(span.AsReadOnly()), Is.EqualTo(42));
} }
[TestMethod] [Test]
public void NextInt16_ShouldBe13076_GivenSeed1234() public void NextInt16_ShouldBe13076_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(13076, random.NextInt16()); Assert.That(random.NextInt16(), Is.EqualTo(13076));
} }
[TestMethod] [Test]
public void NextInt16_WithMax10_ShouldBe3_GivenSeed1234() public void NextInt16_WithMax10_ShouldBe3_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3, random.NextInt16(10)); Assert.That(random.NextInt16(10), Is.EqualTo(3));
} }
[TestMethod] [Test]
public void NextInt16_WithMin0Max10_ShouldBe3_GivenSeed1234() public void NextInt16_WithMin0Max10_ShouldBe3_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3, random.NextInt16(0, 10)); Assert.That(random.NextInt16(0, 10), Is.EqualTo(3));
} }
[TestMethod] [Test]
public void NextInt16_ShouldThrow_GivenMaxLessThan0() public void NextInt16_ShouldThrow_GivenMaxLessThan0()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentOutOfRangeException>(() => random.NextInt16(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => random.NextInt16(-1));
} }
[TestMethod] [Test]
public void NextInt16_ShouldThrow_GivenNull() public void NextInt16_ShouldThrow_GivenNull()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextInt16()); Assert.Throws<ArgumentNullException>(() => random!.NextInt16());
Assert.ThrowsException<ArgumentNullException>(() => random!.NextInt16(10)); Assert.Throws<ArgumentNullException>(() => random!.NextInt16(10));
Assert.ThrowsException<ArgumentNullException>(() => random!.NextInt16(0, 10)); Assert.Throws<ArgumentNullException>(() => random!.NextInt16(0, 10));
} }
[TestMethod] [Test]
public void NextSingle_WithMax10_ShouldBe3point99081_GivenSeed1234() public void NextSingle_WithMax10_ShouldBe3point99081_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3.99081f, random.NextSingle(10)); Assert.That(random.NextSingle(10), Is.EqualTo(3.99081f));
} }
[TestMethod] [Test]
public void NextSingle_WithMin0Max10_ShouldBe3point99081_GivenSeed1234() public void NextSingle_WithMin0Max10_ShouldBe3point99081_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(3.99081f, random.NextSingle(0, 10)); Assert.That(random.NextSingle(0, 10), Is.EqualTo(3.99081f));
} }
[TestMethod] [Test]
public void NextSingle_ShouldThrow_GivenNull() public void NextSingle_ShouldThrow_GivenNull()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextSingle(10)); Assert.Throws<ArgumentNullException>(() => random!.NextSingle(10));
Assert.ThrowsException<ArgumentNullException>(() => random!.NextSingle(0, 10)); Assert.Throws<ArgumentNullException>(() => random!.NextSingle(0, 10));
#if !NET6_0_OR_GREATER #if !NET6_0_OR_GREATER
Assert.ThrowsException<ArgumentNullException>(() => random!.NextSingle()); Assert.Throws<ArgumentNullException>(() => random!.NextSingle());
#endif #endif
} }
[TestMethod] [Test]
public void NextSingle_ShouldThrow_GivenMaxLessThan0() public void NextSingle_ShouldThrow_GivenMaxLessThan0()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentOutOfRangeException>(() => random.NextSingle(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => random.NextSingle(-1));
} }
[TestMethod] [Test]
public void NextSingle_ShouldThrow_GivenMaxLessThanMin() public void NextSingle_ShouldThrow_GivenMaxLessThanMin()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentException>(() => random.NextSingle(0, -1)); Assert.Throws<ArgumentException>(() => random.NextSingle(0, -1));
} }
[TestMethod] [Test]
public void NextString_ShouldBe_kxiyiyvnqi_GivenSeed1234() public void NextString_ShouldBe_kxiyiyvnqi_GivenSeed1234()
{ {
const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const string alphabet = "abcdefghijklmnopqrstuvwxyz";
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual("kxiyiyvnqi", random.NextString(alphabet.ToCharArray(), 10)); Assert.That(random.NextString(alphabet.ToCharArray(), 10), Is.EqualTo("kxiyiyvnqi"));
} }
[TestMethod] [Test]
public void NextString_ShouldBeEmpty_GivenLength0() public void NextString_ShouldBeEmpty_GivenLength0()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(string.Empty, random.NextString(ArraySegment<char>.Empty, 0)); Assert.That(random.NextString(ArraySegment<char>.Empty, 0), Is.EqualTo(string.Empty));
} }
[TestMethod] [Test]
public void NextString_ShouldBeLength1_GivenLength1() public void NextString_ShouldBeLength1_GivenLength1()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(1, random.NextString("hello world".ToCharArray(), 1).Length); Assert.That(random.NextString("hello world".ToCharArray(), 1).Length, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void NextString_ShouldThrow_GivenNullRandom() public void NextString_ShouldThrow_GivenNullRandom()
{ {
Random? random = null; Random? random = null;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextString(ArraySegment<char>.Empty, 0)); Assert.Throws<ArgumentNullException>(() => random!.NextString(ArraySegment<char>.Empty, 0));
} }
[TestMethod] [Test]
public void NextString_ShouldThrow_GivenNullSource() public void NextString_ShouldThrow_GivenNullSource()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentNullException>(() => random.NextString(null!, 0)); Assert.Throws<ArgumentNullException>(() => random.NextString(null!, 0));
} }
[TestMethod] [Test]
public void NextString_ShouldThrow_GivenNegativeLength() public void NextString_ShouldThrow_GivenNegativeLength()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.ThrowsException<ArgumentOutOfRangeException>(() => random.NextString(ArraySegment<char>.Empty, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => random.NextString(ArraySegment<char>.Empty, -1));
} }
} }

View File

@ -2,191 +2,203 @@
using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
#endif #endif
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Core; using X10D.Core;
namespace X10D.Tests.Core; namespace X10D.Tests.Core;
[TestClass] [TestFixture]
public class SpanTest public class SpanTest
{ {
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingByteEnum() public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingByteEnum()
{
Assert.Multiple(() =>
{ {
ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B}; ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
Assert.That(span.Contains(EnumByte.A), Is.False);
Assert.IsFalse(span.Contains(EnumByte.A)); Assert.That(span.Contains(EnumByte.C), Is.False);
Assert.IsFalse(span.Contains(EnumByte.C)); });
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt16Enum() public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt16Enum()
{
Assert.Multiple(() =>
{ {
ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B}; ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
Assert.That(span.Contains(EnumInt16.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt16.A)); Assert.That(span.Contains(EnumInt16.C), Is.False);
Assert.IsFalse(span.Contains(EnumInt16.C)); });
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt32Enum() public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt32Enum()
{
Assert.Multiple(() =>
{ {
ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B}; ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
Assert.That(span.Contains(EnumInt32.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt32.A)); Assert.That(span.Contains(EnumInt32.C), Is.False);
Assert.IsFalse(span.Contains(EnumInt32.C)); });
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt64Enum() public void Contains_ShouldReturnFalse_GivenReadOnlySpanWithNoMatchingElements_UsingInt64Enum()
{
Assert.Multiple(() =>
{ {
ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B}; ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
Assert.IsFalse(span.Contains(EnumInt64.A)); Assert.That(span.Contains(EnumInt64.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt64.C)); Assert.That(span.Contains(EnumInt64.C), Is.False);
});
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingByteEnum() public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingByteEnum()
{ {
ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B}; ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
Assert.IsTrue(span.Contains(EnumByte.B)); Assert.That(span.Contains(EnumByte.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt16Enum() public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt16Enum()
{ {
ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B}; ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
Assert.IsTrue(span.Contains(EnumInt16.B)); Assert.That(span.Contains(EnumInt16.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt32Enum() public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt32Enum()
{ {
ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B}; ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
Assert.IsTrue(span.Contains(EnumInt32.B)); Assert.That(span.Contains(EnumInt32.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt64Enum() public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt64Enum()
{ {
ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B}; ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
Assert.IsTrue(span.Contains(EnumInt64.B)); Assert.That(span.Contains(EnumInt64.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingByteEnum() public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingByteEnum()
{
Assert.Multiple(() =>
{ {
Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B}; Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
Assert.IsFalse(span.Contains(EnumByte.A)); Assert.That(span.Contains(EnumByte.A), Is.False);
Assert.IsFalse(span.Contains(EnumByte.C)); Assert.That(span.Contains(EnumByte.C), Is.False);
});
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt16Enum() public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt16Enum()
{ {
Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B}; Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
Assert.IsFalse(span.Contains(EnumInt16.A)); Assert.That(span.Contains(EnumInt16.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt16.C)); Assert.That(span.Contains(EnumInt16.C), Is.False);
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt32Enum() public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt32Enum()
{ {
Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B}; Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
Assert.IsFalse(span.Contains(EnumInt32.A)); Assert.That(span.Contains(EnumInt32.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt32.C)); Assert.That(span.Contains(EnumInt32.C), Is.False);
} }
[TestMethod] [Test]
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt64Enum() public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt64Enum()
{ {
Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B}; Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
Assert.IsFalse(span.Contains(EnumInt64.A)); Assert.That(span.Contains(EnumInt64.A), Is.False);
Assert.IsFalse(span.Contains(EnumInt64.C)); Assert.That(span.Contains(EnumInt64.C), Is.False);
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingByteEnum() public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingByteEnum()
{ {
Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B}; Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
Assert.IsTrue(span.Contains(EnumByte.B)); Assert.That(span.Contains(EnumByte.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt16Enum() public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt16Enum()
{ {
Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B}; Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
Assert.IsTrue(span.Contains(EnumInt16.B)); Assert.That(span.Contains(EnumInt16.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt32Enum() public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt32Enum()
{ {
Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B}; Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
Assert.IsTrue(span.Contains(EnumInt32.B)); Assert.That(span.Contains(EnumInt32.B));
} }
[TestMethod] [Test]
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt64Enum() public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt64Enum()
{ {
Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B}; Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
Assert.IsTrue(span.Contains(EnumInt64.B)); Assert.That(span.Contains(EnumInt64.B));
} }
[TestMethod] [Test]
public void PackByte_ShouldThrowArgumentException_GivenSpanLengthGreaterThan8() public void PackByte_ShouldThrowArgumentException_GivenSpanLengthGreaterThan8()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
Span<bool> span = stackalloc bool[9]; Span<bool> span = stackalloc bool[9];
return span.PackByte(); _ = span.PackByte();
}); });
} }
[TestMethod] [Test]
public void PackInt16_ShouldThrowArgumentException_GivenSpanLengthGreaterThan16() public void PackInt16_ShouldThrowArgumentException_GivenSpanLengthGreaterThan16()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
Span<bool> span = stackalloc bool[17]; Span<bool> span = stackalloc bool[17];
return span.PackInt16(); _ = span.PackInt16();
}); });
} }
[TestMethod] [Test]
public void PackInt32_ShouldThrowArgumentException_GivenSpanLengthGreaterThan32() public void PackInt32_ShouldThrowArgumentException_GivenSpanLengthGreaterThan32()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
Span<bool> span = stackalloc bool[33]; Span<bool> span = stackalloc bool[33];
return span.PackInt32(); _ = span.PackInt32();
}); });
} }
[TestMethod] [Test]
public void PackInt64_ShouldThrowArgumentException_GivenSpanLengthGreaterThan64() public void PackInt64_ShouldThrowArgumentException_GivenSpanLengthGreaterThan64()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
Span<bool> span = stackalloc bool[65]; Span<bool> span = stackalloc bool[65];
return span.PackInt64(); _ = span.PackInt64();
}); });
} }
[TestMethod] [Test]
public void PackByteInternal_Fallback_ShouldReturnCorrectByte_GivenReadOnlySpan_Using() public void PackByteInternal_Fallback_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
{ {
const byte expected = 0b00110011; const byte expected = 0b00110011;
@ -194,11 +206,11 @@ public class SpanTest
byte actual = span.PackByteInternal_Fallback(); byte actual = span.PackByteInternal_Fallback();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[TestMethod] [Test]
public void PackByteInternal_Sse2_ShouldReturnCorrectByte_GivenReadOnlySpan_Using() public void PackByteInternal_Sse2_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -211,10 +223,10 @@ public class SpanTest
byte actual = span.PackByteInternal_Sse2(); byte actual = span.PackByteInternal_Sse2();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackByteInternal_AdvSimd_ShouldReturnCorrectByte_GivenReadOnlySpan_Using() public void PackByteInternal_AdvSimd_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
{ {
if (!AdvSimd.IsSupported) if (!AdvSimd.IsSupported)
@ -227,11 +239,11 @@ public class SpanTest
byte actual = span.PackByteInternal_AdvSimd(); byte actual = span.PackByteInternal_AdvSimd();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#endif #endif
[TestMethod] [Test]
public void PackInt16_ShouldReturnSameAsPackByte_WhenSpanHasLength8() public void PackInt16_ShouldReturnSameAsPackByte_WhenSpanHasLength8()
{ {
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
@ -239,10 +251,10 @@ public class SpanTest
short expected = span.PackByte(); short expected = span.PackByte();
short actual = span.PackInt16(); short actual = span.PackInt16();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt16Internal_Fallback_ShouldReturnCorrectInt16_GivenReadOnlySpan() public void PackInt16Internal_Fallback_ShouldReturnCorrectInt16_GivenReadOnlySpan()
{ {
const short expected = 0b00101101_11010100; const short expected = 0b00101101_11010100;
@ -253,11 +265,11 @@ public class SpanTest
short actual = span.PackInt16Internal_Fallback(); short actual = span.PackInt16Internal_Fallback();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[TestMethod] [Test]
public void PackInt16Internal_Sse2_ShouldReturnCorrectInt16_GivenReadOnlySpan_Using() public void PackInt16Internal_Sse2_ShouldReturnCorrectInt16_GivenReadOnlySpan_Using()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -273,11 +285,11 @@ public class SpanTest
short actual = span.PackInt16Internal_Sse2(); short actual = span.PackInt16Internal_Sse2();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#endif #endif
[TestMethod] [Test]
public void PackInt32Internal_Fallback_ShouldReturnCorrectInt32_GivenReadOnlySpan() public void PackInt32Internal_Fallback_ShouldReturnCorrectInt32_GivenReadOnlySpan()
{ {
const int expected = 0b01010101_10101010_01010101_10101010; const int expected = 0b01010101_10101010_01010101_10101010;
@ -289,11 +301,11 @@ public class SpanTest
int actual = span.PackInt32Internal_Fallback(); int actual = span.PackInt32Internal_Fallback();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
[TestMethod] [Test]
public void PackInt32Internal_Sse2_ShouldReturnCorrectInt32_GivenReadOnlySpan() public void PackInt32Internal_Sse2_ShouldReturnCorrectInt32_GivenReadOnlySpan()
{ {
if (!Sse2.IsSupported) if (!Sse2.IsSupported)
@ -310,10 +322,10 @@ public class SpanTest
int actual = span.PackInt32Internal_Sse2(); int actual = span.PackInt32Internal_Sse2();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt32Internal_Avx2_ShouldReturnCorrectInt32_GivenReadOnlySpan() public void PackInt32Internal_Avx2_ShouldReturnCorrectInt32_GivenReadOnlySpan()
{ {
if (!Avx2.IsSupported) if (!Avx2.IsSupported)
@ -330,10 +342,10 @@ public class SpanTest
int actual = span.PackInt32Internal_Avx2(); int actual = span.PackInt32Internal_Avx2();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt32Internal_AdvSimd_ShouldReturnCorrectInt32_GivenReadOnlySpan() public void PackInt32Internal_AdvSimd_ShouldReturnCorrectInt32_GivenReadOnlySpan()
{ {
if (!AdvSimd.IsSupported) if (!AdvSimd.IsSupported)
@ -350,11 +362,11 @@ public class SpanTest
int actual = span.PackInt32Internal_AdvSimd(); int actual = span.PackInt32Internal_AdvSimd();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
#endif #endif
[TestMethod] [Test]
public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan() public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan()
{ {
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
@ -362,10 +374,10 @@ public class SpanTest
int expected = span.PackByte(); int expected = span.PackByte();
int actual = span.PackInt32(); int actual = span.PackInt32();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan() public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan()
{ {
Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
@ -373,10 +385,10 @@ public class SpanTest
int expected = span.PackByte(); int expected = span.PackByte();
int actual = span.PackInt32(); int actual = span.PackInt32();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan() public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan()
{ {
ReadOnlySpan<bool> span = stackalloc bool[16] ReadOnlySpan<bool> span = stackalloc bool[16]
@ -387,10 +399,10 @@ public class SpanTest
int expected = span.PackInt16(); int expected = span.PackInt16();
int actual = span.PackInt32(); int actual = span.PackInt32();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan() public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan()
{ {
Span<bool> span = stackalloc bool[16] Span<bool> span = stackalloc bool[16]
@ -401,10 +413,10 @@ public class SpanTest
int expected = span.PackInt16(); int expected = span.PackInt16();
int actual = span.PackInt32(); int actual = span.PackInt32();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnCorrectInt64_GivenReadOnlySpan() public void PackInt64_ShouldReturnCorrectInt64_GivenReadOnlySpan()
{ {
const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101; const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101;
@ -418,10 +430,10 @@ public class SpanTest
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnCorrectInt64_GivenSpan() public void PackInt64_ShouldReturnCorrectInt64_GivenSpan()
{ {
const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101; const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101;
@ -435,10 +447,10 @@ public class SpanTest
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan() public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan()
{ {
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
@ -446,10 +458,10 @@ public class SpanTest
long expected = span.PackByte(); long expected = span.PackByte();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan() public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan()
{ {
Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
@ -457,10 +469,10 @@ public class SpanTest
long expected = span.PackByte(); long expected = span.PackByte();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan() public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan()
{ {
ReadOnlySpan<bool> span = stackalloc bool[16] ReadOnlySpan<bool> span = stackalloc bool[16]
@ -471,10 +483,10 @@ public class SpanTest
long expected = span.PackInt16(); long expected = span.PackInt16();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan() public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan()
{ {
Span<bool> span = stackalloc bool[16] Span<bool> span = stackalloc bool[16]
@ -485,10 +497,10 @@ public class SpanTest
long expected = span.PackInt16(); long expected = span.PackInt16();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingReadOnlySpan() public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingReadOnlySpan()
{ {
ReadOnlySpan<bool> span = stackalloc bool[32] ReadOnlySpan<bool> span = stackalloc bool[32]
@ -500,10 +512,10 @@ public class SpanTest
long expected = span.PackInt32(); long expected = span.PackInt32();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingSpan() public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingSpan()
{ {
Span<bool> span = stackalloc bool[32] Span<bool> span = stackalloc bool[32]
@ -515,10 +527,10 @@ public class SpanTest
long expected = span.PackInt32(); long expected = span.PackInt32();
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingReadOnlySpan() public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingReadOnlySpan()
{ {
const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011; const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011;
@ -526,10 +538,10 @@ public class SpanTest
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingSpan() public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingSpan()
{ {
const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011; const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011;
@ -537,7 +549,7 @@ public class SpanTest
long actual = span.PackInt64(); long actual = span.PackInt64();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
private enum EnumByte : byte private enum EnumByte : byte

View File

@ -1,167 +1,181 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Drawing;
using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class CircleFTests public class CircleFTests
{ {
[TestMethod] [Test]
public void Area_ShouldBePiRadiusRadius_GivenUnitCircle() public void Area_ShouldBePiRadiusRadius_GivenUnitCircle()
{ {
var unitCircle = CircleF.Unit; var unitCircle = CircleF.Unit;
Assert.AreEqual(MathF.PI, unitCircle.Area); Assert.That(unitCircle.Area, Is.EqualTo(MathF.PI));
} }
[TestMethod] [Test]
public void Circumference_ShouldBe2PiRadius_GivenUnitCircle() public void Circumference_ShouldBe2PiRadius_GivenUnitCircle()
{ {
var unitCircle = CircleF.Unit; var unitCircle = CircleF.Unit;
Assert.AreEqual(2 * MathF.PI, unitCircle.Circumference, 1e-6f); Assert.That(unitCircle.Circumference, Is.EqualTo(2 * MathF.PI).Within(1e-6f));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(-1, CircleF.Empty.CompareTo(CircleF.Unit)); Assert.That(CircleF.Empty.CompareTo(CircleF.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(1, CircleF.Unit.CompareTo(CircleF.Empty)); Assert.That(CircleF.Unit.CompareTo(CircleF.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject()
{ {
Assert.AreEqual(-1, CircleF.Empty.CompareTo((object)CircleF.Unit)); Assert.That(CircleF.Empty.CompareTo((object)CircleF.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, CircleF.Unit.CompareTo(null)); Assert.That(CircleF.Unit.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitCircle() public void CompareTo_ShouldBeZero_GivenUnitCircle()
{ {
var unitCircle = CircleF.Unit; var unitCircle = CircleF.Unit;
Assert.AreEqual(0, unitCircle.CompareTo(unitCircle)); Assert.That(unitCircle.CompareTo(unitCircle), Is.Zero);
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => CircleF.Unit.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = CircleF.Unit.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Diameter_ShouldBe2_GivenUnitCircle() public void Diameter_ShouldBe2_GivenUnitCircle()
{ {
Assert.AreEqual(2.0f, CircleF.Unit.Diameter, 1e-6f); Assert.That(CircleF.Unit.Diameter, Is.EqualTo(2.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitCircles() public void Equals_ShouldBeTrue_GivenTwoUnitCircles()
{ {
var unitCircle1 = CircleF.Unit; var unitCircle1 = CircleF.Unit;
var unitCircle2 = CircleF.Unit; var unitCircle2 = CircleF.Unit;
Assert.AreEqual(unitCircle1, unitCircle2); Assert.Multiple(() =>
Assert.IsTrue(unitCircle1 == unitCircle2); {
Assert.IsFalse(unitCircle1 != unitCircle2); Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
Assert.That(unitCircle1 == unitCircle2);
Assert.That(unitCircle2 == unitCircle1);
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenUnitCirclesAsObjects() public void Equals_ShouldBeTrue_GivenUnitCirclesAsObjects()
{ {
CircleF unitCircle1 = CircleF.Unit; CircleF unitCircle1 = CircleF.Unit;
object unitCircle2 = CircleF.Unit; object unitCircle2 = CircleF.Unit;
Assert.AreEqual(unitCircle1, unitCircle2); Assert.Multiple(() =>
Assert.IsTrue(unitCircle1.Equals(unitCircle2)); {
Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentCircles() public void Equals_ShouldBeFalse_GivenDifferentCircles()
{ {
Assert.AreNotEqual(CircleF.Unit, CircleF.Empty); Assert.Multiple(() =>
Assert.IsFalse(CircleF.Unit == CircleF.Empty); {
Assert.IsTrue(CircleF.Unit != CircleF.Empty); Assert.That(CircleF.Empty, Is.Not.EqualTo(CircleF.Unit));
Assert.That(CircleF.Unit, Is.Not.EqualTo(CircleF.Empty));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.AreNotEqual((object?)null, CircleF.Empty); Assert.That(CircleF.Empty, Is.Not.EqualTo(null));
Assert.IsFalse(CircleF.Empty.Equals(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = CircleF.Empty.GetHashCode(); int hashCode = CircleF.Empty.GetHashCode();
Assert.AreEqual(hashCode, CircleF.Empty.GetHashCode()); Assert.That(CircleF.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitCircle() public void GetHashCode_ShouldBeCorrect_GivenUnitCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = CircleF.Unit.GetHashCode(); int hashCode = CircleF.Unit.GetHashCode();
Assert.AreEqual(hashCode, CircleF.Unit.GetHashCode()); Assert.That(CircleF.Unit.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentCircle_GivenCircle() public void op_Explicit_ShouldReturnEquivalentCircle_GivenCircle()
{ {
CircleF unitCircle = CircleF.Unit; CircleF unitCircle = CircleF.Unit;
Circle converted = (Circle)unitCircle; Circle converted = (Circle)unitCircle;
Assert.AreEqual(unitCircle, converted); Assert.Multiple(() =>
Assert.AreEqual(unitCircle.Radius, converted.Radius); {
Assert.AreEqual(unitCircle.Center, converted.Center); Assert.That(converted, Is.EqualTo((Circle)unitCircle));
Assert.That(converted.Radius, Is.EqualTo(unitCircle.Radius));
Assert.That((PointF)converted.Center, Is.EqualTo(unitCircle.Center));
});
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(CircleF.Unit > CircleF.Empty); Assert.That(CircleF.Unit, Is.GreaterThan(CircleF.Empty));
Assert.IsTrue(CircleF.Unit >= CircleF.Empty); Assert.That(CircleF.Unit, Is.GreaterThanOrEqualTo(CircleF.Empty));
Assert.IsFalse(CircleF.Unit < CircleF.Empty);
Assert.IsFalse(CircleF.Unit <= CircleF.Empty);
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentCircle_GivenCircle() public void op_Implicit_ShouldReturnEquivalentCircle_GivenCircle()
{ {
Circle unitCircle = Circle.Unit; Circle unitCircle = Circle.Unit;
CircleF converted = unitCircle; CircleF converted = unitCircle;
Assert.AreEqual(unitCircle, converted); Assert.Multiple(() =>
Assert.AreEqual(unitCircle.Radius, converted.Radius); {
Assert.AreEqual(unitCircle.Center, converted.Center); Assert.That(converted, Is.EqualTo((CircleF)unitCircle));
Assert.That(converted.Radius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.Center, Is.EqualTo((PointF)unitCircle.Center));
});
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(CircleF.Empty < CircleF.Unit); Assert.Multiple(() =>
Assert.IsTrue(CircleF.Empty <= CircleF.Unit); {
Assert.IsFalse(CircleF.Empty > CircleF.Unit); Assert.That(CircleF.Empty, Is.LessThan(CircleF.Unit));
Assert.IsFalse(CircleF.Empty >= CircleF.Unit); Assert.That(CircleF.Empty, Is.LessThanOrEqualTo(CircleF.Unit));
});
} }
[TestMethod] [Test]
public void Radius_ShouldBe0_GivenEmptyCircle() public void Radius_ShouldBe0_GivenEmptyCircle()
{ {
Assert.AreEqual(0.0f, CircleF.Empty.Radius, 1e-6f); Assert.That(CircleF.Empty.Radius, Is.EqualTo(0.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Radius_ShouldBe1_GivenUnitCircle() public void Radius_ShouldBe1_GivenUnitCircle()
{ {
Assert.AreEqual(1.0f, CircleF.Unit.Radius, 1e-6f); Assert.That(CircleF.Unit.Radius, Is.EqualTo(1.0f).Within(1e-6f));
} }
} }

View File

@ -1,145 +1,147 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class CircleTests public class CircleTests
{ {
[TestMethod] [Test]
public void Area_ShouldBePiRadiusRadius_GivenUnitCircle() public void Area_ShouldBePiRadiusRadius_GivenUnitCircle()
{ {
var unitCircle = Circle.Unit; var unitCircle = Circle.Unit;
Assert.AreEqual(MathF.PI * unitCircle.Radius * unitCircle.Radius, unitCircle.Area); Assert.That(unitCircle.Area, Is.EqualTo(MathF.PI * unitCircle.Radius * unitCircle.Radius));
} }
[TestMethod] [Test]
public void Circumference_ShouldBe2PiRadius_GivenUnitCircle() public void Circumference_ShouldBe2PiRadius_GivenUnitCircle()
{ {
var unitCircle = Circle.Unit; var unitCircle = Circle.Unit;
Assert.AreEqual(2.0f * MathF.PI * unitCircle.Radius, unitCircle.Circumference, 1e-6f); Assert.That(unitCircle.Circumference, Is.EqualTo(2.0f * MathF.PI * unitCircle.Radius).Within(1e-6f));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(-1, Circle.Empty.CompareTo(Circle.Unit)); Assert.That(Circle.Empty.CompareTo(Circle.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(1, Circle.Unit.CompareTo(Circle.Empty)); Assert.That(Circle.Unit.CompareTo(Circle.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject()
{ {
Assert.AreEqual(-1, Circle.Empty.CompareTo((object)Circle.Unit)); Assert.That(Circle.Empty.CompareTo((object)Circle.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, Circle.Unit.CompareTo(null)); Assert.That(Circle.Unit.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitCircle() public void CompareTo_ShouldBeZero_GivenUnitCircle()
{ {
var unitCircle = Circle.Unit; var unitCircle = Circle.Unit;
Assert.AreEqual(0, unitCircle.CompareTo(unitCircle)); Assert.That(unitCircle.CompareTo(unitCircle), Is.Zero);
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => Circle.Unit.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = Circle.Unit.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Diameter_ShouldBe2_GivenUnitCircle() public void Diameter_ShouldBe2_GivenUnitCircle()
{ {
Assert.AreEqual(2.0f, Circle.Unit.Diameter, 1e-6f); Assert.That(Circle.Unit.Diameter, Is.EqualTo(2.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitCircles() public void Equals_ShouldBeTrue_GivenTwoUnitCircles()
{ {
var unitCircle1 = Circle.Unit; var unitCircle1 = Circle.Unit;
var unitCircle2 = Circle.Unit; var unitCircle2 = Circle.Unit;
Assert.AreEqual(unitCircle1, unitCircle2); Assert.Multiple(() =>
Assert.IsTrue(unitCircle1 == unitCircle2); {
Assert.IsFalse(unitCircle1 != unitCircle2); Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenUnitCirclesAsObjects() public void Equals_ShouldBeTrue_GivenUnitCirclesAsObjects()
{ {
Circle unitCircle1 = Circle.Unit; Circle unitCircle1 = Circle.Unit;
object unitCircle2 = Circle.Unit; object unitCircle2 = Circle.Unit;
Assert.AreEqual(unitCircle1, unitCircle2); Assert.Multiple(() =>
Assert.IsTrue(unitCircle1.Equals(unitCircle2)); {
Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentCircles() public void Equals_ShouldBeFalse_GivenDifferentCircles()
{ {
Assert.AreNotEqual(Circle.Unit, Circle.Empty); Assert.Multiple(() =>
Assert.IsFalse(Circle.Unit == Circle.Empty); {
Assert.IsTrue(Circle.Unit != Circle.Empty); Assert.That(Circle.Empty, Is.Not.EqualTo(Circle.Unit));
Assert.That(Circle.Unit, Is.Not.EqualTo(Circle.Empty));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.AreNotEqual((object?)null, Circle.Empty); Assert.That(Circle.Empty, Is.Not.EqualTo(null));
Assert.IsFalse(Circle.Empty.Equals(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Circle.Empty.GetHashCode(); int hashCode = Circle.Empty.GetHashCode();
Assert.AreEqual(hashCode, Circle.Empty.GetHashCode()); Assert.That(Circle.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitCircle() public void GetHashCode_ShouldBeCorrect_GivenUnitCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Circle.Unit.GetHashCode(); int hashCode = Circle.Unit.GetHashCode();
Assert.AreEqual(hashCode, Circle.Unit.GetHashCode()); Assert.That(Circle.Unit.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(Circle.Unit > Circle.Empty); Assert.That(Circle.Unit, Is.GreaterThan(Circle.Empty));
Assert.IsTrue(Circle.Unit >= Circle.Empty); Assert.That(Circle.Unit, Is.GreaterThanOrEqualTo(Circle.Empty));
Assert.IsFalse(Circle.Unit < Circle.Empty);
Assert.IsFalse(Circle.Unit <= Circle.Empty);
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(Circle.Empty < Circle.Unit); Assert.That(Circle.Empty, Is.LessThan(Circle.Unit));
Assert.IsTrue(Circle.Empty <= Circle.Unit); Assert.That(Circle.Empty, Is.LessThanOrEqualTo(Circle.Unit));
Assert.IsFalse(Circle.Empty > Circle.Unit);
Assert.IsFalse(Circle.Empty >= Circle.Unit);
} }
[TestMethod] [Test]
public void Radius_ShouldBe0_GivenEmptyCircle() public void Radius_ShouldBe0_GivenEmptyCircle()
{ {
Assert.AreEqual(0, Circle.Empty.Radius); Assert.That(Circle.Empty.Radius, Is.Zero);
} }
[TestMethod] [Test]
public void Radius_ShouldBe1_GivenUnitCircle() public void Radius_ShouldBe1_GivenUnitCircle()
{ {
Assert.AreEqual(1, Circle.Unit.Radius); Assert.That(Circle.Unit.Radius, Is.EqualTo(1));
} }
} }

View File

@ -1,10 +1,10 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class ColorTests public class ColorTests
{ {
private static readonly Color Black = Color.FromArgb(0, 0, 0); private static readonly Color Black = Color.FromArgb(0, 0, 0);
@ -16,251 +16,278 @@ public class ColorTests
private static readonly Color Magenta = Color.FromArgb(255, 0, 255); private static readonly Color Magenta = Color.FromArgb(255, 0, 255);
private static readonly Color Yellow = Color.FromArgb(255, 255, 0); private static readonly Color Yellow = Color.FromArgb(255, 255, 0);
[TestMethod] [Test]
public void Deconstruct_ShouldDeconstructColor_GivenColor() public void Deconstruct_ShouldDeconstructColor_GivenColor()
{ {
(byte r, byte g, byte b) = Black; (byte r, byte g, byte b) = Black;
Assert.AreEqual(0, r); Assert.Multiple(() =>
Assert.AreEqual(0, g); {
Assert.AreEqual(0, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.Zero);
Assert.That(b, Is.Zero);
});
(byte a, r, g, b) = Black; (byte a, r, g, b) = Black;
Assert.AreEqual(255, a); Assert.Multiple(() =>
Assert.AreEqual(0, r); {
Assert.AreEqual(0, g); Assert.That(a, Is.EqualTo(255));
Assert.AreEqual(0, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.Zero);
Assert.That(b, Is.Zero);
});
(r, g, b) = Red; (r, g, b) = Red;
Assert.AreEqual(255, r); Assert.Multiple(() =>
Assert.AreEqual(0, g); {
Assert.AreEqual(0, b); Assert.That(r, Is.EqualTo(255));
Assert.That(g, Is.Zero);
Assert.That(b, Is.Zero);
});
(a, r, g, b) = Red; (a, r, g, b) = Red;
Assert.AreEqual(255, a); Assert.Multiple(() =>
Assert.AreEqual(255, r); {
Assert.AreEqual(0, g); Assert.That(a, Is.EqualTo(255));
Assert.AreEqual(0, b); Assert.That(r, Is.EqualTo(255));
Assert.That(g, Is.Zero);
Assert.That(b, Is.Zero);
});
(r, g, b) = Green; (r, g, b) = Green;
Assert.AreEqual(0, r); Assert.Multiple(() =>
Assert.AreEqual(255, g); {
Assert.AreEqual(0, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.EqualTo(255));
Assert.That(b, Is.Zero);
});
(a, r, g, b) = Green; (a, r, g, b) = Green;
Assert.AreEqual(255, a); Assert.Multiple(() =>
Assert.AreEqual(0, r); {
Assert.AreEqual(255, g); Assert.That(a, Is.EqualTo(255));
Assert.AreEqual(0, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.EqualTo(255));
Assert.That(b, Is.Zero);
});
(r, g, b) = Blue; (r, g, b) = Blue;
Assert.AreEqual(0, r); Assert.Multiple(() =>
Assert.AreEqual(0, g); {
Assert.AreEqual(255, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.Zero);
Assert.That(b, Is.EqualTo(255));
});
(a, r, g, b) = Blue; (a, r, g, b) = Blue;
Assert.AreEqual(255, a); Assert.Multiple(() =>
Assert.AreEqual(0, r); {
Assert.AreEqual(0, g); Assert.That(a, Is.EqualTo(255));
Assert.AreEqual(255, b); Assert.That(r, Is.Zero);
Assert.That(g, Is.Zero);
Assert.That(b, Is.EqualTo(255));
});
} }
[TestMethod] [Test]
public void GetClosestConsoleColor_ShouldReturnClosestColor_GivenValidColor() public void GetClosestConsoleColor_ShouldReturnClosestColor_GivenValidColor()
{ {
Assert.AreEqual(ConsoleColor.White, Color.Transparent.GetClosestConsoleColor()); Assert.Multiple(() =>
Assert.AreEqual(ConsoleColor.White, Color.AliceBlue.GetClosestConsoleColor()); {
Assert.AreEqual(ConsoleColor.White, Color.AntiqueWhite.GetClosestConsoleColor()); Assert.That(Color.Transparent.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Cyan, Color.Aqua.GetClosestConsoleColor()); Assert.That(Color.AliceBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Aquamarine.GetClosestConsoleColor()); Assert.That(Color.AntiqueWhite.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.Azure.GetClosestConsoleColor()); Assert.That(Color.Aqua.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.White, Color.Beige.GetClosestConsoleColor()); Assert.That(Color.Aquamarine.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.Bisque.GetClosestConsoleColor()); Assert.That(Color.Azure.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Black, Color.Black.GetClosestConsoleColor()); Assert.That(Color.Beige.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.BlanchedAlmond.GetClosestConsoleColor()); Assert.That(Color.Bisque.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Blue, Color.Blue.GetClosestConsoleColor()); Assert.That(Color.Black.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Black));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.BlueViolet.GetClosestConsoleColor()); Assert.That(Color.BlanchedAlmond.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkRed, Color.Brown.GetClosestConsoleColor()); Assert.That(Color.Blue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Blue));
Assert.AreEqual(ConsoleColor.DarkGray, Color.BurlyWood.GetClosestConsoleColor()); Assert.That(Color.BlueViolet.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.Gray, Color.CadetBlue.GetClosestConsoleColor()); Assert.That(Color.Brown.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.Yellow, Color.Chartreuse.GetClosestConsoleColor()); Assert.That(Color.BurlyWood.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Chocolate.GetClosestConsoleColor()); Assert.That(Color.CadetBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Coral.GetClosestConsoleColor()); Assert.That(Color.Chartreuse.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
Assert.AreEqual(ConsoleColor.DarkGray, Color.CornflowerBlue.GetClosestConsoleColor()); Assert.That(Color.Chocolate.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.White, Color.Cornsilk.GetClosestConsoleColor()); Assert.That(Color.Coral.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.Red, Color.Crimson.GetClosestConsoleColor()); Assert.That(Color.CornflowerBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Cyan, Color.Cyan.GetClosestConsoleColor()); Assert.That(Color.Cornsilk.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkBlue, Color.DarkBlue.GetClosestConsoleColor()); Assert.That(Color.Crimson.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Red));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.DarkCyan.GetClosestConsoleColor()); Assert.That(Color.Cyan.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.DarkGoldenrod.GetClosestConsoleColor()); Assert.That(Color.DarkBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkBlue));
Assert.AreEqual(ConsoleColor.DarkGray, Color.DarkGray.GetClosestConsoleColor()); Assert.That(Color.DarkCyan.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.DarkGreen, Color.DarkGreen.GetClosestConsoleColor()); Assert.That(Color.DarkGoldenrod.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.DarkGray, Color.DarkKhaki.GetClosestConsoleColor()); Assert.That(Color.DarkGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.DarkMagenta.GetClosestConsoleColor()); Assert.That(Color.DarkGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGreen));
Assert.AreEqual(ConsoleColor.Gray, Color.DarkOliveGreen.GetClosestConsoleColor()); Assert.That(Color.DarkKhaki.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.DarkOrange.GetClosestConsoleColor()); Assert.That(Color.DarkMagenta.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.DarkOrchid.GetClosestConsoleColor()); Assert.That(Color.DarkOliveGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkRed, Color.DarkRed.GetClosestConsoleColor()); Assert.That(Color.DarkOrange.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.DarkGray, Color.DarkSalmon.GetClosestConsoleColor()); Assert.That(Color.DarkOrchid.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.DarkGray, Color.DarkSeaGreen.GetClosestConsoleColor()); Assert.That(Color.DarkRed.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.Gray, Color.DarkSlateBlue.GetClosestConsoleColor()); Assert.That(Color.DarkSalmon.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGreen, Color.DarkSlateGray.GetClosestConsoleColor()); Assert.That(Color.DarkSeaGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Cyan, Color.DarkTurquoise.GetClosestConsoleColor()); Assert.That(Color.DarkSlateBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.DarkViolet.GetClosestConsoleColor()); Assert.That(Color.DarkSlateGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGreen));
Assert.AreEqual(ConsoleColor.Magenta, Color.DeepPink.GetClosestConsoleColor()); Assert.That(Color.DarkTurquoise.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.Cyan, Color.DeepSkyBlue.GetClosestConsoleColor()); Assert.That(Color.DarkViolet.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.Gray, Color.DimGray.GetClosestConsoleColor()); Assert.That(Color.DeepPink.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Magenta));
Assert.AreEqual(ConsoleColor.Cyan, Color.DodgerBlue.GetClosestConsoleColor()); Assert.That(Color.DeepSkyBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.DarkRed, Color.Firebrick.GetClosestConsoleColor()); Assert.That(Color.DimGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.White, Color.FloralWhite.GetClosestConsoleColor()); Assert.That(Color.DodgerBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.Green, Color.ForestGreen.GetClosestConsoleColor()); Assert.That(Color.Firebrick.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.Magenta, Color.Fuchsia.GetClosestConsoleColor()); Assert.That(Color.FloralWhite.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.Gainsboro.GetClosestConsoleColor()); Assert.That(Color.ForestGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Green));
Assert.AreEqual(ConsoleColor.White, Color.GhostWhite.GetClosestConsoleColor()); Assert.That(Color.Fuchsia.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Magenta));
Assert.AreEqual(ConsoleColor.Yellow, Color.Gold.GetClosestConsoleColor()); Assert.That(Color.Gainsboro.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Goldenrod.GetClosestConsoleColor()); Assert.That(Color.GhostWhite.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Gray, Color.Gray.GetClosestConsoleColor()); Assert.That(Color.Gold.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
Assert.AreEqual(ConsoleColor.Green, Color.Green.GetClosestConsoleColor()); Assert.That(Color.Goldenrod.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.Yellow, Color.GreenYellow.GetClosestConsoleColor()); Assert.That(Color.Gray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.White, Color.Honeydew.GetClosestConsoleColor()); Assert.That(Color.Green.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Green));
Assert.AreEqual(ConsoleColor.DarkGray, Color.HotPink.GetClosestConsoleColor()); Assert.That(Color.GreenYellow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
Assert.AreEqual(ConsoleColor.Gray, Color.IndianRed.GetClosestConsoleColor()); Assert.That(Color.Honeydew.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.Indigo.GetClosestConsoleColor()); Assert.That(Color.HotPink.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.Ivory.GetClosestConsoleColor()); Assert.That(Color.IndianRed.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Khaki.GetClosestConsoleColor()); Assert.That(Color.Indigo.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.White, Color.Lavender.GetClosestConsoleColor()); Assert.That(Color.Ivory.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.LavenderBlush.GetClosestConsoleColor()); Assert.That(Color.Khaki.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Yellow, Color.LawnGreen.GetClosestConsoleColor()); Assert.That(Color.Lavender.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.LemonChiffon.GetClosestConsoleColor()); Assert.That(Color.LavenderBlush.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightBlue.GetClosestConsoleColor()); Assert.That(Color.LawnGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightCoral.GetClosestConsoleColor()); Assert.That(Color.LemonChiffon.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.LightCyan.GetClosestConsoleColor()); Assert.That(Color.LightBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.LightGoldenrodYellow.GetClosestConsoleColor()); Assert.That(Color.LightCoral.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightGreen.GetClosestConsoleColor()); Assert.That(Color.LightCyan.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightGray.GetClosestConsoleColor()); Assert.That(Color.LightGoldenrodYellow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightPink.GetClosestConsoleColor()); Assert.That(Color.LightGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightSalmon.GetClosestConsoleColor()); Assert.That(Color.LightGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.LightSeaGreen.GetClosestConsoleColor()); Assert.That(Color.LightPink.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightSkyBlue.GetClosestConsoleColor()); Assert.That(Color.LightSalmon.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Gray, Color.LightSlateGray.GetClosestConsoleColor()); Assert.That(Color.LightSeaGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.DarkGray, Color.LightSteelBlue.GetClosestConsoleColor()); Assert.That(Color.LightSkyBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.LightYellow.GetClosestConsoleColor()); Assert.That(Color.LightSlateGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.Green, Color.Lime.GetClosestConsoleColor()); Assert.That(Color.LightSteelBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Green, Color.LimeGreen.GetClosestConsoleColor()); Assert.That(Color.LightYellow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.Linen.GetClosestConsoleColor()); Assert.That(Color.Lime.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Green));
Assert.AreEqual(ConsoleColor.Magenta, Color.Magenta.GetClosestConsoleColor()); Assert.That(Color.LimeGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Green));
Assert.AreEqual(ConsoleColor.DarkRed, Color.Maroon.GetClosestConsoleColor()); Assert.That(Color.Linen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.MediumAquamarine.GetClosestConsoleColor()); Assert.That(Color.Magenta.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Magenta));
Assert.AreEqual(ConsoleColor.Blue, Color.MediumBlue.GetClosestConsoleColor()); Assert.That(Color.Maroon.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.DarkGray, Color.MediumOrchid.GetClosestConsoleColor()); Assert.That(Color.MediumAquamarine.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.MediumPurple.GetClosestConsoleColor()); Assert.That(Color.MediumBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Blue));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.MediumSeaGreen.GetClosestConsoleColor()); Assert.That(Color.MediumOrchid.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.MediumSlateBlue.GetClosestConsoleColor()); Assert.That(Color.MediumPurple.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Cyan, Color.MediumSpringGreen.GetClosestConsoleColor()); Assert.That(Color.MediumSeaGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.Cyan, Color.MediumTurquoise.GetClosestConsoleColor()); Assert.That(Color.MediumSlateBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.MediumVioletRed.GetClosestConsoleColor()); Assert.That(Color.MediumSpringGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.DarkBlue, Color.MidnightBlue.GetClosestConsoleColor()); Assert.That(Color.MediumTurquoise.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.White, Color.MintCream.GetClosestConsoleColor()); Assert.That(Color.MediumVioletRed.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
Assert.AreEqual(ConsoleColor.White, Color.MistyRose.GetClosestConsoleColor()); Assert.That(Color.MidnightBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkBlue));
Assert.AreEqual(ConsoleColor.White, Color.Moccasin.GetClosestConsoleColor()); Assert.That(Color.MintCream.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.NavajoWhite.GetClosestConsoleColor()); Assert.That(Color.MistyRose.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkBlue, Color.Navy.GetClosestConsoleColor()); Assert.That(Color.Moccasin.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.OldLace.GetClosestConsoleColor()); Assert.That(Color.NavajoWhite.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Gray, Color.Olive.GetClosestConsoleColor()); Assert.That(Color.Navy.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkBlue));
Assert.AreEqual(ConsoleColor.Gray, Color.OliveDrab.GetClosestConsoleColor()); Assert.That(Color.OldLace.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Orange.GetClosestConsoleColor()); Assert.That(Color.Olive.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.Red, Color.OrangeRed.GetClosestConsoleColor()); Assert.That(Color.OliveDrab.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Orchid.GetClosestConsoleColor()); Assert.That(Color.Orange.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.White, Color.PaleGoldenrod.GetClosestConsoleColor()); Assert.That(Color.OrangeRed.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Red));
Assert.AreEqual(ConsoleColor.DarkGray, Color.PaleGreen.GetClosestConsoleColor()); Assert.That(Color.Orchid.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.PaleTurquoise.GetClosestConsoleColor()); Assert.That(Color.PaleGoldenrod.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.PaleVioletRed.GetClosestConsoleColor()); Assert.That(Color.PaleGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.PapayaWhip.GetClosestConsoleColor()); Assert.That(Color.PaleTurquoise.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.PeachPuff.GetClosestConsoleColor()); Assert.That(Color.PaleVioletRed.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Peru.GetClosestConsoleColor()); Assert.That(Color.PapayaWhip.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.Pink.GetClosestConsoleColor()); Assert.That(Color.PeachPuff.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Plum.GetClosestConsoleColor()); Assert.That(Color.Peru.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.DarkGray, Color.PowderBlue.GetClosestConsoleColor()); Assert.That(Color.Pink.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.Purple.GetClosestConsoleColor()); Assert.That(Color.Plum.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.That(Color.PowderBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.That(Color.Purple.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
Assert.AreEqual(ConsoleColor.DarkMagenta, Color.RebeccaPurple.GetClosestConsoleColor()); Assert.That(Color.RebeccaPurple.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkMagenta));
#endif #endif
Assert.AreEqual(ConsoleColor.Red, Color.Red.GetClosestConsoleColor()); Assert.That(Color.Red.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Red));
Assert.AreEqual(ConsoleColor.DarkGray, Color.RosyBrown.GetClosestConsoleColor()); Assert.That(Color.RosyBrown.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.RoyalBlue.GetClosestConsoleColor()); Assert.That(Color.RoyalBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.DarkRed, Color.SaddleBrown.GetClosestConsoleColor()); Assert.That(Color.SaddleBrown.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Salmon.GetClosestConsoleColor()); Assert.That(Color.Salmon.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.SandyBrown.GetClosestConsoleColor()); Assert.That(Color.SandyBrown.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.SeaGreen.GetClosestConsoleColor()); Assert.That(Color.SeaGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.White, Color.SeaShell.GetClosestConsoleColor()); Assert.That(Color.SeaShell.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkRed, Color.Sienna.GetClosestConsoleColor()); Assert.That(Color.Sienna.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkRed));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Silver.GetClosestConsoleColor()); Assert.That(Color.Silver.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.SkyBlue.GetClosestConsoleColor()); Assert.That(Color.SkyBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.Gray, Color.SlateBlue.GetClosestConsoleColor()); Assert.That(Color.SlateBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.Gray, Color.SlateGray.GetClosestConsoleColor()); Assert.That(Color.SlateGray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.White, Color.Snow.GetClosestConsoleColor()); Assert.That(Color.Snow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.SpringGreen.GetClosestConsoleColor()); Assert.That(Color.SpringGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.Gray, Color.SteelBlue.GetClosestConsoleColor()); Assert.That(Color.SteelBlue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Tan.GetClosestConsoleColor()); Assert.That(Color.Tan.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkCyan, Color.Teal.GetClosestConsoleColor()); Assert.That(Color.Teal.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkCyan));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Thistle.GetClosestConsoleColor()); Assert.That(Color.Thistle.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.DarkYellow, Color.Tomato.GetClosestConsoleColor()); Assert.That(Color.Tomato.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkYellow));
Assert.AreEqual(ConsoleColor.Cyan, Color.Turquoise.GetClosestConsoleColor()); Assert.That(Color.Turquoise.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
Assert.AreEqual(ConsoleColor.DarkGray, Color.Violet.GetClosestConsoleColor()); Assert.That(Color.Violet.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.DarkGray));
Assert.AreEqual(ConsoleColor.White, Color.Wheat.GetClosestConsoleColor()); Assert.That(Color.Wheat.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.White.GetClosestConsoleColor()); Assert.That(Color.White.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.White, Color.WhiteSmoke.GetClosestConsoleColor()); Assert.That(Color.WhiteSmoke.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
Assert.AreEqual(ConsoleColor.Yellow, Color.Yellow.GetClosestConsoleColor()); Assert.That(Color.Yellow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
Assert.AreEqual(ConsoleColor.Gray, Color.YellowGreen.GetClosestConsoleColor()); Assert.That(Color.YellowGreen.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
});
} }
[TestMethod] [Test]
public void Inverted_ShouldReturnInvertedColor() public void Inverted_ShouldReturnInvertedColor()
{ {
Assert.AreEqual(White, Black.Inverted()); Assert.That(Black.Inverted(), Is.EqualTo(White));
Assert.AreEqual(Black, White.Inverted()); Assert.That(White.Inverted(), Is.EqualTo(Black));
Assert.AreEqual(Red, Cyan.Inverted()); Assert.That(Cyan.Inverted(), Is.EqualTo(Red));
Assert.AreEqual(Cyan, Red.Inverted()); Assert.That(Red.Inverted(), Is.EqualTo(Cyan));
Assert.AreEqual(Green, Magenta.Inverted()); Assert.That(Magenta.Inverted(), Is.EqualTo(Green));
Assert.AreEqual(Magenta, Green.Inverted()); Assert.That(Green.Inverted(), Is.EqualTo(Magenta));
Assert.AreEqual(Yellow, Blue.Inverted()); Assert.That(Blue.Inverted(), Is.EqualTo(Yellow));
Assert.AreEqual(Blue, Yellow.Inverted()); Assert.That(Yellow.Inverted(), Is.EqualTo(Blue));
} }
[TestMethod] [Test]
public void Inverted_ShouldIgnoreAlpha() public void Inverted_ShouldIgnoreAlpha()
{ {
Color expected = Color.FromArgb(255, 0, 0, 0); Color expected = Color.FromArgb(255, 0, 0, 0);
Color actual = Color.FromArgb(255, 255, 255, 255).Inverted(); Color actual = Color.FromArgb(255, 255, 255, 255).Inverted();
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void WithA0_ShouldReturnSameColor_GivenWhite() public void WithA0_ShouldReturnSameColor_GivenWhite()
{ {
Color transparent = Color.FromArgb(0, 255, 255, 255); Color transparent = Color.FromArgb(0, 255, 255, 255);
Assert.AreEqual(transparent, White.WithA(0)); Assert.That(White.WithA(0), Is.EqualTo(transparent));
Assert.AreEqual(transparent, transparent.WithA(0)); Assert.That(transparent.WithA(0), Is.EqualTo(transparent));
} }
[TestMethod] [Test]
public void WithB0_ShouldReturnYellow_GivenWhite() public void WithB0_ShouldReturnYellow_GivenWhite()
{ {
Assert.AreEqual(Yellow, White.WithB(0)); Assert.That(White.WithB(0), Is.EqualTo(Yellow));
Assert.AreEqual(Yellow, Yellow.WithB(0)); Assert.That(Yellow.WithB(0), Is.EqualTo(Yellow));
} }
[TestMethod] [Test]
public void WithG0_ShouldReturnMagenta_GivenWhite() public void WithG0_ShouldReturnMagenta_GivenWhite()
{ {
Assert.AreEqual(Magenta, White.WithG(0)); Assert.That(White.WithG(0), Is.EqualTo(Magenta));
Assert.AreEqual(Magenta, Magenta.WithG(0)); Assert.That(Magenta.WithG(0), Is.EqualTo(Magenta));
} }
[TestMethod] [Test]
public void WithR0_ShouldReturnCyan_GivenWhite() public void WithR0_ShouldReturnCyan_GivenWhite()
{ {
Assert.AreEqual(Cyan, White.WithR(0)); Assert.That(White.WithR(0), Is.EqualTo(Cyan));
Assert.AreEqual(Cyan, Cyan.WithR(0)); Assert.That(Cyan.WithR(0), Is.EqualTo(Cyan));
} }
} }

View File

@ -1,82 +1,79 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class CuboidTests public class CuboidTests
{ {
[TestMethod] [Test]
public void Corners_ShouldBeCorrect_GivenCubeOfSize1() public void Corners_ShouldBeCorrect_GivenCubeOfSize1()
{ {
Cuboid cube = Cuboid.Cube; Cuboid cube = Cuboid.Cube;
Assert.AreEqual(new Vector3(0.5f, 0.5f, -0.5f), cube.FrontTopRight); Assert.That(cube.FrontTopRight, Is.EqualTo(new Vector3(0.5f, 0.5f, -0.5f)));
Assert.AreEqual(new Vector3(-0.5f, 0.5f, -0.5f), cube.FrontTopLeft); Assert.That(cube.FrontTopLeft, Is.EqualTo(new Vector3(-0.5f, 0.5f, -0.5f)));
Assert.AreEqual(new Vector3(0.5f, -0.5f, -0.5f), cube.FrontBottomRight); Assert.That(cube.FrontBottomRight, Is.EqualTo(new Vector3(0.5f, -0.5f, -0.5f)));
Assert.AreEqual(new Vector3(-0.5f, -0.5f, -0.5f), cube.FrontBottomLeft); Assert.That(cube.FrontBottomLeft, Is.EqualTo(new Vector3(-0.5f, -0.5f, -0.5f)));
Assert.AreEqual(new Vector3(0.5f, 0.5f, 0.5f), cube.BackTopRight); Assert.That(cube.BackTopRight, Is.EqualTo(new Vector3(0.5f, 0.5f, 0.5f)));
Assert.AreEqual(new Vector3(-0.5f, 0.5f, 0.5f), cube.BackTopLeft); Assert.That(cube.BackTopLeft, Is.EqualTo(new Vector3(-0.5f, 0.5f, 0.5f)));
Assert.AreEqual(new Vector3(0.5f, -0.5f, 0.5f), cube.BackBottomRight); Assert.That(cube.BackBottomRight, Is.EqualTo(new Vector3(0.5f, -0.5f, 0.5f)));
Assert.AreEqual(new Vector3(-0.5f, -0.5f, 0.5f), cube.BackBottomLeft); Assert.That(cube.BackBottomLeft, Is.EqualTo(new Vector3(-0.5f, -0.5f, 0.5f)));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoCubesOfSize1() public void Equals_ShouldBeTrue_GivenTwoCubesOfSize1()
{ {
var cube1 = Cuboid.Cube; var cube1 = Cuboid.Cube;
var cube2 = Cuboid.Cube; var cube2 = Cuboid.Cube;
Assert.AreEqual(cube1, cube2); Assert.That(cube1, Is.EqualTo(cube2));
Assert.IsTrue(cube1 == cube2); Assert.That(cube2, Is.EqualTo(cube1));
Assert.IsFalse(cube1 != cube2);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentCubes() public void Equals_ShouldBeFalse_GivenDifferentCubes()
{ {
Assert.AreNotEqual(Cuboid.Cube, Cuboid.Empty); Assert.That(Cuboid.Empty, Is.Not.EqualTo(Cuboid.Cube));
Assert.IsFalse(Cuboid.Cube == Cuboid.Empty);
Assert.IsTrue(Cuboid.Cube != Cuboid.Empty);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(Cuboid.Cube.Equals(null)); Assert.That(Cuboid.Cube.Equals(null), Is.False);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Cuboid.Empty.GetHashCode(); int hashCode = Cuboid.Empty.GetHashCode();
Assert.AreEqual(hashCode, Cuboid.Empty.GetHashCode()); Assert.That(Cuboid.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenCubeOfSize1() public void GetHashCode_ShouldBeCorrect_GivenCubeOfSize1()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Cuboid.Cube.GetHashCode(); int hashCode = Cuboid.Cube.GetHashCode();
Assert.AreEqual(hashCode, Cuboid.Cube.GetHashCode()); Assert.That(Cuboid.Cube.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void Size_ShouldBeOne_GivenCubeOfSize1() public void Size_ShouldBeOne_GivenCubeOfSize1()
{ {
Assert.AreEqual(Vector3.One, Cuboid.Cube.Size); Assert.That(Cuboid.Cube.Size, Is.EqualTo(Vector3.One));
} }
[TestMethod] [Test]
public void Size_ShouldBeOne_GivenRotatedCube() public void Size_ShouldBeOne_GivenRotatedCube()
{ {
Assert.AreEqual(Vector3.One, new Cuboid(0, 0, 0, 1, 1, 1, 90, 0, 0).Size); Assert.That(new Cuboid(0, 0, 0, 1, 1, 1, 90, 0, 0).Size, Is.EqualTo(Vector3.One));
} }
[TestMethod] [Test]
public void Volume_ShouldBe1_GivenCubeOfSize1() public void Volume_ShouldBe1_GivenCubeOfSize1()
{ {
Assert.AreEqual(1.0f, Cuboid.Cube.Volume, 1e-6f); Assert.That(Cuboid.Cube.Volume, Is.EqualTo(1.0f).Within(1e-6f));
} }
} }

View File

@ -1,156 +1,165 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class EllipseFTests public class EllipseFTests
{ {
[TestMethod] [Test]
public void Area_ShouldBePiRadiusRadius_GivenUnitEllipse() public void Area_ShouldBePiRadiusRadius_GivenUnitEllipse()
{ {
var unitEllipse = EllipseF.Unit; var unitEllipse = EllipseF.Unit;
Assert.AreEqual(MathF.PI, unitEllipse.Area, 1e-6f); Assert.That(unitEllipse.Area, Is.EqualTo(MathF.PI).Within(1e-6f));
} }
[TestMethod] [Test]
public void ApproximateCircumference_ShouldBe2PiRadius_GivenUnitEllipse() public void ApproximateCircumference_ShouldBe2PiRadius_GivenUnitEllipse()
{ {
var unitEllipse = EllipseF.Unit; var unitEllipse = EllipseF.Unit;
Assert.AreEqual(2 * MathF.PI, unitEllipse.ApproximateCircumference, 1e-6f); Assert.That(unitEllipse.ApproximateCircumference, Is.EqualTo(2 * MathF.PI).Within(1e-6f));
} }
[TestMethod] [Test]
public void Constructor_ShouldGiveCorrectEllipse() public void Constructor_ShouldGiveCorrectEllipse()
{ {
var ellipse = new EllipseF(PointF.Empty, new SizeF(2, 1)); var ellipse = new EllipseF(PointF.Empty, new SizeF(2, 1));
Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.That(ellipse.Center, Is.EqualTo(new PointF(0, 0)));
Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); Assert.That(ellipse.Radius, Is.EqualTo(new SizeF(2, 1)));
ellipse = new EllipseF(0, 0, 2, 1); ellipse = new EllipseF(0, 0, 2, 1);
Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.That(ellipse.Center, Is.EqualTo(new PointF(0, 0)));
Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); Assert.That(ellipse.Radius, Is.EqualTo(new SizeF(2, 1)));
ellipse = new EllipseF(PointF.Empty, new Vector2(2, 1)); ellipse = new EllipseF(PointF.Empty, new Vector2(2, 1));
Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.That(ellipse.Center, Is.EqualTo(new PointF(0, 0)));
Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); Assert.That(ellipse.Radius, Is.EqualTo(new SizeF(2, 1)));
ellipse = new EllipseF(Vector2.Zero, new Vector2(2, 1)); ellipse = new EllipseF(Vector2.Zero, new Vector2(2, 1));
Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.That(ellipse.Center, Is.EqualTo(new PointF(0, 0)));
Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); Assert.That(ellipse.Radius, Is.EqualTo(new SizeF(2, 1)));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitEllipses() public void Equals_ShouldBeTrue_GivenTwoUnitEllipses()
{ {
var unitEllipse1 = EllipseF.Unit; var unitEllipse1 = EllipseF.Unit;
var unitEllipse2 = EllipseF.Unit; var unitEllipse2 = EllipseF.Unit;
Assert.AreEqual(unitEllipse1, unitEllipse2); Assert.That(unitEllipse2, Is.EqualTo(unitEllipse1));
Assert.IsTrue(unitEllipse1 == unitEllipse2); Assert.That(unitEllipse1, Is.EqualTo(unitEllipse2));
Assert.IsFalse(unitEllipse1 != unitEllipse2);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentEllipses() public void Equals_ShouldBeFalse_GivenDifferentEllipses()
{ {
Assert.AreNotEqual(EllipseF.Unit, EllipseF.Empty); Assert.That(EllipseF.Empty, Is.Not.EqualTo(EllipseF.Unit));
Assert.IsFalse(EllipseF.Unit == EllipseF.Empty);
Assert.IsTrue(EllipseF.Unit != EllipseF.Empty);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(EllipseF.Unit.Equals(null)); Assert.That(EllipseF.Unit, Is.Not.EqualTo(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyEllipse() public void GetHashCode_ShouldBeCorrect_GivenEmptyEllipse()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = EllipseF.Empty.GetHashCode(); int hashCode = EllipseF.Empty.GetHashCode();
Assert.AreEqual(hashCode, EllipseF.Empty.GetHashCode()); Assert.That(EllipseF.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitEllipse() public void GetHashCode_ShouldBeCorrect_GivenUnitEllipse()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = EllipseF.Unit.GetHashCode(); int hashCode = EllipseF.Unit.GetHashCode();
Assert.AreEqual(hashCode, EllipseF.Unit.GetHashCode()); Assert.That(EllipseF.Unit.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void HorizontalRadius_ShouldBe0_GivenEmptyEllipse() public void HorizontalRadius_ShouldBe0_GivenEmptyEllipse()
{ {
Assert.AreEqual(0, EllipseF.Empty.HorizontalRadius); Assert.That(EllipseF.Empty.HorizontalRadius, Is.Zero);
} }
[TestMethod] [Test]
public void HorizontalRadius_ShouldBe1_GivenUnitEllipse() public void HorizontalRadius_ShouldBe1_GivenUnitEllipse()
{ {
Assert.AreEqual(1, EllipseF.Unit.HorizontalRadius); Assert.That(EllipseF.Unit.HorizontalRadius, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentEllipse_GivenEllipse() public void op_Explicit_ShouldReturnEquivalentEllipse_GivenEllipse()
{ {
EllipseF unitEllipse = EllipseF.Unit; EllipseF unitEllipse = EllipseF.Unit;
Ellipse converted = (Ellipse)unitEllipse; Ellipse converted = (Ellipse)unitEllipse;
Assert.AreEqual(unitEllipse, converted); Assert.Multiple(() =>
Assert.AreEqual(unitEllipse.HorizontalRadius, converted.HorizontalRadius); {
Assert.AreEqual(unitEllipse.VerticalRadius, converted.VerticalRadius); Assert.That(converted, Is.EqualTo((Ellipse)unitEllipse));
Assert.AreEqual(unitEllipse.Center, converted.Center); Assert.That(converted.HorizontalRadius, Is.EqualTo(unitEllipse.HorizontalRadius));
Assert.That(converted.VerticalRadius, Is.EqualTo(unitEllipse.VerticalRadius));
Assert.That((PointF)converted.Center, Is.EqualTo(unitEllipse.Center));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircle() public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircle()
{ {
Circle unitCircle = Circle.Unit; Circle unitCircle = Circle.Unit;
EllipseF converted = unitCircle; EllipseF converted = unitCircle;
Assert.AreEqual(unitCircle, converted); Assert.Multiple(() =>
Assert.AreEqual(unitCircle.Radius, converted.HorizontalRadius); {
Assert.AreEqual(unitCircle.Radius, converted.VerticalRadius); Assert.That(converted, Is.EqualTo((EllipseF)unitCircle));
Assert.AreEqual(unitCircle.Center, converted.Center); Assert.That(converted.HorizontalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.VerticalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.Center, Is.EqualTo((PointF)unitCircle.Center));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircleF() public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircleF()
{ {
CircleF unitCircle = CircleF.Unit; CircleF unitCircle = CircleF.Unit;
EllipseF converted = unitCircle; EllipseF converted = unitCircle;
Assert.AreEqual(unitCircle, converted); Assert.Multiple(() =>
Assert.AreEqual(unitCircle.Radius, converted.HorizontalRadius); {
Assert.AreEqual(unitCircle.Radius, converted.VerticalRadius); Assert.That(converted, Is.EqualTo((EllipseF)unitCircle));
Assert.AreEqual(unitCircle.Center, converted.Center); Assert.That(converted.HorizontalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.VerticalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.Center, Is.EqualTo(unitCircle.Center));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentEllipse_GivenEllipse() public void op_Implicit_ShouldReturnEquivalentEllipse_GivenEllipse()
{ {
Ellipse unitEllipse = Ellipse.Unit; Ellipse unitEllipse = Ellipse.Unit;
EllipseF converted = unitEllipse; EllipseF converted = unitEllipse;
Assert.AreEqual(unitEllipse, converted); Assert.Multiple(() =>
Assert.AreEqual(unitEllipse.HorizontalRadius, converted.HorizontalRadius); {
Assert.AreEqual(unitEllipse.VerticalRadius, converted.VerticalRadius); Assert.That(converted, Is.EqualTo((EllipseF)unitEllipse));
Assert.AreEqual(unitEllipse.Center, converted.Center); Assert.That(converted.HorizontalRadius, Is.EqualTo(unitEllipse.HorizontalRadius));
Assert.That(converted.VerticalRadius, Is.EqualTo(unitEllipse.VerticalRadius));
Assert.That(converted.Center, Is.EqualTo((PointF)unitEllipse.Center));
});
} }
[TestMethod] [Test]
public void VerticalRadius_ShouldBe0_GivenEmptyEllipse() public void VerticalRadius_ShouldBe0_GivenEmptyEllipse()
{ {
Assert.AreEqual(0, EllipseF.Empty.VerticalRadius); Assert.That(EllipseF.Empty.VerticalRadius, Is.Zero);
} }
[TestMethod] [Test]
public void VerticalRadius_ShouldBe1_GivenUnitEllipse() public void VerticalRadius_ShouldBe1_GivenUnitEllipse()
{ {
Assert.AreEqual(1, EllipseF.Unit.VerticalRadius); Assert.That(EllipseF.Unit.VerticalRadius, Is.EqualTo(1));
} }
} }

View File

@ -1,111 +1,124 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class EllipseTests public class EllipseTests
{ {
[TestMethod] [Test]
public void Area_ShouldBePiRadiusRadius_GivenUnitEllipse() public void Area_ShouldBePiRadiusRadius_GivenUnitEllipse()
{ {
var unitEllipse = Ellipse.Unit; var unitEllipse = Ellipse.Unit;
Assert.AreEqual(MathF.PI, unitEllipse.Area, 1e-6f); Assert.That(unitEllipse.Area, Is.EqualTo(MathF.PI).Within(1e-6f));
} }
[TestMethod] [Test]
public void ApproximateCircumference_ShouldBe2PiRadius_GivenUnitEllipse() public void ApproximateCircumference_ShouldBe2PiRadius_GivenUnitEllipse()
{ {
var unitEllipse = Ellipse.Unit; var unitEllipse = Ellipse.Unit;
Assert.AreEqual(2 * MathF.PI, unitEllipse.ApproximateCircumference, 1e-6f); Assert.That(unitEllipse.ApproximateCircumference, Is.EqualTo(2.0f * MathF.PI).Within(1e-6f));
} }
[TestMethod] [Test]
public void Constructor_ShouldGiveCorrectEllipse() public void Constructor_ShouldGiveCorrectEllipse()
{ {
var ellipse = new Ellipse(Point.Empty, new Size(2, 1)); var ellipse = new Ellipse(Point.Empty, new Size(2, 1));
Assert.AreEqual(new Point(0, 0), ellipse.Center); Assert.Multiple(() =>
Assert.AreEqual(new Size(2, 1), ellipse.Radius); {
Assert.That(ellipse.Center, Is.EqualTo(new Point(0, 0)));
Assert.That(ellipse.Radius, Is.EqualTo(new Size(2, 1)));
});
ellipse = new Ellipse(0, 0, 2, 1); ellipse = new Ellipse(0, 0, 2, 1);
Assert.AreEqual(new Point(0, 0), ellipse.Center); Assert.Multiple(() =>
Assert.AreEqual(new Size(2, 1), ellipse.Radius); {
Assert.That(ellipse.Center, Is.EqualTo(new Point(0, 0)));
Assert.That(ellipse.Radius, Is.EqualTo(new Size(2, 1)));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitEllipses() public void Equals_ShouldBeTrue_GivenTwoUnitEllipses()
{ {
var unitEllipse1 = Ellipse.Unit; var unitEllipse1 = Ellipse.Unit;
var unitEllipse2 = Ellipse.Unit; var unitEllipse2 = Ellipse.Unit;
Assert.AreEqual(unitEllipse1, unitEllipse2); Assert.Multiple(() =>
Assert.IsTrue(unitEllipse1 == unitEllipse2); {
Assert.IsFalse(unitEllipse1 != unitEllipse2); Assert.That(unitEllipse2, Is.EqualTo(unitEllipse1));
Assert.That(unitEllipse1, Is.EqualTo(unitEllipse2));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentEllipses() public void Equals_ShouldBeFalse_GivenDifferentEllipses()
{ {
Assert.AreNotEqual(Ellipse.Unit, Ellipse.Empty); Assert.Multiple(() =>
Assert.IsFalse(Ellipse.Unit == Ellipse.Empty); {
Assert.IsTrue(Ellipse.Unit != Ellipse.Empty); Assert.That(Ellipse.Empty, Is.Not.EqualTo(Ellipse.Unit));
Assert.That(Ellipse.Unit, Is.Not.EqualTo(Ellipse.Empty));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(Ellipse.Unit.Equals(null)); Assert.That(Ellipse.Unit.Equals(null), Is.False);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyEllipse() public void GetHashCode_ShouldBeCorrect_GivenEmptyEllipse()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Ellipse.Empty.GetHashCode(); int hashCode = Ellipse.Empty.GetHashCode();
Assert.AreEqual(hashCode, Ellipse.Empty.GetHashCode()); Assert.That(Ellipse.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitEllipse() public void GetHashCode_ShouldBeCorrect_GivenUnitEllipse()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Ellipse.Unit.GetHashCode(); int hashCode = Ellipse.Unit.GetHashCode();
Assert.AreEqual(hashCode, Ellipse.Unit.GetHashCode()); Assert.That(Ellipse.Unit.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void HorizontalRadius_ShouldBe0_GivenEmptyEllipse() public void HorizontalRadius_ShouldBe0_GivenEmptyEllipse()
{ {
Assert.AreEqual(0, Ellipse.Empty.HorizontalRadius); Assert.That(Ellipse.Empty.HorizontalRadius, Is.Zero);
} }
[TestMethod] [Test]
public void HorizontalRadius_ShouldBe1_GivenUnitEllipse() public void HorizontalRadius_ShouldBe1_GivenUnitEllipse()
{ {
Assert.AreEqual(1, Ellipse.Unit.HorizontalRadius); Assert.That(Ellipse.Unit.HorizontalRadius, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircle() public void op_Implicit_ShouldReturnEquivalentEllipse_GivenCircle()
{ {
Circle unitCircle = Circle.Unit; Circle unitCircle = Circle.Unit;
Ellipse converted = unitCircle; Ellipse converted = unitCircle;
Assert.AreEqual(unitCircle, converted); Assert.Multiple(() =>
Assert.AreEqual(unitCircle.Radius, converted.HorizontalRadius); {
Assert.AreEqual(unitCircle.Radius, converted.VerticalRadius); Assert.That(converted, Is.EqualTo((Ellipse)unitCircle));
Assert.AreEqual(unitCircle.Center, converted.Center); Assert.That(converted.HorizontalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.VerticalRadius, Is.EqualTo(unitCircle.Radius));
Assert.That(converted.Center, Is.EqualTo(unitCircle.Center));
});
} }
[TestMethod] [Test]
public void VerticalRadius_ShouldBe0_GivenEmptyEllipse() public void VerticalRadius_ShouldBe0_GivenEmptyEllipse()
{ {
Assert.AreEqual(0, Ellipse.Empty.VerticalRadius); Assert.That(Ellipse.Empty.VerticalRadius, Is.Zero);
} }
[TestMethod] [Test]
public void VerticalRadius_ShouldBe1_GivenUnitEllipse() public void VerticalRadius_ShouldBe1_GivenUnitEllipse()
{ {
Assert.AreEqual(1, Ellipse.Unit.VerticalRadius); Assert.That(Ellipse.Unit.VerticalRadius, Is.EqualTo(1));
} }
} }

View File

@ -1,116 +1,112 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class Line3DTests public class Line3DTests
{ {
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne() public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne()
{ {
Assert.AreEqual(-1, Line3D.Empty.CompareTo(Line3D.One)); Assert.That(Line3D.Empty.CompareTo(Line3D.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject()
{ {
Assert.AreEqual(-1, Line3D.Empty.CompareTo((object)Line3D.One)); Assert.That(Line3D.Empty.CompareTo((object)Line3D.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, Line3D.One.CompareTo(null)); Assert.That(Line3D.One.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenOneAndEmpty() public void CompareTo_ShouldBeOne_GivenOneAndEmpty()
{ {
Assert.AreEqual(1, Line3D.One.CompareTo(Line3D.Empty)); Assert.That(Line3D.One.CompareTo(Line3D.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitLine() public void CompareTo_ShouldBeZero_GivenUnitLine()
{ {
var unitLine3D = Line3D.One; var unitLine3D = Line3D.One;
Assert.AreEqual(0, unitLine3D.CompareTo(unitLine3D)); Assert.That(unitLine3D.CompareTo(unitLine3D), Is.Zero);
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => Line3D.Empty.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = Line3D.Empty.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Length_ShouldBe0_GivenEmptyLine() public void Length_ShouldBe0_GivenEmptyLine()
{ {
Assert.AreEqual(0.0f, Line3D.Empty.Length); Assert.That(Line3D.Empty.Length, Is.Zero);
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitXLine() public void Length_ShouldBe1_GivenUnitXLine()
{ {
Assert.AreEqual(1.0f, Line3D.UnitX.Length, 1e-6f); Assert.That(Line3D.UnitX.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitYLine() public void Length_ShouldBe1_GivenUnitYLine()
{ {
Assert.AreEqual(1.0f, Line3D.UnitY.Length, 1e-6f); Assert.That(Line3D.UnitY.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitZLine() public void Length_ShouldBe1_GivenUnitZLine()
{ {
Assert.AreEqual(1.0f, Line3D.UnitZ.Length, 1e-6f); Assert.That(Line3D.UnitZ.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitLines() public void Equals_ShouldBeTrue_GivenTwoUnitLines()
{ {
Line3D first = Line3D.One; Line3D first = Line3D.One;
Line3D second = Line3D.One; Line3D second = Line3D.One;
Assert.AreEqual(first, second); Assert.That(second, Is.EqualTo(first));
Assert.IsTrue(first == second);
Assert.IsFalse(first != second);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentLines() public void Equals_ShouldBeFalse_GivenDifferentLines()
{ {
Assert.AreNotEqual(Line3D.One, Line3D.Empty); Assert.That(Line3D.Empty, Is.Not.EqualTo(Line3D.One));
Assert.IsFalse(Line3D.One == Line3D.Empty);
Assert.IsTrue(Line3D.One != Line3D.Empty);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(Line3D.One.Equals(null)); Assert.That(Line3D.One, Is.Not.EqualTo(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyLine() public void GetHashCode_ShouldBeCorrect_GivenEmptyLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Line3D.Empty.GetHashCode(); int hashCode = Line3D.Empty.GetHashCode();
Assert.AreEqual(hashCode, Line3D.Empty.GetHashCode()); Assert.That(Line3D.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitLine() public void GetHashCode_ShouldBeCorrect_GivenUnitLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Line3D.One.GetHashCode(); int hashCode = Line3D.One.GetHashCode();
Assert.AreEqual(hashCode, Line3D.One.GetHashCode()); Assert.That(Line3D.One.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentLine_GivenLine() public void op_Explicit_ShouldReturnEquivalentLine_GivenLine()
{ {
Line3D oneLine = new Line3D(Vector3.Zero, Vector3.UnitX + Vector3.UnitY); Line3D oneLine = new Line3D(Vector3.Zero, Vector3.UnitX + Vector3.UnitY);
@ -119,12 +115,15 @@ public class Line3DTests
var expectedStart = new Point((int)oneLine.Start.X, (int)oneLine.Start.Y); var expectedStart = new Point((int)oneLine.Start.X, (int)oneLine.Start.Y);
var expectedEnd = new Point((int)oneLine.End.X, (int)oneLine.End.Y); var expectedEnd = new Point((int)oneLine.End.X, (int)oneLine.End.Y);
Assert.AreEqual(oneLine.Length, converted.Length); Assert.Multiple(() =>
Assert.AreEqual(expectedStart, converted.Start); {
Assert.AreEqual(expectedEnd, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That(converted.Start, Is.EqualTo(expectedStart));
Assert.That(converted.End, Is.EqualTo(expectedEnd));
});
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentLineF_GivenLine() public void op_Explicit_ShouldReturnEquivalentLineF_GivenLine()
{ {
Line3D oneLine = new Line3D(Vector3.Zero, Vector3.UnitX + Vector3.UnitY); Line3D oneLine = new Line3D(Vector3.Zero, Vector3.UnitX + Vector3.UnitY);
@ -133,21 +132,22 @@ public class Line3DTests
var expectedStart = new PointF(oneLine.Start.X, oneLine.Start.Y); var expectedStart = new PointF(oneLine.Start.X, oneLine.Start.Y);
var expectedEnd = new PointF(oneLine.End.X, oneLine.End.Y); var expectedEnd = new PointF(oneLine.End.X, oneLine.End.Y);
Assert.AreEqual(oneLine.Length, converted.Length); Assert.Multiple(() =>
Assert.AreEqual(expectedStart, converted.Start); {
Assert.AreEqual(expectedEnd, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That(converted.Start, Is.EqualTo(expectedStart));
Assert.That(converted.End, Is.EqualTo(expectedEnd));
});
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(Line3D.One > Line3D.Empty); Assert.That(Line3D.One, Is.GreaterThan(Line3D.Empty));
Assert.IsTrue(Line3D.One >= Line3D.Empty); Assert.That(Line3D.One, Is.GreaterThanOrEqualTo(Line3D.Empty));
Assert.IsFalse(Line3D.One < Line3D.Empty);
Assert.IsFalse(Line3D.One <= Line3D.Empty);
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentLine_GivenLine() public void op_Implicit_ShouldReturnEquivalentLine_GivenLine()
{ {
Line oneLine = Line.One; Line oneLine = Line.One;
@ -156,13 +156,16 @@ public class Line3DTests
var expectedStart = new Vector3(oneLine.Start.X, oneLine.Start.Y, 0.0f); var expectedStart = new Vector3(oneLine.Start.X, oneLine.Start.Y, 0.0f);
var expectedEnd = new Vector3(oneLine.End.X, oneLine.End.Y, 0.0f); var expectedEnd = new Vector3(oneLine.End.X, oneLine.End.Y, 0.0f);
Assert.AreEqual(oneLine, converted); Assert.Multiple(() =>
Assert.AreEqual(oneLine.Length, converted.Length); {
Assert.AreEqual(expectedStart, converted.Start); Assert.That(converted, Is.EqualTo((Line3D)oneLine));
Assert.AreEqual(expectedEnd, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That(converted.Start, Is.EqualTo(expectedStart));
Assert.That(converted.End, Is.EqualTo(expectedEnd));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentLine_GivenLineF() public void op_Implicit_ShouldReturnEquivalentLine_GivenLineF()
{ {
LineF oneLine = LineF.One; LineF oneLine = LineF.One;
@ -171,18 +174,19 @@ public class Line3DTests
var expectedStart = new Vector3(oneLine.Start.X, oneLine.Start.Y, 0.0f); var expectedStart = new Vector3(oneLine.Start.X, oneLine.Start.Y, 0.0f);
var expectedEnd = new Vector3(oneLine.End.X, oneLine.End.Y, 0.0f); var expectedEnd = new Vector3(oneLine.End.X, oneLine.End.Y, 0.0f);
Assert.AreEqual(oneLine, converted); Assert.Multiple(() =>
Assert.AreEqual(oneLine.Length, converted.Length); {
Assert.AreEqual(expectedStart, converted.Start); Assert.That(converted, Is.EqualTo((Line3D)oneLine));
Assert.AreEqual(expectedEnd, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That(converted.Start, Is.EqualTo(expectedStart));
Assert.That(converted.End, Is.EqualTo(expectedEnd));
});
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(Line3D.Empty < Line3D.One); Assert.That(Line3D.Empty, Is.LessThan(Line3D.One));
Assert.IsTrue(Line3D.Empty <= Line3D.One); Assert.That(Line3D.Empty, Is.LessThanOrEqualTo(Line3D.One));
Assert.IsFalse(Line3D.Empty > Line3D.One);
Assert.IsFalse(Line3D.Empty >= Line3D.One);
} }
} }

View File

@ -1,146 +1,152 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Drawing;
using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class LineFTests public class LineFTests
{ {
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne() public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne()
{ {
Assert.AreEqual(-1, LineF.Empty.CompareTo(LineF.One)); Assert.That(LineF.Empty.CompareTo(LineF.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject()
{ {
Assert.AreEqual(-1, LineF.Empty.CompareTo((object)LineF.One)); Assert.That(LineF.Empty.CompareTo((object)LineF.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, LineF.One.CompareTo(null)); Assert.That(LineF.One.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenOneAndEmpty() public void CompareTo_ShouldBeOne_GivenOneAndEmpty()
{ {
Assert.AreEqual(1, LineF.One.CompareTo(LineF.Empty)); Assert.That(LineF.One.CompareTo(LineF.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitLine() public void CompareTo_ShouldBeZero_GivenUnitLine()
{ {
var unitLineF = LineF.One; Assert.That(LineF.One.CompareTo(LineF.One), Is.Zero);
Assert.AreEqual(0, unitLineF.CompareTo(unitLineF));
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => LineF.Empty.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = LineF.Empty.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Length_ShouldBe0_GivenEmptyLine() public void Length_ShouldBe0_GivenEmptyLine()
{ {
Assert.AreEqual(0.0f, LineF.Empty.Length); Assert.That(LineF.Empty.Length, Is.Zero);
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitXLine() public void Length_ShouldBe1_GivenUnitXLine()
{ {
Assert.AreEqual(1.0f, LineF.UnitX.Length, 1e-6f); Assert.That(LineF.UnitX.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitYLine() public void Length_ShouldBe1_GivenUnitYLine()
{ {
Assert.AreEqual(1.0f, LineF.UnitY.Length, 1e-6f); Assert.That(LineF.UnitY.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitLines() public void Equals_ShouldBeTrue_GivenTwoUnitLines()
{ {
LineF first = LineF.One; LineF first = LineF.One;
LineF second = LineF.One; LineF second = LineF.One;
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.IsTrue(first == second); {
Assert.IsFalse(first != second); Assert.That(second, Is.EqualTo(first));
Assert.That(first, Is.EqualTo(second));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentLines() public void Equals_ShouldBeFalse_GivenDifferentLines()
{ {
Assert.AreNotEqual(LineF.One, LineF.Empty); Assert.Multiple(() =>
Assert.IsFalse(LineF.One == LineF.Empty); {
Assert.IsTrue(LineF.One != LineF.Empty); Assert.That(LineF.Empty, Is.Not.EqualTo(LineF.One));
Assert.That(LineF.One, Is.Not.EqualTo(LineF.Empty));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(LineF.One.Equals(null)); Assert.That(LineF.One, Is.Not.EqualTo(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyLine() public void GetHashCode_ShouldBeCorrect_GivenEmptyLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = LineF.Empty.GetHashCode(); int hashCode = LineF.Empty.GetHashCode();
Assert.AreEqual(hashCode, LineF.Empty.GetHashCode()); Assert.That(LineF.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitLine() public void GetHashCode_ShouldBeCorrect_GivenUnitLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = LineF.One.GetHashCode(); int hashCode = LineF.One.GetHashCode();
Assert.AreEqual(hashCode, LineF.One.GetHashCode()); Assert.That(LineF.One.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentLine_GivenLine() public void op_Explicit_ShouldReturnEquivalentLine_GivenLine()
{ {
LineF oneLine = LineF.One; LineF oneLine = LineF.One;
Line converted = (Line)oneLine; Line converted = (Line)oneLine;
Assert.AreEqual(oneLine, converted); Assert.Multiple(() =>
Assert.AreEqual(oneLine.Length, converted.Length); {
Assert.AreEqual(oneLine.Start, converted.Start); Assert.That(converted, Is.EqualTo((Line)oneLine));
Assert.AreEqual(oneLine.End, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That((PointF)converted.Start, Is.EqualTo(oneLine.Start));
Assert.That((PointF)converted.End, Is.EqualTo(oneLine.End));
});
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(LineF.One > LineF.Empty); Assert.That(LineF.One, Is.GreaterThan(LineF.Empty));
Assert.IsTrue(LineF.One >= LineF.Empty); Assert.That(LineF.One, Is.GreaterThanOrEqualTo(LineF.Empty));
Assert.IsFalse(LineF.One < LineF.Empty);
Assert.IsFalse(LineF.One <= LineF.Empty);
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentLine_GivenLine() public void op_Implicit_ShouldReturnEquivalentLine_GivenLine()
{ {
Line oneLine = Line.One; Line oneLine = Line.One;
LineF converted = oneLine; LineF converted = oneLine;
Assert.AreEqual(oneLine, converted); Assert.Multiple(() =>
Assert.AreEqual(oneLine.Length, converted.Length); {
Assert.AreEqual(oneLine.Start, converted.Start); Assert.That(converted, Is.EqualTo((LineF)oneLine));
Assert.AreEqual(oneLine.End, converted.End); Assert.That(converted.Length, Is.EqualTo(oneLine.Length));
Assert.That(converted.Start, Is.EqualTo((PointF)oneLine.Start));
Assert.That(converted.End, Is.EqualTo((PointF)oneLine.End));
});
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(LineF.Empty < LineF.One); Assert.That(LineF.Empty, Is.LessThan(LineF.One));
Assert.IsTrue(LineF.Empty <= LineF.One); Assert.That(LineF.Empty, Is.LessThanOrEqualTo(LineF.One));
Assert.IsFalse(LineF.Empty > LineF.One);
Assert.IsFalse(LineF.Empty >= LineF.One);
} }
} }

View File

@ -1,122 +1,122 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class LineTests public class LineTests
{ {
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne() public void CompareTo_ShouldBeNegativeOne_GivenEmptyAndOne()
{ {
Assert.AreEqual(-1, Line.Empty.CompareTo(Line.One)); Assert.That(Line.Empty.CompareTo(Line.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyLineAndOneLineAsObject()
{ {
Assert.AreEqual(-1, Line.Empty.CompareTo((object)Line.One)); Assert.That(Line.Empty.CompareTo((object)Line.One), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, Line.One.CompareTo(null)); Assert.That(Line.One.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenOneAndEmpty() public void CompareTo_ShouldBeOne_GivenOneAndEmpty()
{ {
Assert.AreEqual(1, Line.One.CompareTo(Line.Empty)); Assert.That(Line.One.CompareTo(Line.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitLine() public void CompareTo_ShouldBeZero_GivenUnitLine()
{ {
var unitLine = Line.One; var unitLine = Line.One;
Assert.AreEqual(0, unitLine.CompareTo(unitLine)); Assert.That(unitLine.CompareTo(unitLine), Is.Zero);
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => Line.Empty.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = Line.Empty.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitLines() public void Equals_ShouldBeTrue_GivenTwoUnitLines()
{ {
Line first = Line.One; Line first = Line.One;
Line second = Line.One; Line second = Line.One;
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.IsTrue(first == second); {
Assert.IsFalse(first != second); Assert.That(second, Is.EqualTo(first));
Assert.That(first, Is.EqualTo(second));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentLines() public void Equals_ShouldBeFalse_GivenDifferentLines()
{ {
Assert.AreNotEqual(Line.One, Line.Empty); Assert.Multiple(() =>
Assert.IsFalse(Line.One == Line.Empty); {
Assert.IsTrue(Line.One != Line.Empty); Assert.That(Line.Empty, Is.Not.EqualTo(Line.One));
Assert.That(Line.One, Is.Not.EqualTo(Line.Empty));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(Line.One.Equals(null)); Assert.That(Line.One, Is.Not.EqualTo(null));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyLine() public void GetHashCode_ShouldBeCorrect_GivenEmptyLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Line.Empty.GetHashCode(); int hashCode = Line.Empty.GetHashCode();
Assert.AreEqual(hashCode, Line.Empty.GetHashCode()); Assert.That(Line.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitLine() public void GetHashCode_ShouldBeCorrect_GivenUnitLine()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Line.One.GetHashCode(); int hashCode = Line.One.GetHashCode();
Assert.AreEqual(hashCode, Line.One.GetHashCode()); Assert.That(Line.One.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void Length_ShouldBe0_GivenEmptyLine() public void Length_ShouldBe0_GivenEmptyLine()
{ {
Assert.AreEqual(0.0f, Line.Empty.Length); Assert.That(Line.Empty.Length, Is.Zero);
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitXLine() public void Length_ShouldBe1_GivenUnitXLine()
{ {
Assert.AreEqual(1.0f, Line.UnitX.Length, 1e-6f); Assert.That(Line.UnitX.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Length_ShouldBe1_GivenUnitYLine() public void Length_ShouldBe1_GivenUnitYLine()
{ {
Assert.AreEqual(1.0f, Line.UnitY.Length, 1e-6f); Assert.That(Line.UnitY.Length, Is.EqualTo(1.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(Line.One > Line.Empty); Assert.That(Line.One, Is.GreaterThan(Line.Empty));
Assert.IsTrue(Line.One >= Line.Empty); Assert.That(Line.One, Is.GreaterThanOrEqualTo(Line.Empty));
Assert.IsFalse(Line.One < Line.Empty);
Assert.IsFalse(Line.One <= Line.Empty);
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(Line.Empty < Line.One); Assert.That(Line.Empty, Is.LessThan(Line.One));
Assert.IsTrue(Line.Empty <= Line.One); Assert.That(Line.Empty, Is.LessThanOrEqualTo(Line.One));
Assert.IsFalse(Line.Empty > Line.One);
Assert.IsFalse(Line.Empty >= Line.One);
} }
} }

View File

@ -1,5 +1,5 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
#if !NET6_0_OR_GREATER #if !NET6_0_OR_GREATER
using X10D.Core; using X10D.Core;
#endif #endif
@ -7,59 +7,74 @@ using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class PointFTests public class PointFTests
{ {
[TestMethod] [Test]
public void IsOnLine_ShouldReturnTrue_GivenPointOnLine() public void IsOnLine_ShouldReturnTrue_GivenPointOnLine()
{ {
var point = new PointF(1.0f, 0.0f); var point = new PointF(1.0f, 0.0f);
var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f)); var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f));
Assert.IsTrue(point.IsOnLine(line)); Assert.Multiple(() =>
Assert.IsTrue(point.IsOnLine(line.Start, line.End)); {
Assert.IsTrue(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); Assert.That(point.IsOnLine(line));
Assert.That(point.IsOnLine(line.Start, line.End));
Assert.That(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2()));
});
} }
[TestMethod] [Test]
public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine() public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine()
{ {
var point = new PointF(1.0f, 1.0f); var point = new PointF(1.0f, 1.0f);
var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f)); var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f));
Assert.IsFalse(point.IsOnLine(line)); Assert.Multiple(() =>
Assert.IsFalse(point.IsOnLine(line.Start, line.End)); {
Assert.IsFalse(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); Assert.That(point.IsOnLine(line), Is.False);
Assert.That(point.IsOnLine(line.Start, line.End), Is.False);
Assert.That(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2()), Is.False);
});
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearestInteger_GivenNoParameters() public void Round_ShouldRoundToNearestInteger_GivenNoParameters()
{ {
var point = new PointF(1.5f, 2.6f); var point = new PointF(1.5f, 2.6f);
var rounded = point.Round(); var rounded = point.Round();
Assert.AreEqual(2, rounded.X); Assert.Multiple(() =>
Assert.AreEqual(3, rounded.Y); {
Assert.That(rounded.X, Is.EqualTo(2));
Assert.That(rounded.Y, Is.EqualTo(3));
});
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearest10_GivenPrecision10() public void Round_ShouldRoundToNearest10_GivenPrecision10()
{ {
var point = new PointF(1.5f, 25.2f); var point = new PointF(1.5f, 25.2f);
var rounded = point.Round(10); var rounded = point.Round(10);
Assert.AreEqual(0, rounded.X); Assert.Multiple(() =>
Assert.AreEqual(30, rounded.Y); {
Assert.That(rounded.X, Is.Zero);
Assert.That(rounded.Y, Is.EqualTo(30));
});
} }
[TestMethod] [Test]
public void ToSizeF_ShouldReturnSize_WithEquivalentMembers() public void ToSizeF_ShouldReturnSize_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var point = new PointF(random.NextSingle(), random.NextSingle()); var point = new PointF(random.NextSingle(), random.NextSingle());
var size = point.ToSizeF(); var size = point.ToSizeF();
Assert.AreEqual(point.X, size.Width, 1e-6f); Assert.Multiple(() =>
Assert.AreEqual(point.Y, size.Height, 1e-6f); {
Assert.That(size.Width, Is.EqualTo(point.X).Within(1e-6f));
Assert.That(size.Height, Is.EqualTo(point.Y).Within(1e-6f));
});
} }
} }

View File

@ -1,64 +1,79 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class PointTests public class PointTests
{ {
[TestMethod] [Test]
public void IsOnLine_ShouldReturnTrue_GivenPointOnLine() public void IsOnLine_ShouldReturnTrue_GivenPointOnLine()
{ {
var point = new Point(1, 0); var point = new Point(1, 0);
var line = new Line(Point.Empty, new Point(2, 0)); var line = new Line(Point.Empty, new Point(2, 0));
Assert.IsTrue(point.IsOnLine(line)); Assert.Multiple(() =>
Assert.IsTrue(point.IsOnLine(line.Start, line.End)); {
Assert.IsTrue(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); Assert.That(point.IsOnLine(line));
Assert.That(point.IsOnLine(line.Start, line.End));
Assert.That(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2()));
});
} }
[TestMethod] [Test]
public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine() public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine()
{ {
var point = new Point(1, 1); var point = new Point(1, 1);
var line = new Line(Point.Empty, new Point(2, 0)); var line = new Line(Point.Empty, new Point(2, 0));
Assert.IsFalse(point.IsOnLine(line)); Assert.Multiple(() =>
Assert.IsFalse(point.IsOnLine(line.Start, line.End)); {
Assert.IsFalse(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); Assert.That(point.IsOnLine(line), Is.False);
Assert.That(point.IsOnLine(line.Start, line.End), Is.False);
Assert.That(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2()), Is.False);
});
} }
[TestMethod] [Test]
public void ToSize_ShouldReturnSize_WithEquivalentMembers() public void ToSize_ShouldReturnSize_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var point = new Point(random.Next(), random.Next()); var point = new Point(random.Next(), random.Next());
var size = point.ToSize(); var size = point.ToSize();
Assert.AreEqual(point.X, size.Width); Assert.Multiple(() =>
Assert.AreEqual(point.Y, size.Height); {
Assert.That(size.Width, Is.EqualTo(point.X));
Assert.That(size.Height, Is.EqualTo(point.Y));
});
} }
[TestMethod] [Test]
public void ToSizeF_ShouldReturnSize_WithEquivalentMembers() public void ToSizeF_ShouldReturnSize_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var point = new Point(random.Next(), random.Next()); var point = new Point(random.Next(), random.Next());
var size = point.ToSizeF(); var size = point.ToSizeF();
Assert.AreEqual(point.X, size.Width, 1e-6f); Assert.Multiple(() =>
Assert.AreEqual(point.Y, size.Height, 1e-6f); {
Assert.That(size.Width, Is.EqualTo(point.X).Within(1e-6f));
Assert.That(size.Height, Is.EqualTo(point.Y).Within(1e-6f));
});
} }
[TestMethod] [Test]
public void ToVector2_ShouldReturnVector_WithEquivalentMembers() public void ToVector2_ShouldReturnVector_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var point = new Point(random.Next(), random.Next()); var point = new Point(random.Next(), random.Next());
var size = point.ToVector2(); var size = point.ToVector2();
Assert.AreEqual(point.X, size.X, 1e-6f); Assert.Multiple(() =>
Assert.AreEqual(point.Y, size.Y, 1e-6f); {
Assert.That(size.X, Is.EqualTo(point.X).Within(1e-6f));
Assert.That(size.Y, Is.EqualTo(point.Y).Within(1e-6f));
});
} }
} }

View File

@ -1,228 +1,223 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class PolygonFTests public class PolygonFTests
{ {
[TestMethod] [Test]
public void AddVertices_ShouldAddVertices() public void AddVertices_ShouldAddVertices()
{ {
var polygon = PolygonF.Empty; var polygon = PolygonF.Empty;
polygon.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)}); polygon.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)});
Assert.AreEqual(2, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(2));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, PolygonF.Empty.VertexCount); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF() public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF()
{ {
var polygon = PolygonF.Empty; var polygon = PolygonF.Empty;
IEnumerable<PointF> vertices = null!; IEnumerable<PointF> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices)); Assert.Throws<ArgumentNullException>(() => polygon.AddVertices(vertices));
} }
[TestMethod] [Test]
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2() public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2()
{ {
var polygon = PolygonF.Empty; var polygon = PolygonF.Empty;
IEnumerable<Vector2> vertices = null!; IEnumerable<Vector2> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices)); Assert.Throws<ArgumentNullException>(() => polygon.AddVertices(vertices));
} }
[TestMethod] [Test]
public void ClearVertices_ShouldClearVertices() public void ClearVertices_ShouldClearVertices()
{ {
var polygon = PolygonF.Empty; var polygon = PolygonF.Empty;
polygon.AddVertices(new[] {new Vector2(1, 2), new Vector2(3, 4)}); polygon.AddVertices(new[] {new Vector2(1, 2), new Vector2(3, 4)});
Assert.AreEqual(2, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(2));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, PolygonF.Empty.VertexCount); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
polygon.ClearVertices(); polygon.ClearVertices();
Assert.AreEqual(0, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void Constructor_ShouldPopulateVertices_GivenPolygon() public void Constructor_ShouldPopulateVertices_GivenPolygon()
{ {
var pointPolygon = new PolygonF(new[] {new PointF(1, 2), new PointF(3, 4)}); var pointPolygon = new PolygonF(new[] {new PointF(1, 2), new PointF(3, 4)});
var vectorPolygon = new PolygonF(new[] {new Vector2(1, 2), new Vector2(3, 4)}); var vectorPolygon = new PolygonF(new[] {new Vector2(1, 2), new Vector2(3, 4)});
Assert.AreEqual(2, pointPolygon.VertexCount); Assert.That(pointPolygon.VertexCount, Is.EqualTo(2));
Assert.AreEqual(2, vectorPolygon.VertexCount); Assert.That(vectorPolygon.VertexCount, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF() public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF()
{ {
IEnumerable<PointF> vertices = null!; IEnumerable<PointF> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(vertices)); Assert.Throws<ArgumentNullException>(() => _ = new PolygonF(vertices));
} }
[TestMethod] [Test]
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2() public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2()
{ {
IEnumerable<Vector2> vertices = null!; IEnumerable<Vector2> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(vertices)); Assert.Throws<ArgumentNullException>(() => _ = new PolygonF(vertices));
} }
[TestMethod] [Test]
public void CopyConstructor_ShouldCopyVertices_GivenPolygon() public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
{ {
var first = PolygonF.Empty; var first = PolygonF.Empty;
first.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)}); first.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)});
var second = new PolygonF(first); var second = new PolygonF(first);
Assert.AreEqual(2, first.VertexCount); Assert.That(first.VertexCount, Is.EqualTo(2));
Assert.AreEqual(2, second.VertexCount); Assert.That(second.VertexCount, Is.EqualTo(2));
// we cannot use CollectionAssert here for reasons I am not entirely sure of. // we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay. // it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
Assert.IsTrue(first.Vertices.SequenceEqual(second.Vertices)); CollectionAssert.AreEqual(first.Vertices, second.Vertices);
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, PolygonF.Empty.VertexCount); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygonF() public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygonF()
{ {
PolygonF polygon = null!; PolygonF polygon = null!;
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(polygon)); Assert.Throws<ArgumentNullException>(() => _ = new PolygonF(polygon));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons() public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
{ {
var first = PolygonF.Empty; var first = PolygonF.Empty;
var second = PolygonF.Empty; var second = PolygonF.Empty;
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.AreEqual(second, first); {
Assert.IsTrue(first.Equals(second)); Assert.That(second, Is.EqualTo(first));
Assert.IsTrue(second.Equals(first)); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first == second); });
Assert.IsTrue(second == first);
Assert.IsFalse(first != second);
Assert.IsFalse(second != first);
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoHexagons() public void Equals_ShouldBeTrue_GivenTwoHexagons()
{ {
PolygonF first = CreateHexagon(); PolygonF first = CreateHexagon();
PolygonF second = CreateHexagon(); PolygonF second = CreateHexagon();
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.AreEqual(second, first); {
Assert.IsTrue(first.Equals(second)); Assert.That(second, Is.EqualTo(first));
Assert.IsTrue(second.Equals(first)); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first == second); });
Assert.IsTrue(second == first);
Assert.IsFalse(first != second);
Assert.IsFalse(second != first);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolygon() public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolygon()
{ {
PolygonF first = CreateHexagon(); PolygonF first = CreateHexagon();
PolygonF second = PolygonF.Empty; PolygonF second = PolygonF.Empty;
Assert.AreNotEqual(first, second); Assert.Multiple(() =>
Assert.AreNotEqual(second, first); {
Assert.IsFalse(first.Equals(second)); Assert.That(second, Is.Not.EqualTo(first));
Assert.IsFalse(second.Equals(first)); Assert.That(first, Is.Not.EqualTo(second));
Assert.IsFalse(first == second); });
Assert.IsFalse(second == first);
Assert.IsTrue(first != second);
Assert.IsTrue(second != first);
} }
[TestMethod] [Test]
public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF() public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF()
{ {
Assert.ThrowsException<ArgumentNullException>(() => PolygonF.FromPolygon(null!)); Assert.Throws<ArgumentNullException>(() => PolygonF.FromPolygon(null!));
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon() public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
{ {
Assert.IsFalse(PolygonF.Empty.IsConvex); Assert.That(PolygonF.Empty.IsConvex, Is.False);
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeTrue_GivenHexagon() public void IsConvex_ShouldBeTrue_GivenHexagon()
{ {
Assert.IsTrue(CreateHexagon().IsConvex); Assert.That(CreateHexagon().IsConvex, Is.True);
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeFalse_GivenConcavePolygon() public void IsConvex_ShouldBeFalse_GivenConcavePolygon()
{ {
Assert.IsFalse(CreateConcavePolygon().IsConvex); Assert.That(CreateConcavePolygon().IsConvex, Is.False);
} }
[TestMethod] [Test]
public void op_Explicit_ShouldReturnEquivalentCircle_GivenCircle() public void op_Explicit_ShouldReturnEquivalentCircle_GivenCircle()
{ {
PolygonF polygon = CreateHexagon(); PolygonF polygon = CreateHexagon();
Polygon converted = (Polygon)polygon; Polygon converted = (Polygon)polygon;
Assert.AreEqual(polygon, converted); Assert.Multiple(() =>
Assert.AreEqual(polygon.IsConvex, converted.IsConvex); {
Assert.AreEqual(polygon.VertexCount, converted.VertexCount); Assert.That(converted, Is.EqualTo((Polygon)polygon));
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.IsTrue(polygon.Vertices.SequenceEqual(converted.Vertices.Select(p => (PointF)p))); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(polygon.Vertices, converted.Vertices.Select(p => (PointF)p));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentCircle_GivenCircle() public void op_Implicit_ShouldReturnEquivalentCircle_GivenCircle()
{ {
Polygon polygon = PolygonTests.CreateHexagon(); Polygon polygon = PolygonTests.CreateHexagon();
PolygonF converted = polygon; PolygonF converted = polygon;
Assert.AreEqual(polygon, converted); Assert.Multiple(() =>
Assert.AreEqual(polygon.IsConvex, converted.IsConvex); {
Assert.AreEqual(polygon.VertexCount, converted.VertexCount); Assert.That(converted, Is.EqualTo((PolygonF)polygon));
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.IsTrue(converted.Vertices.SequenceEqual(polygon.Vertices.Select(p => (PointF)p))); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => (PointF)p));
});
} }
[TestMethod] [Test]
public void PointCount_ShouldBe1_GivenPolygonFWith1Point() public void PointCount_ShouldBe1_GivenPolygonFWith1Point()
{ {
var polygon = new PolygonF(); var polygon = new PolygonF();
polygon.AddVertex(new Point(1, 1)); polygon.AddVertex(new Point(1, 1));
Assert.AreEqual(1, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(1));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, PolygonF.Empty.VertexCount); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void PointCount_ShouldBe0_GivenEmptyPolygon() public void PointCount_ShouldBe0_GivenEmptyPolygon()
{ {
Assert.AreEqual(0, PolygonF.Empty.VertexCount); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = PolygonF.Empty.GetHashCode(); int hashCode = PolygonF.Empty.GetHashCode();
Assert.AreEqual(hashCode, PolygonF.Empty.GetHashCode()); Assert.That(PolygonF.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
internal static PolygonF CreateHexagon() private static PolygonF CreateHexagon()
{ {
var hexagon = new PolygonF(); var hexagon = new PolygonF();
hexagon.AddVertex(new Vector2(0, 0)); hexagon.AddVertex(new Vector2(0, 0));
@ -234,7 +229,7 @@ public class PolygonFTests
return hexagon; return hexagon;
} }
internal static PolygonF CreateConcavePolygon() private static PolygonF CreateConcavePolygon()
{ {
var hexagon = new PolygonF(); var hexagon = new PolygonF();
hexagon.AddVertex(new Vector2(0, 0)); hexagon.AddVertex(new Vector2(0, 0));

View File

@ -1,120 +1,118 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class PolygonTests public class PolygonTests
{ {
[TestMethod] [Test]
public void AddVertices_ShouldAddVertices() public void AddVertices_ShouldAddVertices()
{ {
var polygon = Polygon.Empty; var polygon = Polygon.Empty;
polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)}); polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
Assert.AreEqual(2, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(2));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, Polygon.Empty.VertexCount); Assert.That(Polygon.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerable() public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerable()
{ {
var polygon = Polygon.Empty; var polygon = Polygon.Empty;
IEnumerable<Point> vertices = null!; IEnumerable<Point> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices)); Assert.Throws<ArgumentNullException>(() => polygon.AddVertices(vertices));
} }
[TestMethod] [Test]
public void ClearVertices_ShouldClearVertices() public void ClearVertices_ShouldClearVertices()
{ {
var polygon = Polygon.Empty; var polygon = Polygon.Empty;
polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)}); polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
Assert.AreEqual(2, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(2));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, Polygon.Empty.VertexCount); Assert.That(Polygon.Empty.VertexCount, Is.Zero);
polygon.ClearVertices(); polygon.ClearVertices();
Assert.AreEqual(0, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void Constructor_ShouldPopulateVertices_GivenPolygon() public void Constructor_ShouldPopulateVertices_GivenPolygon()
{ {
var pointPolygon = new Polygon(new[] {new Point(1, 2), new Point(3, 4)}); var pointPolygon = new Polygon(new[] {new Point(1, 2), new Point(3, 4)});
Assert.AreEqual(2, pointPolygon.VertexCount); Assert.That(pointPolygon.VertexCount, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPoint() public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPoint()
{ {
IEnumerable<Point> vertices = null!; IEnumerable<Point> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => new Polygon(vertices)); Assert.Throws<ArgumentNullException>(() => new Polygon(vertices));
} }
[TestMethod] [Test]
public void CopyConstructor_ShouldCopyVertices_GivenPolygon() public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
{ {
var first = Polygon.Empty; var first = Polygon.Empty;
first.AddVertices(new[] {new Point(1, 2), new Point(3, 4)}); first.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
var second = new Polygon(first); var second = new Polygon(first);
Assert.AreEqual(2, first.VertexCount); Assert.That(first.VertexCount, Is.EqualTo(2));
Assert.AreEqual(2, second.VertexCount); Assert.That(second.VertexCount, Is.EqualTo(2));
// we cannot use CollectionAssert here for reasons I am not entirely sure of. // we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay. // it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
Assert.IsTrue(first.Vertices.SequenceEqual(second.Vertices)); Assert.That(first.Vertices.SequenceEqual(second.Vertices));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, Polygon.Empty.VertexCount); Assert.That(Polygon.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygon() public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygon()
{ {
Polygon polygon = null!; Polygon polygon = null!;
Assert.ThrowsException<ArgumentNullException>(() => new Polygon(polygon)); Assert.Throws<ArgumentNullException>(() => new Polygon(polygon));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons() public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
{ {
var first = Polygon.Empty; var first = Polygon.Empty;
var second = Polygon.Empty; var second = Polygon.Empty;
Assert.AreEqual(first, second); Assert.That(second, Is.EqualTo(first));
Assert.AreEqual(second, first); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first.Equals(second)); Assert.That(first.Equals(second));
Assert.IsTrue(second.Equals(first)); Assert.That(second.Equals(first));
Assert.IsTrue(first == second); Assert.That(first == second);
Assert.IsTrue(second == first); Assert.That(second == first);
Assert.IsFalse(first != second); Assert.That(first != second, Is.False);
Assert.IsFalse(second != first); Assert.That(second != first, Is.False);
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoHexagons() public void Equals_ShouldBeTrue_GivenTwoHexagons()
{ {
Polygon first = CreateHexagon(); Polygon first = CreateHexagon();
Polygon second = CreateHexagon(); Polygon second = CreateHexagon();
Assert.AreEqual(first, second); Assert.That(second, Is.EqualTo(first));
Assert.AreEqual(second, first); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first.Equals(second)); Assert.That(first.Equals(second));
Assert.IsTrue(second.Equals(first)); Assert.That(second.Equals(first));
Assert.IsTrue(first == second); Assert.That(first == second);
Assert.IsTrue(second == first); Assert.That(second == first);
Assert.IsFalse(first != second); Assert.That(first != second, Is.False);
Assert.IsFalse(second != first); Assert.That(second != first, Is.False);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolygon() public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolygon()
{ {
Polygon first = CreateHexagon(); Polygon first = CreateHexagon();
@ -122,15 +120,15 @@ public class PolygonTests
Assert.AreNotEqual(first, second); Assert.AreNotEqual(first, second);
Assert.AreNotEqual(second, first); Assert.AreNotEqual(second, first);
Assert.IsFalse(first.Equals(second)); Assert.That(first.Equals(second), Is.False);
Assert.IsFalse(second.Equals(first)); Assert.That(second.Equals(first), Is.False);
Assert.IsFalse(first == second); Assert.That(first == second, Is.False);
Assert.IsFalse(second == first); Assert.That(second == first, Is.False);
Assert.IsTrue(first != second); Assert.That(first != second);
Assert.IsTrue(second != first); Assert.That(second != first);
} }
[TestMethod] [Test]
public void FromPolygonF_ShouldReturnEquivalentPolygon_GivenPolygon() public void FromPolygonF_ShouldReturnEquivalentPolygon_GivenPolygon()
{ {
PolygonF hexagon = CreateHexagonF(); PolygonF hexagon = CreateHexagonF();
@ -138,57 +136,57 @@ public class PolygonTests
Polygon expected = CreateHexagon(); Polygon expected = CreateHexagon();
Polygon actual = Polygon.FromPolygonF(hexagon); Polygon actual = Polygon.FromPolygonF(hexagon);
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygon() public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygon()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Polygon.FromPolygonF(null!)); Assert.Throws<ArgumentNullException>(() => Polygon.FromPolygonF(null!));
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon() public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
{ {
Assert.IsFalse(Polygon.Empty.IsConvex); Assert.That(Polygon.Empty.IsConvex, Is.False);
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeTrue_GivenHexagon() public void IsConvex_ShouldBeTrue_GivenHexagon()
{ {
Assert.IsTrue(CreateHexagon().IsConvex); Assert.That(CreateHexagon().IsConvex);
} }
[TestMethod] [Test]
public void IsConvex_ShouldBeFalse_GivenConcavePolygon() public void IsConvex_ShouldBeFalse_GivenConcavePolygon()
{ {
Assert.IsFalse(CreateConcavePolygon().IsConvex); Assert.That(CreateConcavePolygon().IsConvex, Is.False);
} }
[TestMethod] [Test]
public void PointCount_ShouldBe1_GivenPolygonWith1Point() public void PointCount_ShouldBe1_GivenPolygonWith1Point()
{ {
var polygon = Polygon.Empty; var polygon = Polygon.Empty;
polygon.AddVertex(new Point(1, 1)); polygon.AddVertex(new Point(1, 1));
Assert.AreEqual(1, polygon.VertexCount); Assert.That(polygon.VertexCount, Is.EqualTo(1));
// assert that the empty polygon was not modified // assert that the empty polygon was not modified
Assert.AreEqual(0, Polygon.Empty.VertexCount); Assert.That(Polygon.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void PointCount_ShouldBe0_GivenEmptyPolygon() public void PointCount_ShouldBe0_GivenEmptyPolygon()
{ {
Assert.AreEqual(0, Polygon.Empty.VertexCount); Assert.That(Polygon.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Polygon.Empty.GetHashCode(); int hashCode = Polygon.Empty.GetHashCode();
Assert.AreEqual(hashCode, Polygon.Empty.GetHashCode()); Assert.That(Polygon.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
internal static Polygon CreateHexagon() internal static Polygon CreateHexagon()

View File

@ -1,196 +1,217 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class PolyhedronTests public class PolyhedronTests
{ {
[TestMethod] [Test]
public void AddVertices_ShouldAddVertices() public void AddVertices_ShouldAddVertices()
{ {
var polyhedron = Polyhedron.Empty; var polyhedron = Polyhedron.Empty;
polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)}); polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
Assert.AreEqual(2, polyhedron.VertexCount);
Assert.Multiple(() =>
{
Assert.That(polyhedron.VertexCount, Is.EqualTo(2));
// assert that the empty polyhedron was not modified // assert that the empty polyhedron was not modified
Assert.AreEqual(0, Polyhedron.Empty.VertexCount); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
});
} }
[TestMethod] [Test]
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3() public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3()
{ {
var polygon = Polyhedron.Empty; var polygon = Polyhedron.Empty;
IEnumerable<Vector3> vertices = null!; IEnumerable<Vector3> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices)); Assert.Throws<ArgumentNullException>(() => polygon.AddVertices(vertices));
} }
[TestMethod] [Test]
public void ClearVertices_ShouldClearVertices() public void ClearVertices_ShouldClearVertices()
{ {
var polyhedron = Polyhedron.Empty; var polyhedron = Polyhedron.Empty;
polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)}); polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
Assert.AreEqual(2, polyhedron.VertexCount); Assert.Multiple(() =>
{
Assert.That(polyhedron.VertexCount, Is.EqualTo(2));
// assert that the empty polyhedron was not modified // assert that the empty polyhedron was not modified
Assert.AreEqual(0, Polyhedron.Empty.VertexCount); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
});
polyhedron.ClearVertices(); polyhedron.ClearVertices();
Assert.AreEqual(0, polyhedron.VertexCount); Assert.That(polyhedron.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void Constructor_ShouldPopulateVertices_GivenPolyhedron() public void Constructor_ShouldPopulateVertices_GivenPolyhedron()
{ {
var polyhedron = new Polyhedron(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)}); var polyhedron = new Polyhedron(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
Assert.AreEqual(2, polyhedron.VertexCount); Assert.That(polyhedron.VertexCount, Is.EqualTo(2));
} }
[TestMethod] [Test]
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3() public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3()
{ {
IEnumerable<Vector3> vertices = null!; IEnumerable<Vector3> vertices = null!;
Assert.ThrowsException<ArgumentNullException>(() => new Polyhedron(vertices)); Assert.Throws<ArgumentNullException>(() => _ = new Polyhedron(vertices));
} }
[TestMethod] [Test]
public void CopyConstructor_ShouldCopyVertices_GivenPolyhedron() public void CopyConstructor_ShouldCopyVertices_GivenPolyhedron()
{ {
var first = Polyhedron.Empty; var first = Polyhedron.Empty;
first.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)}); first.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
var second = new Polyhedron(first); var second = new Polyhedron(first);
Assert.AreEqual(2, first.VertexCount); Assert.Multiple(() =>
Assert.AreEqual(2, second.VertexCount); {
Assert.That(first.VertexCount, Is.EqualTo(2));
Assert.That(second.VertexCount, Is.EqualTo(2));
// we cannot use CollectionAssert here for reasons I am not entirely sure of. // we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay. // it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
Assert.IsTrue(first.Vertices.SequenceEqual(second.Vertices)); CollectionAssert.AreEqual(first.Vertices, second.Vertices);
// assert that the empty polyhedron was not modified // assert that the empty polyhedron was not modified
Assert.AreEqual(0, Polyhedron.Empty.VertexCount); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoEmptyPolyhedrons() public void Equals_ShouldBeTrue_GivenTwoEmptyPolyhedrons()
{ {
var first = Polyhedron.Empty; var first = Polyhedron.Empty;
var second = Polyhedron.Empty; var second = Polyhedron.Empty;
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.AreEqual(second, first); {
Assert.IsTrue(first.Equals(second)); Assert.That(second, Is.EqualTo(first));
Assert.IsTrue(second.Equals(first)); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first == second); });
Assert.IsTrue(second == first);
Assert.IsFalse(first != second);
Assert.IsFalse(second != first);
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoHexagons() public void Equals_ShouldBeTrue_GivenTwoHexagons()
{ {
Polyhedron first = CreateHexagon(); Polyhedron first = CreateHexagonPolyhedron();
Polyhedron second = CreateHexagon(); Polyhedron second = CreateHexagonPolyhedron();
Assert.AreEqual(first, second); Assert.Multiple(() =>
Assert.AreEqual(second, first); {
Assert.IsTrue(first.Equals(second)); Assert.That(second, Is.EqualTo(first));
Assert.IsTrue(second.Equals(first)); Assert.That(first, Is.EqualTo(second));
Assert.IsTrue(first == second); });
Assert.IsTrue(second == first);
Assert.IsFalse(first != second);
Assert.IsFalse(second != first);
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolyhedron() public void Equals_ShouldBeFalse_GivenHexagonAndEmptyPolyhedron()
{ {
Polyhedron first = CreateHexagon(); Polyhedron first = CreateHexagonPolyhedron();
Polyhedron second = Polyhedron.Empty; Polyhedron second = Polyhedron.Empty;
Assert.AreNotEqual(first, second); Assert.Multiple(() =>
Assert.AreNotEqual(second, first); {
Assert.IsFalse(first.Equals(second)); Assert.That(second, Is.Not.EqualTo(first));
Assert.IsFalse(second.Equals(first)); Assert.That(first, Is.Not.EqualTo(second));
Assert.IsFalse(first == second); });
Assert.IsFalse(second == first);
Assert.IsTrue(first != second);
Assert.IsTrue(second != first);
} }
[TestMethod] [Test]
public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF() public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Polyhedron.FromPolygon(null!)); Assert.Throws<ArgumentNullException>(() => Polyhedron.FromPolygon(null!));
} }
[TestMethod] [Test]
public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygonF() public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygonF()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Polyhedron.FromPolygonF(null!)); Assert.Throws<ArgumentNullException>(() => Polyhedron.FromPolygonF(null!));
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedron() public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedron()
{ {
Polygon polygon = PolygonTests.CreateHexagon(); Polygon polygon = PolygonTests.CreateHexagon();
Polyhedron converted = polygon; Polyhedron converted = polygon;
Assert.AreEqual(polygon, converted); Assert.Multiple(() =>
Assert.AreEqual(polygon.VertexCount, converted.VertexCount); {
Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
Assert.IsTrue(converted.Vertices.SequenceEqual(polygon.Vertices.Select(p => CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
{ {
var point = p.ToVector2(); var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0); return new Vector3(point.X, point.Y, 0);
}))); }));
});
} }
[TestMethod] [Test]
public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedronF() public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedronF()
{ {
PolygonF polygon = PolygonFTests.CreateHexagon(); PolygonF polygon = CreateHexagonPolygon();
Polyhedron converted = polygon; Polyhedron converted = polygon;
Assert.AreEqual(polygon, converted); Assert.Multiple(() =>
Assert.AreEqual(polygon.VertexCount, converted.VertexCount);
Assert.IsTrue(converted.Vertices.SequenceEqual(polygon.Vertices.Select(v =>
{ {
var point = v.ToVector2(); Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
{
var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0); return new Vector3(point.X, point.Y, 0);
}))); }));
});
} }
[TestMethod] [Test]
public void PointCount_ShouldBe1_GivenPolyhedronWith1Point() public void PointCount_ShouldBe1_GivenPolyhedronWith1Point()
{ {
var polyhedron = new Polyhedron(); var polyhedron = new Polyhedron();
polyhedron.AddVertex(Vector3.One); polyhedron.AddVertex(Vector3.One);
Assert.AreEqual(1, polyhedron.VertexCount); Assert.Multiple(() =>
{
Assert.That(polyhedron.VertexCount, Is.EqualTo(1));
// assert that the empty polyhedron was not modified // assert that the empty polyhedron was not modified
Assert.AreEqual(0, Polyhedron.Empty.VertexCount); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
});
} }
[TestMethod] [Test]
public void PointCount_ShouldBe0_GivenEmptyPolyhedron() public void PointCount_ShouldBe0_GivenEmptyPolyhedron()
{ {
Assert.AreEqual(0, Polyhedron.Empty.VertexCount); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Polyhedron.Empty.GetHashCode(); int hashCode = Polyhedron.Empty.GetHashCode();
Assert.AreEqual(hashCode, Polyhedron.Empty.GetHashCode()); Assert.That(Polyhedron.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
internal static Polyhedron CreateHexagon() private static PolygonF CreateHexagonPolygon()
{
var hexagon = new PolygonF();
hexagon.AddVertex(new Vector2(0, 0));
hexagon.AddVertex(new Vector2(1, 0));
hexagon.AddVertex(new Vector2(1, 1));
hexagon.AddVertex(new Vector2(0, 1));
hexagon.AddVertex(new Vector2(-1, 1));
hexagon.AddVertex(new Vector2(-1, 0));
return hexagon;
}
private static Polyhedron CreateHexagonPolyhedron()
{ {
var hexagon = new Polyhedron(); var hexagon = new Polyhedron();
hexagon.AddVertex(new Vector3(0, 0, 0)); hexagon.AddVertex(new Vector3(0, 0, 0));
@ -202,7 +223,7 @@ public class PolyhedronTests
return hexagon; return hexagon;
} }
internal static Polyhedron CreateConcavePolyhedron() private static Polyhedron CreateConcavePolyhedron()
{ {
var hexagon = new Polyhedron(); var hexagon = new Polyhedron();
hexagon.AddVertex(new Vector3(0, 0, 0)); hexagon.AddVertex(new Vector3(0, 0, 0));

View File

@ -1,37 +1,37 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class RandomTests public class RandomTests
{ {
[TestMethod] [Test]
public void NextColorArgb_ShouldReturn331515e5_GivenSeed1234() public void NextColorArgb_ShouldReturn331515e5_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(Color.FromArgb(51, 21, 21, 229), random.NextColorArgb()); Assert.That(random.NextColorArgb(), Is.EqualTo(Color.FromArgb(51, 21, 21, 229)));
} }
[TestMethod] [Test]
public void NextColorArgb_ShouldThrow_GivenNull() public void NextColorArgb_ShouldThrow_GivenNull()
{ {
Random? random = null; Random random = null!;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextColorArgb()); Assert.Throws<ArgumentNullException>(() => random.NextColorArgb());
} }
[TestMethod] [Test]
public void NextColorRgb_ShouldReturn1515e5_GivenSeed1234() public void NextColorRgb_ShouldReturn1515e5_GivenSeed1234()
{ {
var random = new Random(1234); var random = new Random(1234);
Assert.AreEqual(Color.FromArgb(255, 21, 21, 229), random.NextColorRgb()); Assert.That(random.NextColorRgb(), Is.EqualTo(Color.FromArgb(255, 21, 21, 229)));
} }
[TestMethod] [Test]
public void NextColorRgb_ShouldThrow_GivenNull() public void NextColorRgb_ShouldThrow_GivenNull()
{ {
Random? random = null; Random random = null!;
Assert.ThrowsException<ArgumentNullException>(() => random!.NextColorRgb()); Assert.Throws<ArgumentNullException>(() => random.NextColorRgb());
} }
} }

View File

@ -1,42 +1,51 @@
using System.Drawing; using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class SizeTests public class SizeTests
{ {
[TestMethod] [Test]
public void ToPoint_ShouldReturnPoint_WithEquivalentMembers() public void ToPoint_ShouldReturnPoint_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var size = new Size(random.Next(), random.Next()); var size = new Size(random.Next(), random.Next());
var point = size.ToPoint(); var point = size.ToPoint();
Assert.AreEqual(size.Width, point.X); Assert.Multiple(() =>
Assert.AreEqual(size.Height, point.Y); {
Assert.That(point.X, Is.EqualTo(size.Width));
Assert.That(point.Y, Is.EqualTo(size.Height));
});
} }
[TestMethod] [Test]
public void ToPointF_ShouldReturnPoint_WithEquivalentMembers() public void ToPointF_ShouldReturnPoint_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var size = new Size(random.Next(), random.Next()); var size = new Size(random.Next(), random.Next());
var point = size.ToPointF(); var point = size.ToPointF();
Assert.AreEqual(size.Width, point.X, 1e-6f); Assert.Multiple(() =>
Assert.AreEqual(size.Height, point.Y, 1e-6f); {
Assert.That(point.X, Is.EqualTo(size.Width).Within(1e-6f));
Assert.That(point.Y, Is.EqualTo(size.Height).Within(1e-6f));
});
} }
[TestMethod] [Test]
public void ToVector2_ShouldReturnVector_WithEquivalentMembers() public void ToVector2_ShouldReturnVector_WithEquivalentMembers()
{ {
var random = new Random(); var random = new Random();
var point = new Size(random.Next(), random.Next()); var point = new Size(random.Next(), random.Next());
var size = point.ToVector2(); var size = point.ToVector2();
Assert.AreEqual(point.Width, size.X, 1e-6f); Assert.Multiple(() =>
Assert.AreEqual(point.Height, size.Y, 1e-6f); {
Assert.That(size.X, Is.EqualTo(point.Width).Within(1e-6f));
Assert.That(size.Y, Is.EqualTo(point.Height).Within(1e-6f));
});
} }
} }

View File

@ -1,135 +1,133 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Drawing; using X10D.Drawing;
namespace X10D.Tests.Drawing; namespace X10D.Tests.Drawing;
[TestClass] [TestFixture]
public class SphereTests public class SphereTests
{ {
[TestMethod] [Test]
public void Circumference_ShouldBe2PiRadius_GivenUnitCircle() public void Circumference_ShouldBe2PiRadius_GivenUnitCircle()
{ {
var unitSphere = Sphere.Unit; var unitSphere = Sphere.Unit;
Assert.AreEqual(2.0f * MathF.PI * unitSphere.Radius, unitSphere.Circumference, 1e-6f); Assert.That(unitSphere.Circumference, Is.EqualTo(2.0f * MathF.PI * unitSphere.Radius).Within(1e-6f));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(-1, Sphere.Empty.CompareTo(Sphere.Unit)); Assert.That(Sphere.Empty.CompareTo(Sphere.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty() public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty()
{ {
Assert.AreEqual(1, Sphere.Unit.CompareTo(Sphere.Empty)); Assert.That(Sphere.Unit.CompareTo(Sphere.Empty), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject() public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject()
{ {
Assert.AreEqual(-1, Sphere.Empty.CompareTo((object)Sphere.Unit)); Assert.That(Sphere.Empty.CompareTo((object)Sphere.Unit), Is.EqualTo(-1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeOne_GivenNull() public void CompareTo_ShouldBeOne_GivenNull()
{ {
Assert.AreEqual(1, Sphere.Unit.CompareTo(null)); Assert.That(Sphere.Unit.CompareTo(null), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void CompareTo_ShouldBeZero_GivenUnitCircle() public void CompareTo_ShouldBeZero_GivenUnitCircle()
{ {
var unitCircle = Sphere.Unit; var unitCircle = Sphere.Unit;
Assert.AreEqual(0, unitCircle.CompareTo(unitCircle)); Assert.That(unitCircle.CompareTo(unitCircle), Is.Zero);
} }
[TestMethod] [Test]
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType() public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
{ {
Assert.ThrowsException<ArgumentException>(() => Sphere.Unit.CompareTo(new object())); Assert.Throws<ArgumentException>(() => _ = Sphere.Unit.CompareTo(new object()));
} }
[TestMethod] [Test]
public void Diameter_ShouldBe2_GivenUnitSphere() public void Diameter_ShouldBe2_GivenUnitSphere()
{ {
Assert.AreEqual(2.0f, Sphere.Unit.Diameter, 1e-6f); Assert.That(Sphere.Unit.Diameter, Is.EqualTo(2.0f).Within(1e-6f));
} }
[TestMethod] [Test]
public void Equals_ShouldBeTrue_GivenTwoUnitCircles() public void Equals_ShouldBeTrue_GivenTwoUnitCircles()
{ {
var unitCircle1 = Sphere.Unit; var unitCircle1 = Sphere.Unit;
var unitCircle2 = Sphere.Unit; var unitCircle2 = Sphere.Unit;
Assert.AreEqual(unitCircle1, unitCircle2);
Assert.IsTrue(unitCircle1 == unitCircle2); Assert.Multiple(() =>
Assert.IsFalse(unitCircle1 != unitCircle2); {
Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
});
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentObjects() public void Equals_ShouldBeFalse_GivenDifferentObjects()
{ {
Assert.IsFalse(Sphere.Unit.Equals(null)); Assert.That(Sphere.Unit, Is.Not.EqualTo(null));
} }
[TestMethod] [Test]
public void Equals_ShouldBeFalse_GivenDifferentCircles() public void Equals_ShouldBeFalse_GivenDifferentCircles()
{ {
Assert.AreNotEqual(Sphere.Unit, Sphere.Empty); Assert.That(Sphere.Empty, Is.Not.EqualTo(Sphere.Unit));
Assert.IsFalse(Sphere.Unit == Sphere.Empty); Assert.That(Sphere.Unit, Is.Not.EqualTo(Sphere.Empty));
Assert.IsTrue(Sphere.Unit != Sphere.Empty);
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle() public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Sphere.Empty.GetHashCode(); int hashCode = Sphere.Empty.GetHashCode();
Assert.AreEqual(hashCode, Sphere.Empty.GetHashCode()); Assert.That(Sphere.Empty.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void GetHashCode_ShouldBeCorrect_GivenUnitCircle() public void GetHashCode_ShouldBeCorrect_GivenUnitCircle()
{ {
// this test is pretty pointless, it exists only for code coverage purposes // this test is pretty pointless, it exists only for code coverage purposes
int hashCode = Sphere.Unit.GetHashCode(); int hashCode = Sphere.Unit.GetHashCode();
Assert.AreEqual(hashCode, Sphere.Unit.GetHashCode()); Assert.That(Sphere.Unit.GetHashCode(), Is.EqualTo(hashCode));
} }
[TestMethod] [Test]
public void op_GreaterThan_True_GivenUnitAndEmptyCircle() public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
{ {
Assert.IsTrue(Sphere.Unit > Sphere.Empty); Assert.That(Sphere.Unit, Is.GreaterThan(Sphere.Empty));
Assert.IsTrue(Sphere.Unit >= Sphere.Empty); Assert.That(Sphere.Unit, Is.GreaterThanOrEqualTo(Sphere.Empty));
Assert.IsFalse(Sphere.Unit < Sphere.Empty);
Assert.IsFalse(Sphere.Unit <= Sphere.Empty);
} }
[TestMethod] [Test]
public void op_LessThan_True_GivenEmptyAndUnitCircle() public void op_LessThan_True_GivenEmptyAndUnitCircle()
{ {
Assert.IsTrue(Sphere.Empty < Sphere.Unit); Assert.That(Sphere.Empty, Is.LessThan(Sphere.Unit));
Assert.IsTrue(Sphere.Empty <= Sphere.Unit); Assert.That(Sphere.Empty, Is.LessThanOrEqualTo(Sphere.Unit));
Assert.IsFalse(Sphere.Empty > Sphere.Unit);
Assert.IsFalse(Sphere.Empty >= Sphere.Unit);
} }
[TestMethod] [Test]
public void Radius_ShouldBe0_GivenEmptySphere() public void Radius_ShouldBe0_GivenEmptySphere()
{ {
Assert.AreEqual(0, Sphere.Empty.Radius); Assert.That(Sphere.Empty.Radius, Is.Zero);
} }
[TestMethod] [Test]
public void Radius_ShouldBe1_GivenUnitSphere() public void Radius_ShouldBe1_GivenUnitSphere()
{ {
Assert.AreEqual(1, Sphere.Unit.Radius); Assert.That(Sphere.Unit.Radius, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void Volume_ShouldBe4Over3TimesPi_GivenUnitCircle() public void Volume_ShouldBe4Over3TimesPi_GivenUnitCircle()
{ {
var unitSphere = Sphere.Unit; var unitSphere = Sphere.Unit;
Assert.AreEqual(4.0f / 3.0f * MathF.PI, unitSphere.Volume); Assert.That(unitSphere.Volume, Is.EqualTo(4.0f / 3.0f * MathF.PI));
} }
} }

View File

@ -1,14 +1,14 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Hosting.DependencyInjection; using X10D.Hosting.DependencyInjection;
namespace X10D.Tests.Hosting; namespace X10D.Tests.Hosting;
[TestClass] [TestFixture]
public class ServiceCollectionTests public class ServiceCollectionTests
{ {
[TestMethod] [Test]
public void AddHostedSingleton_ShouldRegisterServiceAsSingletonAndAsHostedService() public void AddHostedSingleton_ShouldRegisterServiceAsSingletonAndAsHostedService()
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
@ -19,14 +19,17 @@ public class ServiceCollectionTests
var service = serviceProvider.GetService<TestService>(); var service = serviceProvider.GetService<TestService>();
var hostedService = serviceProvider.GetService<IHostedService>(); var hostedService = serviceProvider.GetService<IHostedService>();
Assert.IsNotNull(service); Assert.Multiple(() =>
Assert.IsNotNull(hostedService); {
Assert.IsInstanceOfType(service, typeof(TestService)); Assert.That(service, Is.Not.Null);
Assert.IsInstanceOfType(hostedService, typeof(TestService)); Assert.That(hostedService, Is.Not.Null);
Assert.AreSame(service, hostedService); Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(hostedService, Is.SameAs(service));
});
} }
[TestMethod] [Test]
public void AddHostedSingleton_ShouldRegisterServiceTypeAsSingletonAndAsHostedService() public void AddHostedSingleton_ShouldRegisterServiceTypeAsSingletonAndAsHostedService()
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
@ -37,11 +40,14 @@ public class ServiceCollectionTests
var service = serviceProvider.GetService<TestService>(); var service = serviceProvider.GetService<TestService>();
var hostedService = serviceProvider.GetService<IHostedService>(); var hostedService = serviceProvider.GetService<IHostedService>();
Assert.IsNotNull(service); Assert.Multiple(() =>
Assert.IsNotNull(hostedService); {
Assert.IsInstanceOfType(service, typeof(TestService)); Assert.That(service, Is.Not.Null);
Assert.IsInstanceOfType(hostedService, typeof(TestService)); Assert.That(hostedService, Is.Not.Null);
Assert.AreSame(service, hostedService); Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(hostedService, Is.SameAs(service));
});
} }
private sealed class TestService : IHostedService private sealed class TestService : IHostedService

View File

@ -1,32 +1,32 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class BooleanTests public class BooleanTests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsArrayContaining1() public void GetBytes_ReturnsArrayContaining1()
{ {
const bool value = true; const bool value = true;
CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes()); CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContaining1_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanContaining1_GivenLargeEnoughSpan()
{ {
const bool value = true; const bool value = true;
Span<byte> buffer = stackalloc byte[1]; Span<byte> buffer = stackalloc byte[1];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray()); CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const bool value = true; const bool value = true;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,32 +1,32 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class ByteTests public class ByteTests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsArrayContainingItself() public void GetBytes_ReturnsArrayContainingItself()
{ {
const byte value = 0xFF; const byte value = 0xFF;
CollectionAssert.AreEqual(new[] {value}, value.GetBytes()); CollectionAssert.AreEqual(new[] {value}, value.GetBytes());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{ {
const byte value = 0xFF; const byte value = 0xFF;
Span<byte> buffer = stackalloc byte[1]; Span<byte> buffer = stackalloc byte[1];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new[] {value}, buffer.ToArray()); CollectionAssert.AreEqual(new[] {value}, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const byte value = 0x0F; const byte value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,19 +1,19 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class DirectoryInfoTests public class DirectoryInfoTests
{ {
[TestMethod] [Test]
public void Clear_ShouldClear_GivenValidDirectory() public void Clear_ShouldClear_GivenValidDirectory()
{ {
string tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var tempDirectory = new DirectoryInfo(tempDirectoryPath); var tempDirectory = new DirectoryInfo(tempDirectoryPath);
tempDirectory.Create(); tempDirectory.Create();
Assert.IsTrue(tempDirectory.Exists); Assert.That(tempDirectory.Exists);
var file = new FileInfo(Path.Combine(tempDirectory.FullName, "file")); var file = new FileInfo(Path.Combine(tempDirectory.FullName, "file"));
file.Create().Close(); file.Create().Close();
@ -24,34 +24,42 @@ public class DirectoryInfoTests
var childFile = new FileInfo(Path.Combine(childDirectory.FullName, "childFile")); var childFile = new FileInfo(Path.Combine(childDirectory.FullName, "childFile"));
childFile.Create().Close(); childFile.Create().Close();
Assert.AreEqual(1, tempDirectory.GetFiles().Length); Assert.Multiple(() =>
Assert.AreEqual(1, tempDirectory.GetDirectories().Length); {
Assert.That(tempDirectory.GetFiles(), Has.Length.EqualTo(1));
Assert.That(tempDirectory.GetDirectories(), Has.Length.EqualTo(1));
});
tempDirectory.Clear(); tempDirectory.Clear();
Assert.AreEqual(0, tempDirectory.GetFiles().Length);
Assert.AreEqual(0, tempDirectory.GetDirectories().Length); Assert.Multiple(() =>
Assert.IsTrue(tempDirectory.Exists); {
Assert.That(tempDirectory.GetFiles(), Is.Empty);
Assert.That(tempDirectory.GetDirectories(), Is.Empty);
Assert.That(tempDirectory.Exists);
});
tempDirectory.Delete(); tempDirectory.Delete();
} }
[TestMethod] [Test]
public void Clear_ShouldThrowArgumentNullException_GivenNull() public void Clear_ShouldThrowArgumentNullException_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => ((DirectoryInfo?)null)!.Clear()); Assert.Throws<ArgumentNullException>(() => ((DirectoryInfo?)null)!.Clear());
} }
[TestMethod] [Test]
public void Clear_ShouldThrowDirectoryNotFoundException_GivenInvalidDirectory() public void Clear_ShouldThrowDirectoryNotFoundException_GivenInvalidDirectory()
{ {
var directory = new DirectoryInfo(@"123:/@12#3"); var directory = new DirectoryInfo(@"123:/@12#3");
Assert.ThrowsException<DirectoryNotFoundException>(() => directory.Clear()); Assert.Throws<DirectoryNotFoundException>(() => directory.Clear());
} }
[TestMethod] [Test]
public void Clear_ShouldThrowDirectoryNotFoundException_GivenNonExistentDirectory() public void Clear_ShouldThrowDirectoryNotFoundException_GivenNonExistentDirectory()
{ {
var directory = new DirectoryInfo(@"/@12#3"); var directory = new DirectoryInfo(@"/@12#3");
Assert.IsFalse(directory.Exists); Assert.That(directory.Exists, Is.False);
Assert.ThrowsException<DirectoryNotFoundException>(() => directory.Clear()); Assert.Throws<DirectoryNotFoundException>(() => directory.Clear());
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class DoubleTests public class DoubleTests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const double value = 42.5; const double value = 42.5;
@ -16,7 +16,7 @@ public class DoubleTests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const double value = 42.5; const double value = 42.5;
@ -27,7 +27,7 @@ public class DoubleTests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const double value = 42.5; const double value = 42.5;
@ -36,11 +36,11 @@ public class DoubleTests
: new byte[] {0x40, 0x45, 0x40, 0, 0, 0, 0, 0}; : new byte[] {0x40, 0x45, 0x40, 0, 0, 0, 0, 0};
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const double value = 42.5; const double value = 42.5;
@ -49,18 +49,18 @@ public class DoubleTests
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const double value = 42.5; const double value = 42.5;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,23 +1,23 @@
using System.Security.Cryptography; using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class FileInfoTests public class FileInfoTests
{ {
[TestMethod] [Test]
public void GetHashSha1ShouldBeCorrect() public void GetHashSha1ShouldBeCorrect()
{ {
string fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin"; var fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin";
if (File.Exists(fileName)) if (File.Exists(fileName))
{ {
Assert.Fail("Temporary file already exists"); Assert.Fail("Temporary file already exists");
} }
File.WriteAllText(fileName, "Hello World"); File.WriteAllText(fileName, "Hello World");
Assert.IsTrue(File.Exists(fileName)); Assert.That(File.Exists(fileName));
// SHA-1 // SHA-1
byte[] expectedHash = byte[] expectedHash =
@ -37,17 +37,17 @@ public class FileInfoTests
} }
} }
[TestMethod] [Test]
public void TryWriteHashSha1ShouldBeCorrect() public void TryWriteHashSha1ShouldBeCorrect()
{ {
string fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin"; var fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin";
if (File.Exists(fileName)) if (File.Exists(fileName))
{ {
Assert.Fail("Temporary file already exists"); Assert.Fail("Temporary file already exists");
} }
File.WriteAllText(fileName, "Hello World"); File.WriteAllText(fileName, "Hello World");
Assert.IsTrue(File.Exists(fileName)); Assert.That(File.Exists(fileName));
// SHA-1 // SHA-1
byte[] expectedHash = byte[] expectedHash =
@ -60,7 +60,7 @@ public class FileInfoTests
{ {
Span<byte> hash = stackalloc byte[20]; Span<byte> hash = stackalloc byte[20];
new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten); new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.AreEqual(expectedHash.Length, bytesWritten); Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
CollectionAssert.AreEqual(expectedHash, hash.ToArray()); CollectionAssert.AreEqual(expectedHash, hash.ToArray());
} }
finally finally
@ -69,25 +69,25 @@ public class FileInfoTests
} }
} }
[TestMethod] [Test]
public void GetHashNullShouldThrow() public void GetHashNullShouldThrow()
{ {
// any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here // any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here
Assert.ThrowsException<ArgumentNullException>(() => ((FileInfo?)null)!.GetHash<SHA1>()); Assert.Throws<ArgumentNullException>(() => _ = ((FileInfo?)null)!.GetHash<SHA1>());
Assert.ThrowsException<ArgumentNullException>(() => ((FileInfo?)null)!.TryWriteHash<SHA1>(Span<byte>.Empty, out _)); Assert.Throws<ArgumentNullException>(() => ((FileInfo?)null)!.TryWriteHash<SHA1>(Span<byte>.Empty, out _));
} }
[TestMethod] [Test]
public void GetHashInvalidFileShouldThrow() public void GetHashInvalidFileShouldThrow()
{ {
string fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin"; var fileName = $"temp.{DateTimeOffset.Now.ToUnixTimeSeconds()}.bin";
if (File.Exists(fileName)) if (File.Exists(fileName))
{ {
Assert.Fail("Temporary file already exists"); Assert.Fail("Temporary file already exists");
} }
// any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here // any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here
Assert.ThrowsException<FileNotFoundException>(() => new FileInfo(fileName).GetHash<SHA1>()); Assert.Throws<FileNotFoundException>(() => _ = new FileInfo(fileName).GetHash<SHA1>());
Assert.ThrowsException<FileNotFoundException>(() => new FileInfo(fileName).TryWriteHash<SHA1>(Span<byte>.Empty, out _)); Assert.Throws<FileNotFoundException>(() => new FileInfo(fileName).TryWriteHash<SHA1>(Span<byte>.Empty, out _));
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class Int16Tests public class Int16Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const short value = 0x0F; const short value = 0x0F;
@ -14,7 +14,7 @@ public class Int16Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const short value = 0x0F; const short value = 0x0F;
@ -25,18 +25,18 @@ public class Int16Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const short value = 0x0F; const short value = 0x0F;
byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0} : new byte[] {0, 0x0F}; byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0} : new byte[] {0, 0x0F};
Span<byte> buffer = stackalloc byte[2]; Span<byte> buffer = stackalloc byte[2];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const short value = 0x0F; const short value = 0x0F;
@ -45,18 +45,18 @@ public class Int16Tests
Span<byte> buffer = stackalloc byte[2]; Span<byte> buffer = stackalloc byte[2];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const short value = 0x0F; const short value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class Int32Tests public class Int32Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const int value = 0x0F; const int value = 0x0F;
@ -14,7 +14,7 @@ public class Int32Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const int value = 0x0F; const int value = 0x0F;
@ -25,18 +25,18 @@ public class Int32Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const int value = 0x0F; const int value = 0x0F;
byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0, 0, 0} : new byte[] {0, 0, 0, 0x0F}; byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0, 0, 0} : new byte[] {0, 0, 0, 0x0F};
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const int value = 0x0F; const int value = 0x0F;
@ -45,18 +45,18 @@ public class Int32Tests
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const int value = 0x0F; const int value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class Int64Tests public class Int64Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const long value = 0x0F; const long value = 0x0F;
@ -16,7 +16,7 @@ public class Int64Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const long value = 0x0F; const long value = 0x0F;
@ -27,7 +27,7 @@ public class Int64Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const long value = 0x0F; const long value = 0x0F;
@ -36,11 +36,11 @@ public class Int64Tests
: new byte[] {0, 0, 0, 0, 0, 0, 0, 0x0F}; : new byte[] {0, 0, 0, 0, 0, 0, 0, 0x0F};
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const long value = 0x0F; const long value = 0x0F;
@ -49,18 +49,18 @@ public class Int64Tests
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const long value = 0x0F; const long value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,27 +1,27 @@
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class ListOfByteTests public class ListOfByteTests
{ {
[TestMethod] [Test]
public void AsString_ShouldReturnBytes_GivenBytes() public void AsString_ShouldReturnBytes_GivenBytes()
{ {
var bytes = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05}; var bytes = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};
Assert.AreEqual("01-02-03-04-05", bytes.AsString()); Assert.That(bytes.AsString(), Is.EqualTo("01-02-03-04-05"));
} }
[TestMethod] [Test]
public void AsString_ShouldThrow_GivenNullArray() public void AsString_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[]? bytes = null;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.AsString()); Assert.Throws<ArgumentNullException>(() => bytes!.AsString());
} }
[TestMethod] [Test]
public void ToDouble_ShouldReturnDouble_GivenBytes() public void ToDouble_ShouldReturnDouble_GivenBytes()
{ {
var bytes = new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40}; var bytes = new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40};
@ -31,59 +31,59 @@ public class ListOfByteTests
Array.Reverse(bytes); Array.Reverse(bytes);
} }
Assert.AreEqual(420.0, bytes.ToDouble(), 1e-6); Assert.That(bytes.ToDouble(), Is.EqualTo(420.0).Within(1e-6));
} }
[TestMethod] [Test]
public void ToDouble_ShouldThrow_GivenNullArray() public void ToDouble_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToDouble()); Assert.Throws<ArgumentNullException>(() => bytes.ToDouble());
} }
[TestMethod] [Test]
public void ToInt16_ShouldReturnInt16_GivenBytes() public void ToInt16_ShouldReturnInt16_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01}; var bytes = new byte[] {0xA4, 0x01};
Assert.AreEqual(420, bytes.ToInt16()); Assert.That(bytes.ToInt16(), Is.EqualTo(420));
} }
[TestMethod] [Test]
public void ToInt16_ShouldThrow_GivenNullArray() public void ToInt16_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToInt16()); Assert.Throws<ArgumentNullException>(() => bytes.ToInt16());
} }
[TestMethod] [Test]
public void ToInt32_ShouldReturnInt32_GivenBytes() public void ToInt32_ShouldReturnInt32_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00}; var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00};
Assert.AreEqual(420, bytes.ToInt32()); Assert.That(bytes.ToInt32(), Is.EqualTo(420));
} }
[TestMethod] [Test]
public void ToInt32_ShouldThrow_GivenNullArray() public void ToInt32_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToInt32()); Assert.Throws<ArgumentNullException>(() => bytes.ToInt32());
} }
[TestMethod] [Test]
public void ToInt64_ShouldReturnInt32_GivenBytes() public void ToInt64_ShouldReturnInt32_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Assert.AreEqual(420L, bytes.ToInt64()); Assert.That(bytes.ToInt64(), Is.EqualTo(420L));
} }
[TestMethod] [Test]
public void ToInt64_ShouldThrow_GivenNullArray() public void ToInt64_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[]? bytes = null;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToInt64()); Assert.Throws<ArgumentNullException>(() => bytes!.ToInt64());
} }
[TestMethod] [Test]
public void ToSingle_ShouldReturnDouble_GivenBytes() public void ToSingle_ShouldReturnDouble_GivenBytes()
{ {
var bytes = new byte[] {0x00, 0x00, 0xD2, 0x43}; var bytes = new byte[] {0x00, 0x00, 0xD2, 0x43};
@ -93,76 +93,76 @@ public class ListOfByteTests
Array.Reverse(bytes); Array.Reverse(bytes);
} }
Assert.AreEqual(420.0, bytes.ToSingle(), 1e-6); Assert.That(bytes.ToSingle(), Is.EqualTo(420.0).Within(1e-6));
} }
[TestMethod] [Test]
public void ToSingle_ShouldThrow_GivenNullArray() public void ToSingle_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToSingle()); Assert.Throws<ArgumentNullException>(() => bytes.ToSingle());
} }
[TestMethod] [Test]
public void ToString_ShouldReturnHelloWorld_GivenUTF8() public void ToString_ShouldReturnHelloWorld_GivenUTF8()
{ {
var bytes = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}; var bytes = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64};
Assert.AreEqual("Hello World", bytes.ToString(Encoding.UTF8)); Assert.That(bytes.ToString(Encoding.UTF8), Is.EqualTo("Hello World"));
} }
[TestMethod] [Test]
public void ToString_ShouldThrow_GivenNullArray() public void ToString_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToString(Encoding.UTF8)); Assert.Throws<ArgumentNullException>(() => bytes.ToString(Encoding.UTF8));
} }
[TestMethod] [Test]
public void ToString_ShouldThrow_GivenNullEncoding() public void ToString_ShouldThrow_GivenNullEncoding()
{ {
var bytes = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}; var bytes = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64};
Assert.ThrowsException<ArgumentNullException>(() => bytes.ToString(null!)); Assert.Throws<ArgumentNullException>(() => bytes.ToString(null!));
} }
[TestMethod] [Test]
public void ToUInt16_ShouldReturnInt16_GivenBytes() public void ToUInt16_ShouldReturnInt16_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01}; var bytes = new byte[] {0xA4, 0x01};
Assert.AreEqual((ushort)420, bytes.ToUInt16()); Assert.That(bytes.ToUInt16(), Is.EqualTo((ushort)420));
} }
[TestMethod] [Test]
public void ToUInt16_ShouldThrow_GivenNullArray() public void ToUInt16_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToUInt16()); Assert.Throws<ArgumentNullException>(() => bytes.ToUInt16());
} }
[TestMethod] [Test]
public void ToUInt32_ShouldReturnInt32_GivenBytes() public void ToUInt32_ShouldReturnInt32_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00}; var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00};
Assert.AreEqual(420U, bytes.ToUInt32()); Assert.That(bytes.ToUInt32(), Is.EqualTo(420U));
} }
[TestMethod] [Test]
public void ToUInt32_ShouldThrow_GivenNullArray() public void ToUInt32_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[]? bytes = null;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToUInt32()); Assert.Throws<ArgumentNullException>(() => bytes!.ToUInt32());
} }
[TestMethod] [Test]
public void ToUInt64_ShouldReturnInt32_GivenBytes() public void ToUInt64_ShouldReturnInt32_GivenBytes()
{ {
var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; var bytes = new byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Assert.AreEqual(420UL, bytes.ToUInt64()); Assert.That(bytes.ToUInt64(), Is.EqualTo(420UL));
} }
[TestMethod] [Test]
public void ToUInt64_ShouldThrow_GivenNullArray() public void ToUInt64_ShouldThrow_GivenNullArray()
{ {
byte[]? bytes = null; byte[] bytes = null!;
Assert.ThrowsException<ArgumentNullException>(() => bytes!.ToUInt64()); Assert.Throws<ArgumentNullException>(() => bytes.ToUInt64());
} }
} }

View File

@ -1,33 +1,33 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class SByteTests public class SByteTests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsArrayContainingItself() public void GetBytes_ReturnsArrayContainingItself()
{ {
const sbyte value = 0x0F; const sbyte value = 0x0F;
CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes()); CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{ {
const sbyte value = 0x0F; const sbyte value = 0x0F;
Span<byte> buffer = stackalloc byte[1]; Span<byte> buffer = stackalloc byte[1];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray()); CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const sbyte value = 0x0F; const sbyte value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class SingleTests public class SingleTests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const float value = 42.5f; const float value = 42.5f;
@ -16,7 +16,7 @@ public class SingleTests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const float value = 42.5f; const float value = 42.5f;
@ -27,7 +27,7 @@ public class SingleTests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const float value = 42.5f; const float value = 42.5f;
@ -36,11 +36,11 @@ public class SingleTests
: new byte[] {0x42, 0x2A, 0, 0}; : new byte[] {0x42, 0x2A, 0, 0};
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const float value = 42.5f; const float value = 42.5f;
@ -49,18 +49,18 @@ public class SingleTests
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const float value = 42.5f; const float value = 42.5f;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadDecimal_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadDecimal_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadDecimal()); Assert.Throws<ArgumentException>(() => stream.ReadDecimal());
Assert.ThrowsException<ArgumentException>(() => stream.ReadDecimal(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadDecimal(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadDecimal(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadDecimal(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadDecimal_ShouldThrowArgumentNullException_GivenNullStream() public void ReadDecimal_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDecimal()); Assert.Throws<ArgumentNullException>(() => stream.ReadDecimal());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDecimal(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadDecimal(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDecimal(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadDecimal(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadDecimal_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadDecimal_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadDecimal((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadDecimal((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadDecimal_ShouldReadBigEndian_GivenBigEndian() public void ReadDecimal_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -49,11 +49,14 @@ public partial class StreamTests
const decimal expected = 420.0m; const decimal expected = 420.0m;
decimal actual = stream.ReadDecimal(Endianness.BigEndian); decimal actual = stream.ReadDecimal(Endianness.BigEndian);
Assert.AreEqual(16, stream.Position); Assert.Multiple(() =>
Assert.AreEqual(expected, actual); {
Assert.That(stream.Position, Is.EqualTo(16));
Assert.That(actual, Is.EqualTo(expected));
});
} }
[TestMethod] [Test]
public void ReadDecimal_ShouldWriteLittleEndian_GivenLittleEndian() public void ReadDecimal_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -67,7 +70,10 @@ public partial class StreamTests
const decimal expected = 420.0m; const decimal expected = 420.0m;
decimal actual = stream.ReadDecimal(Endianness.LittleEndian); decimal actual = stream.ReadDecimal(Endianness.LittleEndian);
Assert.AreEqual(16, stream.Position); Assert.Multiple(() =>
Assert.AreEqual(expected, actual); {
Assert.That(stream.Position, Is.EqualTo(16));
Assert.That(actual, Is.EqualTo(expected));
});
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadDouble_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadDouble_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadDouble()); Assert.Throws<ArgumentException>(() => stream.ReadDouble());
Assert.ThrowsException<ArgumentException>(() => stream.ReadDouble(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadDouble(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadDouble(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadDouble(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadDouble_ShouldThrowArgumentNullException_GivenNullStream() public void ReadDouble_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDouble()); Assert.Throws<ArgumentNullException>(() => stream.ReadDouble());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDouble(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadDouble(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadDouble(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadDouble(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadDouble_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadDouble_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadDouble((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadDouble((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadDouble_ShouldReadBigEndian_GivenBigEndian() public void ReadDouble_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -46,11 +46,11 @@ public partial class StreamTests
const double expected = 420.0; const double expected = 420.0;
double actual = stream.ReadDouble(Endianness.BigEndian); double actual = stream.ReadDouble(Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReadDouble_ShouldWriteLittleEndian_GivenLittleEndian() public void ReadDouble_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -61,7 +61,7 @@ public partial class StreamTests
const double expected = 420.0; const double expected = 420.0;
double actual = stream.ReadDouble(Endianness.LittleEndian); double actual = stream.ReadDouble(Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadInt16_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadInt16_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt16()); Assert.Throws<ArgumentException>(() => stream.ReadInt16());
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt16(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt16(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt16(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt16(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt16_ShouldThrowArgumentNullException_GivenNullStream() public void ReadInt16_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt16()); Assert.Throws<ArgumentNullException>(() => stream.ReadInt16());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt16(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt16(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt16(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt16(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadInt16((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadInt16((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadInt16_ShouldReadBigEndian_GivenBigEndian() public void ReadInt16_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -46,11 +46,11 @@ public partial class StreamTests
const short expected = 420; const short expected = 420;
short actual = stream.ReadInt16(Endianness.BigEndian); short actual = stream.ReadInt16(Endianness.BigEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReadInt16_ShouldReadLittleEndian_GivenLittleEndian() public void ReadInt16_ShouldReadLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -61,7 +61,7 @@ public partial class StreamTests
const short expected = 420; const short expected = 420;
short actual = stream.ReadInt16(Endianness.LittleEndian); short actual = stream.ReadInt16(Endianness.LittleEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadInt32_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadInt32_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt32()); Assert.Throws<ArgumentException>(() => stream.ReadInt32());
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt32(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt32(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt32(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt32(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt32_ShouldThrowArgumentNullException_GivenNullStream() public void ReadInt32_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt32()); Assert.Throws<ArgumentNullException>(() => stream.ReadInt32());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt32(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt32(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt32(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt32(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadInt32((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadInt32((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadInt32_ShouldReadBigEndian_GivenBigEndian() public void ReadInt32_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -46,11 +46,11 @@ public partial class StreamTests
const int expected = 420; const int expected = 420;
int actual = stream.ReadInt32(Endianness.BigEndian); int actual = stream.ReadInt32(Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReadInt32_ShouldReadLittleEndian_GivenLittleEndian() public void ReadInt32_ShouldReadLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -61,7 +61,7 @@ public partial class StreamTests
const int expected = 420; const int expected = 420;
int actual = stream.ReadInt32(Endianness.LittleEndian); int actual = stream.ReadInt32(Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadInt64_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadInt64_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt64()); Assert.Throws<ArgumentException>(() => stream.ReadInt64());
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt64(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt64(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadInt64(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadInt64(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt64_ShouldThrowArgumentNullException_GivenNullStream() public void ReadInt64_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt64()); Assert.Throws<ArgumentNullException>(() => stream.ReadInt64());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt64(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt64(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadInt64(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadInt64(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadInt64((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadInt64((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadInt64_ShouldReadBigEndian_GivenBigEndian() public void ReadInt64_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -46,11 +46,11 @@ public partial class StreamTests
const long expected = 420; const long expected = 420;
long actual = stream.ReadInt64(Endianness.BigEndian); long actual = stream.ReadInt64(Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReadInt64_ShouldWriteLittleEndian_GivenLittleEndian() public void ReadInt64_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -61,7 +61,7 @@ public partial class StreamTests
const long expected = 420; const long expected = 420;
long actual = stream.ReadInt64(Endianness.LittleEndian); long actual = stream.ReadInt64(Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void ReadSingle_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadSingle_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadSingle()); Assert.Throws<ArgumentException>(() => stream.ReadSingle());
Assert.ThrowsException<ArgumentException>(() => stream.ReadSingle(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadSingle(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadSingle(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadSingle(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadSingle_ShouldThrowArgumentNullException_GivenNullStream() public void ReadSingle_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadSingle()); Assert.Throws<ArgumentNullException>(() => stream.ReadSingle());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadSingle(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadSingle(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadSingle(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadSingle(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void ReadSingle_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadSingle_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -32,10 +32,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadSingle((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadSingle((Endianness)(-1)));
} }
[TestMethod] [Test]
public void ReadSingle_ShouldReadBigEndian_GivenBigEndian() public void ReadSingle_ShouldReadBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -46,11 +46,11 @@ public partial class StreamTests
const float expected = 420.0f; const float expected = 420.0f;
float actual = stream.ReadSingle(Endianness.BigEndian); float actual = stream.ReadSingle(Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void ReadSingle_ShouldReadLittleEndian_GivenLittleEndian() public void ReadSingle_ShouldReadLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -61,7 +61,7 @@ public partial class StreamTests
const float expected = 420.0f; const float expected = 420.0f;
float actual = stream.ReadSingle(Endianness.LittleEndian); float actual = stream.ReadSingle(Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,31 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt16_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadUInt16_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt16()); Assert.Throws<ArgumentException>(() => stream.ReadUInt16());
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt16(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt16(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt16(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt16(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt16_ShouldThrowArgumentNullException_GivenNullStream() public void ReadUInt16_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt16()); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt16());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt16(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt16(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt16(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt16(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadUInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -35,10 +35,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadUInt16((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadUInt16((Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt16_ShouldReadBigEndian_GivenBigEndian() public void ReadUInt16_ShouldReadBigEndian_GivenBigEndian()
{ {
@ -50,11 +50,11 @@ public partial class StreamTests
const ushort expected = 420; const ushort expected = 420;
ushort actual = stream.ReadUInt16(Endianness.BigEndian); ushort actual = stream.ReadUInt16(Endianness.BigEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt16_ShouldReadLittleEndian_GivenLittleEndian() public void ReadUInt16_ShouldReadLittleEndian_GivenLittleEndian()
{ {
@ -66,7 +66,7 @@ public partial class StreamTests
const ushort expected = 420; const ushort expected = 420;
ushort actual = stream.ReadUInt16(Endianness.LittleEndian); ushort actual = stream.ReadUInt16(Endianness.LittleEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,31 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt32_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadUInt32_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt32()); Assert.Throws<ArgumentException>(() => stream.ReadUInt32());
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt32(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt32(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt32(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt32(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt32_ShouldThrowArgumentNullException_GivenNullStream() public void ReadUInt32_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt32()); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt32());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt32(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt32(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt32(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt32(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadUInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -35,10 +35,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadUInt32((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadUInt32((Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt32_ShouldReadBigEndian_GivenBigEndian() public void ReadUInt32_ShouldReadBigEndian_GivenBigEndian()
{ {
@ -50,11 +50,11 @@ public partial class StreamTests
const uint expected = 420; const uint expected = 420;
uint actual = stream.ReadUInt32(Endianness.BigEndian); uint actual = stream.ReadUInt32(Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt32_ShouldReadLittleEndian_GivenLittleEndian() public void ReadUInt32_ShouldReadLittleEndian_GivenLittleEndian()
{ {
@ -66,7 +66,7 @@ public partial class StreamTests
const uint expected = 420; const uint expected = 420;
uint actual = stream.ReadUInt32(Endianness.LittleEndian); uint actual = stream.ReadUInt32(Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,31 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt64_ShouldThrowArgumentException_GivenNonReadableStream() public void ReadUInt64_ShouldThrowArgumentException_GivenNonReadableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt64()); Assert.Throws<ArgumentException>(() => stream.ReadUInt64());
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt64(Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt64(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.ReadUInt64(Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.ReadUInt64(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt64_ShouldThrowArgumentNullException_GivenNullStream() public void ReadUInt64_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt64()); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt64());
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt64(Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt64(Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.ReadUInt64(Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.ReadUInt64(Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void ReadUInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -35,10 +35,10 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.ReadUInt64((Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadUInt64((Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt64_ShouldReadBigEndian_GivenBigEndian() public void ReadUInt64_ShouldReadBigEndian_GivenBigEndian()
{ {
@ -50,11 +50,11 @@ public partial class StreamTests
const ulong expected = 420; const ulong expected = 420;
ulong actual = stream.ReadUInt64(Endianness.BigEndian); ulong actual = stream.ReadUInt64(Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void ReadUInt64_ShouldWriteLittleEndian_GivenLittleEndian() public void ReadUInt64_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
@ -66,7 +66,7 @@ public partial class StreamTests
const ulong expected = 420; const ulong expected = 420;
ulong actual = stream.ReadUInt64(Endianness.LittleEndian); ulong actual = stream.ReadUInt64(Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
Assert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected));
} }
} }

View File

@ -1,28 +1,28 @@
using System.Diagnostics; using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteDecimal_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteDecimal_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0m, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0m, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0m, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0m, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteDecimal_ShouldThrowArgumentNullException_GivenNullStream() public void WriteDecimal_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0m, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0m, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0m, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0m, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteDecimal_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteDecimal_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -31,16 +31,16 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0m, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0m, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0m, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0m, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteDecimal_ShouldWriteBigEndian_GivenBigEndian() public void WriteDecimal_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0m, Endianness.BigEndian); stream.Write(420.0m, Endianness.BigEndian);
Assert.AreEqual(16, stream.Position); Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[16]; Span<byte> actual = stackalloc byte[16];
@ -50,16 +50,16 @@ public partial class StreamTests
}; };
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(16, read); Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteDecimal_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteDecimal_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0m, Endianness.LittleEndian); stream.Write(420.0m, Endianness.LittleEndian);
Assert.AreEqual(16, stream.Position); Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[16]; Span<byte> actual = stackalloc byte[16];
@ -71,7 +71,7 @@ public partial class StreamTests
Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}"))); Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}")));
Assert.AreEqual(16, read); Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,27 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteDouble_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteDouble_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteDouble_ShouldThrowArgumentNullException_GivenNullStream() public void WriteDouble_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteDouble_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteDouble_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -30,39 +30,39 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteDouble_ShouldWriteBigEndian_GivenBigEndian() public void WriteDouble_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0, Endianness.BigEndian); stream.Write(420.0, Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteDouble_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteDouble_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0, Endianness.LittleEndian); stream.Write(420.0, Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,27 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteInt16_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteInt16_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write((short)420, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write((short)420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write((short)420, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write((short)420, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt16_ShouldThrowArgumentNullException_GivenNullStream() public void WriteInt16_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write((short)420, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write((short)420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write((short)420, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write((short)420, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -30,39 +30,39 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write((short)420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write((short)420, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write((short)420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write((short)420, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteInt16_ShouldWriteBigEndian_GivenBigEndian() public void WriteInt16_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write((short)420, Endianness.BigEndian); stream.Write((short)420, Endianness.BigEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(2, read); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteInt16_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteInt16_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write((short)420, Endianness.LittleEndian); stream.Write((short)420, Endianness.LittleEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(2, read); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,27 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteInt32_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteInt32_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt32_ShouldThrowArgumentNullException_GivenNullStream() public void WriteInt32_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -30,39 +30,39 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteInt32_ShouldWriteBigEndian_GivenBigEndian() public void WriteInt32_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420, Endianness.BigEndian); stream.Write(420, Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteInt32_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteInt32_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420, Endianness.LittleEndian); stream.Write(420, Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,27 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteInt64_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteInt64_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420L, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420L, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420L, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420L, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt64_ShouldThrowArgumentNullException_GivenNullStream() public void WriteInt64_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420L, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420L, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420L, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420L, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -30,39 +30,39 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420L, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420L, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420L, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420L, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteInt64_ShouldWriteBigEndian_GivenBigEndian() public void WriteInt64_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420L, Endianness.BigEndian); stream.Write(420L, Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteInt64_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteInt64_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420L, Endianness.LittleEndian); stream.Write(420L, Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,27 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void WriteSingle_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteSingle_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0f, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0f, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420.0f, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420.0f, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteSingle_ShouldThrowArgumentNullException_GivenNullStream() public void WriteSingle_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0f, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0f, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420.0f, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420.0f, Endianness.BigEndian));
} }
[TestMethod] [Test]
public void WriteSingle_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteSingle_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
// we don't need to enclose this stream in a using declaration, since disposing a // we don't need to enclose this stream in a using declaration, since disposing a
@ -30,39 +30,39 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0f, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0f, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420.0f, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420.0f, (Endianness)(-1)));
} }
[TestMethod] [Test]
public void WriteSingle_ShouldWriteBigEndian_GivenBigEndian() public void WriteSingle_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0f, Endianness.BigEndian); stream.Write(420.0f, Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x43, 0xD2, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x43, 0xD2, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
public void WriteSingle_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteSingle_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420.0f, Endianness.LittleEndian); stream.Write(420.0f, Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0xD2, 0x43}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0xD2, 0x43};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt16_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteUInt16_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write((ushort)420, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write((ushort)420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write((ushort)420, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write((ushort)420, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt16_ShouldThrowArgumentNullException_GivenNullStream() public void WriteUInt16_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write((ushort)420, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write((ushort)420, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write((ushort)420, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write((ushort)420, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteUInt16_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -33,41 +33,41 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write((ushort)420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write((ushort)420, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write((ushort)420, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write((ushort)420, (Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt16_ShouldWriteBigEndian_GivenBigEndian() public void WriteUInt16_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write((ushort)420, Endianness.BigEndian); stream.Write((ushort)420, Endianness.BigEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(2, read); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt16_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteUInt16_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write((ushort)420, Endianness.LittleEndian); stream.Write((ushort)420, Endianness.LittleEndian);
Assert.AreEqual(2, stream.Position); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(2, read); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt32_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteUInt32_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420U, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420U, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420U, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420U, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt32_ShouldThrowArgumentNullException_GivenNullStream() public void WriteUInt32_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420U, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420U, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420U, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420U, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteUInt32_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -33,41 +33,41 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420U, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420U, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420U, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420U, (Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt32_ShouldWriteBigEndian_GivenBigEndian() public void WriteUInt32_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420U, Endianness.BigEndian); stream.Write(420U, Endianness.BigEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt32_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteUInt32_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420U, Endianness.LittleEndian); stream.Write(420U, Endianness.LittleEndian);
Assert.AreEqual(4, stream.Position); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(4, read); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,29 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt64_ShouldThrowArgumentException_GivenNonWriteableStream() public void WriteUInt64_ShouldThrowArgumentException_GivenNonWriteableStream()
{ {
Stream stream = new DummyStream(); Stream stream = new DummyStream();
Assert.ThrowsException<ArgumentException>(() => stream.Write(420UL, Endianness.LittleEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420UL, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentException>(() => stream.Write(420UL, Endianness.BigEndian)); Assert.Throws<ArgumentException>(() => stream.Write(420UL, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt64_ShouldThrowArgumentNullException_GivenNullStream() public void WriteUInt64_ShouldThrowArgumentNullException_GivenNullStream()
{ {
Stream stream = null!; Stream stream = null!;
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420UL, Endianness.LittleEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420UL, Endianness.LittleEndian));
Assert.ThrowsException<ArgumentNullException>(() => stream.Write(420UL, Endianness.BigEndian)); Assert.Throws<ArgumentNullException>(() => stream.Write(420UL, Endianness.BigEndian));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue() public void WriteUInt64_ShouldThrowArgumentOutOfRangeException_GivenInvalidEndiannessValue()
{ {
@ -33,41 +33,41 @@ public partial class StreamTests
// analyser to trip up and think the stream is disposed by the time the local is captured in // analyser to trip up and think the stream is disposed by the time the local is captured in
// assertion lambda - means this line is fine as it is. please do not change. // assertion lambda - means this line is fine as it is. please do not change.
Stream stream = Stream.Null; Stream stream = Stream.Null;
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420UL, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420UL, (Endianness)(-1)));
Assert.ThrowsException<ArgumentOutOfRangeException>(() => stream.Write(420UL, (Endianness)(-1))); Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(420UL, (Endianness)(-1)));
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt64_ShouldWriteBigEndian_GivenBigEndian() public void WriteUInt64_ShouldWriteBigEndian_GivenBigEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420UL, Endianness.BigEndian); stream.Write(420UL, Endianness.BigEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4}; ReadOnlySpan<byte> expected = stackalloc byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
[TestMethod] [Test]
[CLSCompliant(false)] [CLSCompliant(false)]
public void WriteUInt64_ShouldWriteLittleEndian_GivenLittleEndian() public void WriteUInt64_ShouldWriteLittleEndian_GivenLittleEndian()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
stream.Write(420UL, Endianness.LittleEndian); stream.Write(420UL, Endianness.LittleEndian);
Assert.AreEqual(8, stream.Position); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ReadOnlySpan<byte> expected = stackalloc byte[] {0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int read = stream.Read(actual); int read = stream.Read(actual);
Assert.AreEqual(8, read); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
} }
} }

View File

@ -1,15 +1,15 @@
using System.Diagnostics; using System.Diagnostics;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public partial class StreamTests public partial class StreamTests
{ {
[TestMethod] [Test]
public void GetHashSha1ShouldBeCorrect() public void GetHashSha1ShouldBeCorrect()
{ {
// SHA-1 // SHA-1
@ -29,15 +29,15 @@ public partial class StreamTests
CollectionAssert.AreEqual(expectedHash, hash); CollectionAssert.AreEqual(expectedHash, hash);
} }
[TestMethod] [Test]
public void GetHashNullShouldThrow() public void GetHashNullShouldThrow()
{ {
// any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here // any HashAlgorithm will do, but SHA1 is used above. so to remain consistent, we use it here
Assert.ThrowsException<ArgumentNullException>(() => ((Stream?)null)!.GetHash<SHA1>()); Assert.Throws<ArgumentNullException>(() => ((Stream?)null)!.GetHash<SHA1>());
Assert.ThrowsException<ArgumentNullException>(() => ((Stream?)null)!.TryWriteHash<SHA1>(Span<byte>.Empty, out _)); Assert.Throws<ArgumentNullException>(() => ((Stream?)null)!.TryWriteHash<SHA1>(Span<byte>.Empty, out _));
} }
[TestMethod] [Test]
public void TryWriteHashSha1_ShouldBeCorrect() public void TryWriteHashSha1_ShouldBeCorrect()
{ {
// SHA-1 // SHA-1
@ -53,49 +53,49 @@ public partial class StreamTests
Span<byte> hash = stackalloc byte[20]; Span<byte> hash = stackalloc byte[20];
stream.TryWriteHash<SHA1>(hash, out int bytesWritten); stream.TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.AreEqual(expectedHash.Length, bytesWritten); Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
CollectionAssert.AreEqual(expectedHash, hash.ToArray()); CollectionAssert.AreEqual(expectedHash, hash.ToArray());
} }
[TestMethod] [Test]
public void GetHash_TryWriteHash_ShouldThrow_GivenNonReadableStream() public void GetHash_TryWriteHash_ShouldThrow_GivenNonReadableStream()
{ {
Assert.ThrowsException<IOException>(() => Assert.Throws<IOException>(() =>
{ {
using var stream = new DummyStream(); using var stream = new DummyStream();
stream.GetHash<SHA1>(); stream.GetHash<SHA1>();
}); });
Assert.ThrowsException<IOException>(() => Assert.Throws<IOException>(() =>
{ {
using var stream = new DummyStream(); using var stream = new DummyStream();
stream.TryWriteHash<SHA1>(Span<byte>.Empty, out _); stream.TryWriteHash<SHA1>(Span<byte>.Empty, out _);
}); });
} }
[TestMethod] [Test]
public void LargeStreamShouldThrow() public void LargeStreamShouldThrow()
{ {
Assert.ThrowsException<ArgumentException>(() => Assert.Throws<ArgumentException>(() =>
{ {
using var stream = new DummyStream(true); using var stream = new DummyStream(true);
stream.TryWriteHash<SHA1>(Span<byte>.Empty, out _); stream.TryWriteHash<SHA1>(Span<byte>.Empty, out _);
}); });
} }
[TestMethod] [Test]
public void NullCreateMethodShouldThrow() public void NullCreateMethodShouldThrow()
{ {
Assert.ThrowsException<TypeInitializationException>(() => Stream.Null.GetHash<HashAlgorithmTestClass>()); Assert.Throws<TypeInitializationException>(() => Stream.Null.GetHash<HashAlgorithmTestClass>());
Assert.ThrowsException<TypeInitializationException>(() => Assert.Throws<TypeInitializationException>(() =>
Stream.Null.TryWriteHash<HashAlgorithmTestClass>(Span<byte>.Empty, out _)); Stream.Null.TryWriteHash<HashAlgorithmTestClass>(Span<byte>.Empty, out _));
} }
[TestMethod] [Test]
public void NoCreateMethodShouldThrow() public void NoCreateMethodShouldThrow()
{ {
Assert.ThrowsException<TypeInitializationException>(() => Stream.Null.GetHash<HashAlgorithmTestClassNoCreateMethod>()); Assert.Throws<TypeInitializationException>(() => Stream.Null.GetHash<HashAlgorithmTestClassNoCreateMethod>());
Assert.ThrowsException<TypeInitializationException>(() => Assert.Throws<TypeInitializationException>(() =>
Stream.Null.TryWriteHash<HashAlgorithmTestClassNoCreateMethod>(Span<byte>.Empty, out _)); Stream.Null.TryWriteHash<HashAlgorithmTestClassNoCreateMethod>(Span<byte>.Empty, out _));
} }

View File

@ -1,13 +1,13 @@
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
public class TextReaderTests public class TextReaderTests
{ {
[TestMethod] [Test]
public void EnumerateLines_ShouldYield10Lines_Given10LineString() public void EnumerateLines_ShouldYield10Lines_Given10LineString()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -28,10 +28,10 @@ public class TextReaderTests
lineCount++; lineCount++;
} }
Assert.AreEqual(10, lineCount); Assert.That(lineCount, Is.EqualTo(10));
} }
[TestMethod] [Test]
public async Task EnumerateLinesAsync_ShouldYield10Lines_Given10LineString() public async Task EnumerateLinesAsync_ShouldYield10Lines_Given10LineString()
{ {
using var stream = new MemoryStream(); using var stream = new MemoryStream();
@ -52,14 +52,14 @@ public class TextReaderTests
lineCount++; lineCount++;
} }
Assert.AreEqual(10, lineCount); Assert.That(lineCount, Is.EqualTo(10));
} }
[TestMethod] [Test]
public void EnumerateLines_ShouldThrowArgumentNullException_GivenNullSource() public void EnumerateLines_ShouldThrowArgumentNullException_GivenNullSource()
{ {
TextReader reader = null!; TextReader reader = null!;
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
foreach (string _ in reader.EnumerateLines()) foreach (string _ in reader.EnumerateLines())
{ {
@ -68,16 +68,16 @@ public class TextReaderTests
}); });
} }
[TestMethod] [Test]
public async Task EnumerateLinesAsync_ShouldThrowArgumentNullException_GivenNullSource() public void EnumerateLinesAsync_ShouldThrowArgumentNullException_GivenNullSource()
{ {
TextReader reader = null!; TextReader reader = null!;
await Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => Assert.ThrowsAsync<ArgumentNullException>(async () =>
{ {
await foreach (string _ in reader.EnumerateLinesAsync().ConfigureAwait(false)) await foreach (string _ in reader.EnumerateLinesAsync().ConfigureAwait(false))
{ {
// loop body is intentionally empty // loop body is intentionally empty
} }
}).ConfigureAwait(false); });
} }
} }

View File

@ -1,13 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt16Tests public class UInt16Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const ushort value = 0x0F; const ushort value = 0x0F;
@ -15,7 +15,7 @@ public class UInt16Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const ushort value = 0x0F; const ushort value = 0x0F;
@ -26,18 +26,18 @@ public class UInt16Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const ushort value = 0x0F; const ushort value = 0x0F;
byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0} : new byte[] {0, 0x0F}; byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0} : new byte[] {0, 0x0F};
Span<byte> buffer = stackalloc byte[2]; Span<byte> buffer = stackalloc byte[2];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const ushort value = 0x0F; const ushort value = 0x0F;
@ -46,18 +46,18 @@ public class UInt16Tests
Span<byte> buffer = stackalloc byte[2]; Span<byte> buffer = stackalloc byte[2];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const ushort value = 0x0F; const ushort value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,13 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt32Tests public class UInt32Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const uint value = 0x0F; const uint value = 0x0F;
@ -15,7 +15,7 @@ public class UInt32Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const uint value = 0x0F; const uint value = 0x0F;
@ -26,18 +26,18 @@ public class UInt32Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const uint value = 0x0F; const uint value = 0x0F;
byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0, 0, 0} : new byte[] {0, 0, 0, 0x0F}; byte[] bytes = BitConverter.IsLittleEndian ? new byte[] {0x0F, 0, 0, 0} : new byte[] {0, 0, 0, 0x0F};
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const uint value = 0x0F; const uint value = 0x0F;
@ -46,18 +46,18 @@ public class UInt32Tests
Span<byte> buffer = stackalloc byte[4]; Span<byte> buffer = stackalloc byte[4];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const uint value = 0x0F; const uint value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,13 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.IO; using X10D.IO;
namespace X10D.Tests.IO; namespace X10D.Tests.IO;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt64Tests public class UInt64Tests
{ {
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue() public void GetBytes_ReturnsCorrectValue()
{ {
const ulong value = 0x0F; const ulong value = 0x0F;
@ -17,7 +17,7 @@ public class UInt64Tests
CollectionAssert.AreEqual(bytes, value.GetBytes()); CollectionAssert.AreEqual(bytes, value.GetBytes());
} }
[TestMethod] [Test]
public void GetBytes_ReturnsCorrectValue_WithEndianness() public void GetBytes_ReturnsCorrectValue_WithEndianness()
{ {
const ulong value = 0x0F; const ulong value = 0x0F;
@ -28,7 +28,7 @@ public class UInt64Tests
CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian)); CollectionAssert.AreEqual(bigEndian, value.GetBytes(Endianness.BigEndian));
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
{ {
const ulong value = 0x0F; const ulong value = 0x0F;
@ -37,11 +37,11 @@ public class UInt64Tests
: new byte[] {0, 0, 0, 0, 0, 0, 0, 0x0F}; : new byte[] {0, 0, 0, 0, 0, 0, 0, 0x0F};
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(bytes, buffer.ToArray()); CollectionAssert.AreEqual(bytes, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness() public void TryWriteBytes_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan_WithEndianness()
{ {
const ulong value = 0x0F; const ulong value = 0x0F;
@ -50,18 +50,18 @@ public class UInt64Tests
Span<byte> buffer = stackalloc byte[8]; Span<byte> buffer = stackalloc byte[8];
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.LittleEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.LittleEndian));
CollectionAssert.AreEqual(littleEndian, buffer.ToArray()); CollectionAssert.AreEqual(littleEndian, buffer.ToArray());
Assert.IsTrue(value.TryWriteBytes(buffer, Endianness.BigEndian)); Assert.That(value.TryWriteBytes(buffer, Endianness.BigEndian));
CollectionAssert.AreEqual(bigEndian, buffer.ToArray()); CollectionAssert.AreEqual(bigEndian, buffer.ToArray());
} }
[TestMethod] [Test]
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
{ {
const ulong value = 0x0F; const ulong value = 0x0F;
Span<byte> buffer = stackalloc byte[0]; Span<byte> buffer = stackalloc byte[0];
Assert.IsFalse(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer), Is.False);
} }
} }

View File

@ -1,48 +1,48 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class ByteTests public class ByteTests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
byte Cast(int i) => (byte)i; byte Cast(int i) => (byte)i;
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.Zero);
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1));
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2));
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6));
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24));
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120));
// 6! will overflow for byte // 6! will overflow for byte
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
byte Double(int i) => (byte)(i * 2); byte Double(int i) => (byte)(i * 2);
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2));
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8));
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48));
// Π_(i=1)^n (2i) will overflow at i=4 for byte // Π_(i=1)^n (2i) will overflow at i=4 for byte
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<byte> source = null!; IEnumerable<byte> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
[TestMethod] [Test]
public void RangeTo_Byte_ShouldYieldCorrectValues() public void RangeTo_Byte_ShouldYieldCorrectValues()
{ {
const byte start = 1; const byte start = 1;
@ -51,13 +51,13 @@ public class ByteTests
byte current = 1; byte current = 1;
foreach (byte value in start.RangeTo(end)) foreach (byte value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
[TestMethod] [Test]
public void RangeTo_Int16_ShouldYieldCorrectValues() public void RangeTo_Int16_ShouldYieldCorrectValues()
{ {
const byte start = 1; const byte start = 1;
@ -66,13 +66,13 @@ public class ByteTests
short current = 1; short current = 1;
foreach (short value in start.RangeTo(end)) foreach (short value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
[TestMethod] [Test]
public void RangeTo_Int32_ShouldYieldCorrectValues() public void RangeTo_Int32_ShouldYieldCorrectValues()
{ {
const byte start = 1; const byte start = 1;
@ -81,13 +81,13 @@ public class ByteTests
int current = 1; int current = 1;
foreach (int value in start.RangeTo(end)) foreach (int value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
[TestMethod] [Test]
public void RangeTo_Int64_ShouldYieldCorrectValues() public void RangeTo_Int64_ShouldYieldCorrectValues()
{ {
const byte start = 1; const byte start = 1;
@ -96,9 +96,9 @@ public class ByteTests
long current = 1; long current = 1;
foreach (long value in start.RangeTo(end)) foreach (long value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
} }

View File

@ -1,52 +1,58 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class DecimalTests public class DecimalTests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
decimal Cast(int i) => i; decimal Cast(int i) => i;
Assert.AreEqual(0m, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.Multiple(() =>
Assert.AreEqual(1m, Enumerable.Range(1, 1).Select(Cast).Product()); {
Assert.AreEqual(2m, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0m));
Assert.AreEqual(6m, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1m));
Assert.AreEqual(24m, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2m));
Assert.AreEqual(120m, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6m));
Assert.AreEqual(720m, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24m));
Assert.AreEqual(5040m, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120m));
Assert.AreEqual(40320m, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720m));
Assert.AreEqual(362880m, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040m));
Assert.AreEqual(3628800m, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320m));
Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880m));
Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800m));
});
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
decimal Double(int i) => i * 2m; decimal Double(int i) => i * 2m;
Assert.AreEqual(0m, Enumerable.Range(0, 10).Product(Double)); Assert.Multiple(() =>
Assert.AreEqual(2m, Enumerable.Range(1, 1).Product(Double)); {
Assert.AreEqual(8m, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0m));
Assert.AreEqual(48m, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2m));
Assert.AreEqual(384m, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8m));
Assert.AreEqual(3840m, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48m));
Assert.AreEqual(46080m, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384m));
Assert.AreEqual(645120m, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840m));
Assert.AreEqual(10321920m, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080m));
Assert.AreEqual(185794560m, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120m));
Assert.AreEqual(3715891200m, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920m));
Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560m));
Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200m));
});
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<decimal> source = null!; IEnumerable<decimal> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,52 +1,58 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class DoubleTests public class DoubleTests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
double Cast(int i) => i; double Cast(int i) => i;
Assert.AreEqual(0.0, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.Multiple(() =>
Assert.AreEqual(1.0, Enumerable.Range(1, 1).Select(Cast).Product()); {
Assert.AreEqual(2.0, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0.0));
Assert.AreEqual(6.0, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1.0));
Assert.AreEqual(24.0, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2.0));
Assert.AreEqual(120.0, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6.0));
Assert.AreEqual(720.0, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24.0));
Assert.AreEqual(5040.0, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120.0));
Assert.AreEqual(40320.0, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720.0));
Assert.AreEqual(362880.0, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040.0));
Assert.AreEqual(3628800.0, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320.0));
Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880.0));
Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800.0));
});
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
double Double(int i) => i * 2.0; double Double(int i) => i * 2.0;
Assert.AreEqual(0.0, Enumerable.Range(0, 10).Product(Double)); Assert.Multiple(() =>
Assert.AreEqual(2.0, Enumerable.Range(1, 1).Product(Double)); {
Assert.AreEqual(8.0, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0.0));
Assert.AreEqual(48.0, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2.0));
Assert.AreEqual(384.0, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8.0));
Assert.AreEqual(3840.0, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48.0));
Assert.AreEqual(46080.0, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384.0));
Assert.AreEqual(645120.0, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840.0));
Assert.AreEqual(10321920.0, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080.0));
Assert.AreEqual(185794560.0, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120.0));
Assert.AreEqual(3715891200.0, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920.0));
Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560.0));
Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200.0));
});
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<double> source = null!; IEnumerable<double> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class EnumerableTests public class EnumerableTests
{ {
[TestMethod] [Test]
public void ConcatOne_ShouldReturnConcatenatedSequence_GivenValidSequenceAndValue() public void ConcatOne_ShouldReturnConcatenatedSequence_GivenValidSequenceAndValue()
{ {
IEnumerable<string> source = new[] {"Hello"}; IEnumerable<string> source = new[] {"Hello"};
@ -14,11 +14,11 @@ public class EnumerableTests
string[] actual = source.ConcatOne("World").ToArray(); string[] actual = source.ConcatOne("World").ToArray();
Assert.AreEqual(2, actual.Length); Assert.That(actual, Has.Length.EqualTo(2));
CollectionAssert.AreEqual(expected, actual); CollectionAssert.AreEqual(expected, actual);
} }
[TestMethod] [Test]
public void ConcatOne_ShouldReturnSingletonSequence_GivenEmptySequenceAndValidValue() public void ConcatOne_ShouldReturnSingletonSequence_GivenEmptySequenceAndValidValue()
{ {
IEnumerable<string> source = Enumerable.Empty<string>(); IEnumerable<string> source = Enumerable.Empty<string>();
@ -26,159 +26,195 @@ public class EnumerableTests
string[] actual = source.ConcatOne("Foobar").ToArray(); string[] actual = source.ConcatOne("Foobar").ToArray();
Assert.AreEqual(1, actual.Length); Assert.That(actual, Has.Length.EqualTo(1));
CollectionAssert.AreEqual(expected, actual); CollectionAssert.AreEqual(expected, actual);
} }
[TestMethod] [Test]
public void ConcatOne_ShouldThrowArgumentNullException_GivenNullSource() public void ConcatOne_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<string>? source = null; IEnumerable<string>? source = null;
Assert.ThrowsException<ArgumentNullException>(() => source!.ConcatOne("Foobar").ToArray()); Assert.Throws<ArgumentNullException>(() => source!.ConcatOne("Foobar").ToArray());
} }
[TestMethod] [Test]
public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer() public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer()
{ {
IEnumerable<int> source = Enumerable.Range(1, 10); IEnumerable<int> source = Enumerable.Range(1, 10);
(int minimum, int maximum) = source.MinMax(); (int minimum, int maximum) = source.MinMax();
Assert.AreEqual(1, minimum); Assert.Multiple(() =>
Assert.AreEqual(10, maximum); {
Assert.That(minimum, Is.EqualTo(1));
Assert.That(maximum, Is.EqualTo(10));
});
source = Enumerable.Range(1, 10).ToArray(); source = Enumerable.Range(1, 10).ToArray();
(minimum, maximum) = source.MinMax(); (minimum, maximum) = source.MinMax();
Assert.AreEqual(1, minimum); Assert.Multiple(() =>
Assert.AreEqual(10, maximum); {
Assert.That(minimum, Is.EqualTo(1));
Assert.That(maximum, Is.EqualTo(10));
});
} }
[TestMethod] [Test]
public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer()
{ {
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
(int minimum, int maximum) = source.MinMax(p => p.Age); (int minimum, int maximum) = source.MinMax(p => p.Age);
Assert.AreEqual(1, minimum); Assert.Multiple(() =>
Assert.AreEqual(10, maximum); {
Assert.That(minimum, Is.EqualTo(1));
Assert.That(maximum, Is.EqualTo(10));
});
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
(minimum, maximum) = source.MinMax(p => p.Age); (minimum, maximum) = source.MinMax(p => p.Age);
Assert.AreEqual(1, minimum); Assert.Multiple(() =>
Assert.AreEqual(10, maximum); {
Assert.That(minimum, Is.EqualTo(1));
Assert.That(maximum, Is.EqualTo(10));
});
} }
[TestMethod] [Test]
public void MinMax_ShouldReturnOppositeSelectedValues_UsingInverseComparer() public void MinMax_ShouldReturnOppositeSelectedValues_UsingInverseComparer()
{ {
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
(int minimum, int maximum) = source.MinMax(p => p.Age, new InverseComparer<int>()); (int minimum, int maximum) = source.MinMax(p => p.Age, new InverseComparer<int>());
Assert.AreEqual(10, minimum); Assert.Multiple(() =>
Assert.AreEqual(1, maximum); {
Assert.That(minimum, Is.EqualTo(10));
Assert.That(maximum, Is.EqualTo(1));
});
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
(minimum, maximum) = source.MinMax(p => p.Age, new InverseComparer<int>()); (minimum, maximum) = source.MinMax(p => p.Age, new InverseComparer<int>());
Assert.AreEqual(10, minimum); Assert.Multiple(() =>
Assert.AreEqual(1, maximum); {
Assert.That(minimum, Is.EqualTo(10));
Assert.That(maximum, Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void MinMax_ShouldReturnOppositeValues_UsingInverseComparer() public void MinMax_ShouldReturnOppositeValues_UsingInverseComparer()
{ {
(int minimum, int maximum) = Enumerable.Range(1, 10).MinMax(new InverseComparer<int>()); (int minimum, int maximum) = Enumerable.Range(1, 10).MinMax(new InverseComparer<int>());
Assert.AreEqual(10, minimum); Assert.Multiple(() =>
Assert.AreEqual(1, maximum); {
Assert.That(minimum, Is.EqualTo(10));
Assert.That(maximum, Is.EqualTo(1));
});
(minimum, maximum) = Enumerable.Range(1, 10).ToArray().MinMax(new InverseComparer<int>()); (minimum, maximum) = Enumerable.Range(1, 10).ToArray().MinMax(new InverseComparer<int>());
Assert.AreEqual(10, minimum); Assert.Multiple(() =>
Assert.AreEqual(1, maximum); {
Assert.That(minimum, Is.EqualTo(10));
Assert.That(maximum, Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector() public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector()
{ {
IEnumerable<int> source = Enumerable.Empty<int>(); IEnumerable<int> source = Enumerable.Empty<int>();
Assert.ThrowsException<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!))); Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!)));
Assert.ThrowsException<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!), null)); Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!), null));
} }
[TestMethod] [Test]
public void MinMax_ShouldThrowArgumentNullException_GivenNullSource() public void MinMax_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<int>? source = null; IEnumerable<int>? source = null;
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax()); Assert.Throws<ArgumentNullException>(() => source!.MinMax());
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(v => v)); Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v));
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(null)); Assert.Throws<ArgumentNullException>(() => source!.MinMax(null));
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(v => v, null)); Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v, null));
} }
[TestMethod] [Test]
public void MinMax_ShouldThrowInvalidOperationException_GivenEmptySource() public void MinMax_ShouldThrowInvalidOperationException_GivenEmptySource()
{ {
Assert.ThrowsException<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax()); Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax());
Assert.ThrowsException<InvalidOperationException>(() => Array.Empty<int>().MinMax()); Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax());
Assert.ThrowsException<InvalidOperationException>(() => new List<int>().MinMax()); Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax());
Assert.ThrowsException<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax(i => i * 2)); Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax(i => i * 2));
Assert.ThrowsException<InvalidOperationException>(() => Array.Empty<int>().MinMax(i => i * 2)); Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax(i => i * 2));
Assert.ThrowsException<InvalidOperationException>(() => new List<int>().MinMax(i => i * 2)); Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax(i => i * 2));
} }
[TestMethod] [Test]
public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer()
{ {
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
(Person minimum, Person maximum) = source.MinMaxBy(p => p.Age); (Person minimum, Person maximum) = source.MinMaxBy(p => p.Age);
Assert.AreEqual(1, minimum.Age); Assert.Multiple(() =>
Assert.AreEqual(10, maximum.Age); {
Assert.That(minimum.Age, Is.EqualTo(1));
Assert.That(maximum.Age, Is.EqualTo(10));
});
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
(minimum, maximum) = source.MinMaxBy(p => p.Age); (minimum, maximum) = source.MinMaxBy(p => p.Age);
Assert.AreEqual(1, minimum.Age); Assert.Multiple(() =>
Assert.AreEqual(10, maximum.Age); {
Assert.That(minimum.Age, Is.EqualTo(1));
Assert.That(maximum.Age, Is.EqualTo(10));
});
} }
[TestMethod] [Test]
public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer() public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer()
{ {
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
(Person minimum, Person maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>()); (Person minimum, Person maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>());
Assert.AreEqual(10, minimum.Age); Assert.Multiple(() =>
Assert.AreEqual(1, maximum.Age); {
Assert.That(minimum.Age, Is.EqualTo(10));
Assert.That(maximum.Age, Is.EqualTo(1));
});
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
(minimum, maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>()); (minimum, maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>());
Assert.AreEqual(10, minimum.Age); Assert.Multiple(() =>
Assert.AreEqual(1, maximum.Age); {
Assert.That(minimum.Age, Is.EqualTo(10));
Assert.That(maximum.Age, Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSelector() public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSelector()
{ {
Person[] source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); Person[] source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
Assert.ThrowsException<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!)); Assert.Throws<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!));
Assert.ThrowsException<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!, null)); Assert.Throws<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!, null));
} }
[TestMethod] [Test]
public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSource() public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<Person>? source = null; IEnumerable<Person>? source = null;
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age)); Assert.Throws<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age));
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age, null)); Assert.Throws<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age, null));
} }
[TestMethod] [Test]
public void MinMaxBy_ShouldThrowInvalidOperationException_GivenEmptySource() public void MinMaxBy_ShouldThrowInvalidOperationException_GivenEmptySource()
{ {
Assert.ThrowsException<InvalidOperationException>(() => Assert.Throws<InvalidOperationException>(() =>
{ {
IEnumerable<Person> source = Enumerable.Empty<Person>(); IEnumerable<Person> source = Enumerable.Empty<Person>();
return source.MinMaxBy(p => p.Age); _ = source.MinMaxBy(p => p.Age);
}); });
Assert.ThrowsException<InvalidOperationException>(() => Assert.Throws<InvalidOperationException>(() =>
{ {
Person[] source = Array.Empty<Person>(); Person[] source = Array.Empty<Person>();
return source.MinMaxBy(p => p.Age); _ = source.MinMaxBy(p => p.Age);
}); });
} }

View File

@ -1,92 +1,95 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class Int16Tests public class Int16Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
short Cast(int i) => (short)i; short Cast(int i) => (short)i;
Assert.Multiple(() =>
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product()); {
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1));
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2));
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6));
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24));
Assert.AreEqual(720, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120));
Assert.AreEqual(5040, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720));
Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040));
// 8! will overflow for short });
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
short Double(int i) => (short)(i * 2); short Double(int i) => (short)(i * 2);
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2));
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8));
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48));
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384));
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840));
// Π_(i=1)^n (2i) will overflow at i=6 for short // Π_(i=1)^n (2i) will overflow at i=6 for short
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<short> source = null!; IEnumerable<short> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
} }
[TestMethod] [Test]
public void RangeTo_Int16_ShouldYieldCorrectValues() public void RangeTo_Int16_ShouldYieldCorrectValues()
{ {
const short start = 1; const short start = 1;
const short end = 10; const short end = 10;
short current = 1; short current = 1;
foreach (short value in start.RangeTo(end)) foreach (short value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(current, Is.EqualTo(end));
} }
[TestMethod] [Test]
public void RangeTo_Int32_ShouldYieldCorrectValues() public void RangeTo_Int32_ShouldYieldCorrectValues()
{ {
const short start = 1; const short start = 1;
const int end = 10; const int end = 10;
int current = 1; var current = 1;
foreach (int value in start.RangeTo(end)) foreach (int value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(current, Is.EqualTo(end));
} }
[TestMethod] [Test]
public void RangeTo_Int64_ShouldYieldCorrectValues() public void RangeTo_Int64_ShouldYieldCorrectValues()
{ {
const short start = 1; const short start = 1;
const long end = 10; const long end = 10;
long current = 1; long current = 1;
foreach (long value in start.RangeTo(end)) foreach (long value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(current, Is.EqualTo(end));
} }
} }

View File

@ -1,55 +1,55 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class Int32Tests public class Int32Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
Assert.AreEqual(0, Enumerable.Range(0, 10).Product()); Assert.That(Enumerable.Range(0, 10).Product(), Is.Zero);
Assert.AreEqual(1, Enumerable.Range(1, 1).Product()); Assert.That(Enumerable.Range(1, 1).Product(), Is.EqualTo(1));
Assert.AreEqual(2, Enumerable.Range(1, 2).Product()); Assert.That(Enumerable.Range(1, 2).Product(), Is.EqualTo(2));
Assert.AreEqual(6, Enumerable.Range(1, 3).Product()); Assert.That(Enumerable.Range(1, 3).Product(), Is.EqualTo(6));
Assert.AreEqual(24, Enumerable.Range(1, 4).Product()); Assert.That(Enumerable.Range(1, 4).Product(), Is.EqualTo(24));
Assert.AreEqual(120, Enumerable.Range(1, 5).Product()); Assert.That(Enumerable.Range(1, 5).Product(), Is.EqualTo(120));
Assert.AreEqual(720, Enumerable.Range(1, 6).Product()); Assert.That(Enumerable.Range(1, 6).Product(), Is.EqualTo(720));
Assert.AreEqual(5040, Enumerable.Range(1, 7).Product()); Assert.That(Enumerable.Range(1, 7).Product(), Is.EqualTo(5040));
Assert.AreEqual(40320, Enumerable.Range(1, 8).Product()); Assert.That(Enumerable.Range(1, 8).Product(), Is.EqualTo(40320));
Assert.AreEqual(362880, Enumerable.Range(1, 9).Product()); Assert.That(Enumerable.Range(1, 9).Product(), Is.EqualTo(362880));
Assert.AreEqual(3628800, Enumerable.Range(1, 10).Product()); Assert.That(Enumerable.Range(1, 10).Product(), Is.EqualTo(3628800));
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
int Double(int i) => i * 2; int Double(int i) => i * 2;
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2));
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8));
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48));
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384));
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840));
Assert.AreEqual(46080, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080));
Assert.AreEqual(645120, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120));
Assert.AreEqual(10321920, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920));
Assert.AreEqual(185794560, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560));
// Π_(i=1)^n (2i) will overflow at i=10 for int // Π_(i=1)^n (2i) will overflow at i=10 for int
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<int> source = null!; IEnumerable<int> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
[TestMethod] [Test]
public void RangeTo_Int32_ShouldYieldCorrectValues() public void RangeTo_Int32_ShouldYieldCorrectValues()
{ {
const int start = 1; const int start = 1;
@ -58,13 +58,13 @@ public class Int32Tests
int current = 1; int current = 1;
foreach (int value in start.RangeTo(end)) foreach (int value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
[TestMethod] [Test]
public void RangeTo_Int64_ShouldYieldCorrectValues() public void RangeTo_Int64_ShouldYieldCorrectValues()
{ {
const int start = 1; const int start = 1;
@ -73,9 +73,9 @@ public class Int32Tests
long current = 1; long current = 1;
foreach (long value in start.RangeTo(end)) foreach (long value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
} }

View File

@ -1,56 +1,56 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class Int64Tests public class Int64Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
long Cast(int i) => i; long Cast(int i) => i;
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.Zero);
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1));
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2));
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6));
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24));
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120));
Assert.AreEqual(720, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720));
Assert.AreEqual(5040, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040));
Assert.AreEqual(40320, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320));
Assert.AreEqual(362880, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880));
Assert.AreEqual(3628800, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800));
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
long Double(int i) => i * 2; long Double(int i) => i * 2;
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2));
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8));
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48));
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384));
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840));
Assert.AreEqual(46080, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080));
Assert.AreEqual(645120, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120));
Assert.AreEqual(10321920, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920));
Assert.AreEqual(185794560, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560));
Assert.AreEqual(3715891200, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200));
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<long> source = null!; IEnumerable<long> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
[TestMethod] [Test]
public void RangeTo_Int64_ShouldYieldCorrectValues() public void RangeTo_Int64_ShouldYieldCorrectValues()
{ {
const long start = 1; const long start = 1;
@ -59,9 +59,9 @@ public class Int64Tests
long current = 1; long current = 1;
foreach (long value in start.RangeTo(end)) foreach (long value in start.RangeTo(end))
{ {
Assert.AreEqual(current++, value); Assert.That(value, Is.EqualTo(current++));
} }
Assert.AreEqual(current, end); Assert.That(end, Is.EqualTo(current));
} }
} }

View File

@ -1,82 +1,82 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class ReadOnlySpanTests public class ReadOnlySpanTests
{ {
[TestMethod] [Test]
public void AllShouldReturnTrueForEmptySpan() public void AllShouldReturnTrueForEmptySpan()
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
Assert.IsTrue(span.All(x => x > 0)); Assert.That(span.All(x => x > 0));
} }
[TestMethod] [Test]
public void AllShouldBeCorrect() public void AllShouldBeCorrect()
{ {
var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10}); var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.All(x => x % 2 == 0)); Assert.That(span.All(x => x % 2 == 0));
Assert.IsFalse(span.All(x => x % 2 == 1)); Assert.That(span.All(x => x % 2 == 1), Is.False);
} }
[TestMethod] [Test]
public void AnyShouldReturnFalseForEmptySpan() public void AnyShouldReturnFalseForEmptySpan()
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
Assert.IsFalse(span.Any(x => x > 0)); Assert.That(span.Any(x => x > 0), Is.False);
} }
[TestMethod] [Test]
public void AnyShouldBeCorrect() public void AnyShouldBeCorrect()
{ {
var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10}); var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.Any(x => x % 2 == 0)); Assert.That(span.Any(x => x % 2 == 0));
Assert.IsFalse(span.Any(x => x % 2 == 1)); Assert.That(span.Any(x => x % 2 == 1), Is.False);
} }
[TestMethod] [Test]
public void AllNullPredicateShouldThrow() public void AllNullPredicateShouldThrow()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
return span.All(null!); _ = span.All(null!);
}); });
} }
[TestMethod] [Test]
public void AnyNullPredicateShouldThrow() public void AnyNullPredicateShouldThrow()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
return span.Any(null!); _ = span.Any(null!);
}); });
} }
[TestMethod] [Test]
public void Count_ShouldReturn0_GivenEmptySpan() public void Count_ShouldReturn0_GivenEmptySpan()
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
Assert.AreEqual(0, span.Count(i => i % 2 == 0)); Assert.That(span.Count(i => i % 2 == 0), Is.Zero);
} }
[TestMethod] [Test]
public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10() public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10()
{ {
var span = new ReadOnlySpan<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); var span = new ReadOnlySpan<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
Assert.AreEqual(5, span.Count(i => i % 2 == 0)); Assert.That(span.Count(i => i % 2 == 0), Is.EqualTo(5));
} }
[TestMethod] [Test]
public void Count_ShouldThrow_GivenNullPredicate() public void Count_ShouldThrow_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new ReadOnlySpan<int>(); var span = new ReadOnlySpan<int>();
return span.Count(null!); _ = span.Count(null!);
}); });
} }
} }

View File

@ -1,45 +1,45 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class SByteTests public class SByteTests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
sbyte Cast(int i) => (sbyte)i; sbyte Cast(int i) => (sbyte)i;
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.Zero);
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1));
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2));
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6));
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24));
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120));
// 6! will overflow for sbyte // 6! will overflow for sbyte
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
sbyte Double(int i) => (sbyte)(i * 2); sbyte Double(int i) => (sbyte)(i * 2);
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.Zero);
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2));
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8));
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48));
// Π_(i=1)^(n(i*2)) will overflow at i=4 for sbyte // Π_(i=1)^(n(i*2)) will overflow at i=4 for sbyte
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<sbyte> source = null!; IEnumerable<sbyte> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,52 +1,52 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class SingleTests public class SingleTests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
float Cast(int i) => i; float Cast(int i) => i;
Assert.AreEqual(0f, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0f));
Assert.AreEqual(1f, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1f));
Assert.AreEqual(2f, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2f));
Assert.AreEqual(6f, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6f));
Assert.AreEqual(24f, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24f));
Assert.AreEqual(120f, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120f));
Assert.AreEqual(720f, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720f));
Assert.AreEqual(5040f, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040f));
Assert.AreEqual(40320f, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320f));
Assert.AreEqual(362880f, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880f));
Assert.AreEqual(3628800f, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800f));
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
float Double(int i) => i * 2f; float Double(int i) => i * 2f;
Assert.AreEqual(0f, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0f));
Assert.AreEqual(2f, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2f));
Assert.AreEqual(8f, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8f));
Assert.AreEqual(48f, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48f));
Assert.AreEqual(384f, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384f));
Assert.AreEqual(3840f, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840f));
Assert.AreEqual(46080f, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080f));
Assert.AreEqual(645120f, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120f));
Assert.AreEqual(10321920f, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920f));
Assert.AreEqual(185794560f, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560f));
Assert.AreEqual(3715891200f, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200f));
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<float> source = null!; IEnumerable<float> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,82 +1,82 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
public class SpanTests public class SpanTests
{ {
[TestMethod] [Test]
public void AllShouldReturnTrueForEmptySpan() public void AllShouldReturnTrueForEmptySpan()
{ {
var span = new Span<int>(); var span = new Span<int>();
Assert.IsTrue(span.All(x => x > 0)); Assert.That(span.All(x => x > 0));
} }
[TestMethod] [Test]
public void AllShouldBeCorrect() public void AllShouldBeCorrect()
{ {
var span = new Span<int>(new[] {2, 4, 6, 8, 10}); var span = new Span<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.All(x => x % 2 == 0)); Assert.That(span.All(x => x % 2 == 0));
Assert.IsFalse(span.All(x => x % 2 == 1)); Assert.That(span.All(x => x % 2 == 1), Is.False);
} }
[TestMethod] [Test]
public void AnyShouldReturnFalseForEmptySpan() public void AnyShouldReturnFalseForEmptySpan()
{ {
var span = new Span<int>(); var span = new Span<int>();
Assert.IsFalse(span.Any(x => x > 0)); Assert.That(span.Any(x => x > 0), Is.False);
} }
[TestMethod] [Test]
public void AnyShouldBeCorrect() public void AnyShouldBeCorrect()
{ {
var span = new Span<int>(new[] {2, 4, 6, 8, 10}); var span = new Span<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.Any(x => x % 2 == 0)); Assert.That(span.Any(x => x % 2 == 0));
Assert.IsFalse(span.Any(x => x % 2 == 1)); Assert.That(span.Any(x => x % 2 == 1), Is.False);
} }
[TestMethod] [Test]
public void AllNullPredicateShouldThrow() public void AllNullPredicateShouldThrow()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new Span<int>(); var span = new Span<int>();
return span.All(null!); _ = span.All(null!);
}); });
} }
[TestMethod] [Test]
public void AnyNullPredicateShouldThrow() public void AnyNullPredicateShouldThrow()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new Span<int>(); var span = new Span<int>();
return span.Any(null!); _ = span.Any(null!);
}); });
} }
[TestMethod] [Test]
public void Count_ShouldReturn0_GivenEmptySpan() public void Count_ShouldReturn0_GivenEmptySpan()
{ {
var span = new Span<int>(); var span = new Span<int>();
Assert.AreEqual(0, span.Count(i => i % 2 == 0)); Assert.That(span.Count(i => i % 2 == 0), Is.Zero);
} }
[TestMethod] [Test]
public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10() public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10()
{ {
var span = new Span<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); var span = new Span<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
Assert.AreEqual(5, span.Count(i => i % 2 == 0)); Assert.That(span.Count(i => i % 2 == 0), Is.EqualTo(5));
} }
[TestMethod] [Test]
public void Count_ShouldThrow_GivenNullPredicate() public void Count_ShouldThrow_GivenNullPredicate()
{ {
Assert.ThrowsException<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
var span = new Span<int>(); var span = new Span<int>();
return span.Count(null!); _ = span.Count(null!);
}); });
} }
} }

View File

@ -1,51 +1,51 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt16Tests public class UInt16Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
ushort Cast(int i) => (ushort)i; ushort Cast(int i) => (ushort)i;
Assert.AreEqual(0U, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0U));
Assert.AreEqual(1U, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1U));
Assert.AreEqual(2U, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2U));
Assert.AreEqual(6U, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6U));
Assert.AreEqual(24U, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24U));
Assert.AreEqual(120U, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120U));
Assert.AreEqual(720U, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720U));
Assert.AreEqual(5040U, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040U));
Assert.AreEqual(40320U, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320U));
// 9! will overflow for ushort // 9! will overflow for ushort
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
ushort Double(int i) => (ushort)(i * 2); ushort Double(int i) => (ushort)(i * 2);
Assert.AreEqual(0U, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0U));
Assert.AreEqual(2U, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2U));
Assert.AreEqual(8U, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8U));
Assert.AreEqual(48U, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48U));
Assert.AreEqual(384U, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384U));
Assert.AreEqual(3840U, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840U));
Assert.AreEqual(46080U, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080U));
// Π_(i=1)^n (2i) will overflow at i=7 for ushort // Π_(i=1)^n (2i) will overflow at i=7 for ushort
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<ushort> source = null!; IEnumerable<ushort> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,53 +1,53 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt32Tests public class UInt32Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
ulong Cast(int i) => (ulong)i; ulong Cast(int i) => (ulong)i;
Assert.AreEqual(0U, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0U));
Assert.AreEqual(1U, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1U));
Assert.AreEqual(2U, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2U));
Assert.AreEqual(6U, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6U));
Assert.AreEqual(24U, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24U));
Assert.AreEqual(120U, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120U));
Assert.AreEqual(720U, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720U));
Assert.AreEqual(5040U, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040U));
Assert.AreEqual(40320U, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320U));
Assert.AreEqual(362880U, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880U));
Assert.AreEqual(3628800U, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800U));
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
uint Double(int i) => (uint)i * 2; uint Double(int i) => (uint)i * 2;
Assert.AreEqual(0U, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0U));
Assert.AreEqual(2U, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2U));
Assert.AreEqual(8U, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8U));
Assert.AreEqual(48U, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48U));
Assert.AreEqual(384U, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384U));
Assert.AreEqual(3840U, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840U));
Assert.AreEqual(46080U, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080U));
Assert.AreEqual(645120U, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120U));
Assert.AreEqual(10321920U, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920U));
Assert.AreEqual(185794560U, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560U));
Assert.AreEqual(3715891200U, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200U));
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<uint> source = null!; IEnumerable<uint> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,53 +1,53 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Linq; using X10D.Linq;
namespace X10D.Tests.Linq; namespace X10D.Tests.Linq;
[TestClass] [TestFixture]
[CLSCompliant(false)] [CLSCompliant(false)]
public class UInt64Tests public class UInt64Tests
{ {
[TestMethod] [Test]
public void ProductShouldBeCorrect() public void ProductShouldBeCorrect()
{ {
ulong Cast(int i) => (ulong)i; ulong Cast(int i) => (ulong)i;
Assert.AreEqual(0UL, Enumerable.Range(0, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(0, 10).Select(Cast).Product(), Is.EqualTo(0UL));
Assert.AreEqual(1UL, Enumerable.Range(1, 1).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 1).Select(Cast).Product(), Is.EqualTo(1UL));
Assert.AreEqual(2UL, Enumerable.Range(1, 2).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 2).Select(Cast).Product(), Is.EqualTo(2UL));
Assert.AreEqual(6UL, Enumerable.Range(1, 3).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 3).Select(Cast).Product(), Is.EqualTo(6UL));
Assert.AreEqual(24UL, Enumerable.Range(1, 4).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 4).Select(Cast).Product(), Is.EqualTo(24UL));
Assert.AreEqual(120UL, Enumerable.Range(1, 5).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 5).Select(Cast).Product(), Is.EqualTo(120UL));
Assert.AreEqual(720UL, Enumerable.Range(1, 6).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 6).Select(Cast).Product(), Is.EqualTo(720UL));
Assert.AreEqual(5040UL, Enumerable.Range(1, 7).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 7).Select(Cast).Product(), Is.EqualTo(5040UL));
Assert.AreEqual(40320UL, Enumerable.Range(1, 8).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 8).Select(Cast).Product(), Is.EqualTo(40320UL));
Assert.AreEqual(362880UL, Enumerable.Range(1, 9).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 9).Select(Cast).Product(), Is.EqualTo(362880UL));
Assert.AreEqual(3628800UL, Enumerable.Range(1, 10).Select(Cast).Product()); Assert.That(Enumerable.Range(1, 10).Select(Cast).Product(), Is.EqualTo(3628800UL));
} }
[TestMethod] [Test]
public void ProductOfDoublesShouldBeCorrect() public void ProductOfDoublesShouldBeCorrect()
{ {
ulong Double(int i) => (ulong)i * 2; ulong Double(int i) => (ulong)i * 2;
Assert.AreEqual(0UL, Enumerable.Range(0, 10).Product(Double)); Assert.That(Enumerable.Range(0, 10).Product(Double), Is.EqualTo(0UL));
Assert.AreEqual(2UL, Enumerable.Range(1, 1).Product(Double)); Assert.That(Enumerable.Range(1, 1).Product(Double), Is.EqualTo(2UL));
Assert.AreEqual(8UL, Enumerable.Range(1, 2).Product(Double)); Assert.That(Enumerable.Range(1, 2).Product(Double), Is.EqualTo(8UL));
Assert.AreEqual(48UL, Enumerable.Range(1, 3).Product(Double)); Assert.That(Enumerable.Range(1, 3).Product(Double), Is.EqualTo(48UL));
Assert.AreEqual(384UL, Enumerable.Range(1, 4).Product(Double)); Assert.That(Enumerable.Range(1, 4).Product(Double), Is.EqualTo(384UL));
Assert.AreEqual(3840UL, Enumerable.Range(1, 5).Product(Double)); Assert.That(Enumerable.Range(1, 5).Product(Double), Is.EqualTo(3840UL));
Assert.AreEqual(46080UL, Enumerable.Range(1, 6).Product(Double)); Assert.That(Enumerable.Range(1, 6).Product(Double), Is.EqualTo(46080UL));
Assert.AreEqual(645120UL, Enumerable.Range(1, 7).Product(Double)); Assert.That(Enumerable.Range(1, 7).Product(Double), Is.EqualTo(645120UL));
Assert.AreEqual(10321920UL, Enumerable.Range(1, 8).Product(Double)); Assert.That(Enumerable.Range(1, 8).Product(Double), Is.EqualTo(10321920UL));
Assert.AreEqual(185794560UL, Enumerable.Range(1, 9).Product(Double)); Assert.That(Enumerable.Range(1, 9).Product(Double), Is.EqualTo(185794560UL));
Assert.AreEqual(3715891200UL, Enumerable.Range(1, 10).Product(Double)); Assert.That(Enumerable.Range(1, 10).Product(Double), Is.EqualTo(3715891200UL));
} }
[TestMethod] [Test]
public void Product_ShouldThrowArgumentNullException_GivenNullSource() public void Product_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<ulong> source = null!; IEnumerable<ulong> source = null!;
Assert.ThrowsException<ArgumentNullException>(() => source.Product()); Assert.Throws<ArgumentNullException>(() => source.Product());
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v)); Assert.Throws<ArgumentNullException>(() => source.Product(v => v));
} }
} }

View File

@ -1,15 +1,15 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
public partial class BigIntegerTests public partial class BigIntegerTests
{ {
[TestClass] [TestFixture]
public class WrapTests public class WrapTests
{ {
[TestMethod] [Test]
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow() public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
{ {
BigInteger value = 10; BigInteger value = 10;
@ -18,10 +18,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(low, high); BigInteger result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh() public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
{ {
BigInteger value = 20; BigInteger value = 20;
@ -30,10 +30,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(low, high); BigInteger result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
{ {
BigInteger value = 30; BigInteger value = 30;
@ -42,10 +42,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(low, high); BigInteger result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow() public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
{ {
BigInteger value = 5; BigInteger value = 5;
@ -54,10 +54,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(low, high); BigInteger result = value.Wrap(low, high);
Assert.AreEqual(15L, result); Assert.That(result, Is.EqualTo((BigInteger)15));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
{ {
BigInteger value = 15; BigInteger value = 15;
@ -66,10 +66,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(low, high); BigInteger result = value.Wrap(low, high);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength() public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
{ {
BigInteger value = 10; BigInteger value = 10;
@ -77,10 +77,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(length); BigInteger result = value.Wrap(length);
Assert.AreEqual(0L, result); Assert.That(result, Is.EqualTo((BigInteger)0));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength() public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
{ {
BigInteger value = 5; BigInteger value = 5;
@ -88,10 +88,10 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(length); BigInteger result = value.Wrap(length);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
{ {
BigInteger value = 15; BigInteger value = 15;
@ -99,7 +99,7 @@ public partial class BigIntegerTests
BigInteger result = value.Wrap(length); BigInteger result = value.Wrap(length);
Assert.AreEqual(5L, result); Assert.That(result, Is.EqualTo((BigInteger)5));
} }
} }
} }

View File

@ -1,69 +1,74 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
[TestClass] [TestFixture]
public partial class BigIntegerTests public partial class BigIntegerTests
{ {
[TestMethod] [Test]
public void DigitalRootShouldBeCorrect() public void DigitalRootShouldBeCorrect()
{ {
BigInteger value = 238; BigInteger value = 238;
Assert.AreEqual(4, value.DigitalRoot()); Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.AreEqual(4, (-value).DigitalRoot()); Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
} }
[TestMethod] [Test]
public void FactorialShouldBeCorrect() public void FactorialShouldBeCorrect()
{ {
Assert.AreEqual(1, ((BigInteger)0).Factorial()); Assert.Multiple(() =>
Assert.AreEqual(1, ((BigInteger)1).Factorial()); {
Assert.AreEqual(2, ((BigInteger)2).Factorial()); Assert.That(((BigInteger)0).Factorial(), Is.EqualTo((BigInteger)1));
Assert.AreEqual(6, ((BigInteger)3).Factorial()); Assert.That(((BigInteger)1).Factorial(), Is.EqualTo((BigInteger)1));
Assert.AreEqual(24, ((BigInteger)4).Factorial()); Assert.That(((BigInteger)2).Factorial(), Is.EqualTo((BigInteger)2));
Assert.AreEqual(120, ((BigInteger)5).Factorial()); Assert.That(((BigInteger)3).Factorial(), Is.EqualTo((BigInteger)6));
Assert.AreEqual(720, ((BigInteger)6).Factorial()); Assert.That(((BigInteger)4).Factorial(), Is.EqualTo((BigInteger)24));
Assert.AreEqual(5040, ((BigInteger)7).Factorial()); Assert.That(((BigInteger)5).Factorial(), Is.EqualTo((BigInteger)120));
Assert.AreEqual(40320, ((BigInteger)8).Factorial()); Assert.That(((BigInteger)6).Factorial(), Is.EqualTo((BigInteger)720));
Assert.AreEqual(362880, ((BigInteger)9).Factorial()); Assert.That(((BigInteger)7).Factorial(), Is.EqualTo((BigInteger)5040));
Assert.AreEqual(3628800, ((BigInteger)10).Factorial()); Assert.That(((BigInteger)8).Factorial(), Is.EqualTo((BigInteger)40320));
Assert.That(((BigInteger)9).Factorial(), Is.EqualTo((BigInteger)362880));
Assert.That(((BigInteger)10).Factorial(), Is.EqualTo((BigInteger)3628800));
});
} }
[TestMethod] [Test]
public void GreatestCommonFactor_ShouldBe1_ForPrimeNumbers() public void GreatestCommonFactor_ShouldBe1_ForPrimeNumbers()
{ {
BigInteger first = 5L; BigInteger first = 5;
BigInteger second = 7L; BigInteger second = 7;
BigInteger multiple = first.GreatestCommonFactor(second); BigInteger multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(1L, multiple); Assert.That(multiple, Is.EqualTo((BigInteger)1));
} }
[TestMethod] [Test]
public void GreatestCommonFactor_ShouldBe6_Given12And18() public void GreatestCommonFactor_ShouldBe6_Given12And18()
{ {
BigInteger first = 12L; BigInteger first = 12;
BigInteger second = 18L; BigInteger second = 18;
BigInteger multiple = first.GreatestCommonFactor(second); BigInteger multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(6L, multiple); Assert.That(multiple, Is.EqualTo((BigInteger)6));
} }
[TestMethod] [Test]
public void IsOddShouldBeCorrect() public void IsOddShouldBeCorrect()
{ {
BigInteger one = 1; BigInteger one = 1;
BigInteger two = 2; BigInteger two = 2;
Assert.Multiple(() =>
Assert.IsTrue(one.IsOdd()); {
Assert.IsFalse(two.IsOdd()); Assert.That(one.IsOdd());
Assert.That(two.IsOdd(), Is.False);
});
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithValidInput() public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithValidInput()
{ {
BigInteger value1 = 2; BigInteger value1 = 2;
@ -72,10 +77,10 @@ public partial class BigIntegerTests
BigInteger result = value1.LowestCommonMultiple(value2); BigInteger result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnZero_WhenCalledWithZero() public void LowestCommonMultiple_ShouldReturnZero_WhenCalledWithZero()
{ {
BigInteger value1 = 0; BigInteger value1 = 0;
@ -84,10 +89,10 @@ public partial class BigIntegerTests
BigInteger result = value1.LowestCommonMultiple(value2); BigInteger result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnGreaterValue_WhenCalledWithOne() public void LowestCommonMultiple_ShouldReturnGreaterValue_WhenCalledWithOne()
{ {
BigInteger value1 = 1; BigInteger value1 = 1;
@ -97,11 +102,11 @@ public partial class BigIntegerTests
BigInteger result1 = value1.LowestCommonMultiple(value2); BigInteger result1 = value1.LowestCommonMultiple(value2);
BigInteger result2 = value2.LowestCommonMultiple(value1); BigInteger result2 = value2.LowestCommonMultiple(value1);
Assert.AreEqual(expected, result1); Assert.That(result1, Is.EqualTo(expected));
Assert.AreEqual(expected, result2); Assert.That(result2, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnOtherValue_WhenCalledWithSameValue() public void LowestCommonMultiple_ShouldReturnOtherValue_WhenCalledWithSameValue()
{ {
BigInteger value1 = 5; BigInteger value1 = 5;
@ -110,10 +115,10 @@ public partial class BigIntegerTests
BigInteger result = value1.LowestCommonMultiple(value2); BigInteger result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithNegativeValues() public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithNegativeValues()
{ {
BigInteger value1 = -2; BigInteger value1 = -2;
@ -122,38 +127,44 @@ public partial class BigIntegerTests
BigInteger result = value1.LowestCommonMultiple(value2); BigInteger result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplicativePersistence_ShouldReturn1_ForAnyDigitBeing0() public void MultiplicativePersistence_ShouldReturn1_ForAnyDigitBeing0()
{ {
Assert.AreEqual(1, ((BigInteger)10).MultiplicativePersistence()); Assert.Multiple(() =>
Assert.AreEqual(1, ((BigInteger)201).MultiplicativePersistence()); {
Assert.AreEqual(1, ((BigInteger)200).MultiplicativePersistence()); Assert.That(((BigInteger)10).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(1, ((BigInteger)20007).MultiplicativePersistence()); Assert.That(((BigInteger)201).MultiplicativePersistence(), Is.EqualTo(1));
Assert.That(((BigInteger)200).MultiplicativePersistence(), Is.EqualTo(1));
Assert.That(((BigInteger)20007).MultiplicativePersistence(), Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void MultiplicativePersistence_ShouldBeCorrect_ForRecordHolders() public void MultiplicativePersistence_ShouldBeCorrect_ForRecordHolders()
{ {
Assert.AreEqual(0, ((BigInteger)0).MultiplicativePersistence()); Assert.Multiple(() =>
Assert.AreEqual(1, ((BigInteger)10).MultiplicativePersistence()); {
Assert.AreEqual(2, ((BigInteger)25).MultiplicativePersistence()); Assert.That(((BigInteger)0).MultiplicativePersistence(), Is.Zero);
Assert.AreEqual(3, ((BigInteger)39).MultiplicativePersistence()); Assert.That(((BigInteger)10).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(4, ((BigInteger)77).MultiplicativePersistence()); Assert.That(((BigInteger)25).MultiplicativePersistence(), Is.EqualTo(2));
Assert.AreEqual(5, ((BigInteger)679).MultiplicativePersistence()); Assert.That(((BigInteger)39).MultiplicativePersistence(), Is.EqualTo(3));
Assert.AreEqual(6, ((BigInteger)6788).MultiplicativePersistence()); Assert.That(((BigInteger)77).MultiplicativePersistence(), Is.EqualTo(4));
Assert.AreEqual(7, ((BigInteger)68889).MultiplicativePersistence()); Assert.That(((BigInteger)679).MultiplicativePersistence(), Is.EqualTo(5));
Assert.AreEqual(8, ((BigInteger)2677889).MultiplicativePersistence()); Assert.That(((BigInteger)6788).MultiplicativePersistence(), Is.EqualTo(6));
Assert.AreEqual(9, ((BigInteger)26888999).MultiplicativePersistence()); Assert.That(((BigInteger)68889).MultiplicativePersistence(), Is.EqualTo(7));
Assert.AreEqual(10, ((BigInteger)3778888999).MultiplicativePersistence()); Assert.That(((BigInteger)2677889).MultiplicativePersistence(), Is.EqualTo(8));
Assert.AreEqual(11, ((BigInteger)277777788888899).MultiplicativePersistence()); Assert.That(((BigInteger)26888999).MultiplicativePersistence(), Is.EqualTo(9));
Assert.That(((BigInteger)3778888999).MultiplicativePersistence(), Is.EqualTo(10));
Assert.That(((BigInteger)277777788888899).MultiplicativePersistence(), Is.EqualTo(11));
});
} }
[TestMethod] [Test]
public void NegativeFactorialShouldThrow() public void NegativeFactorialShouldThrow()
{ {
Assert.ThrowsException<ArithmeticException>(() => ((BigInteger)(-1)).Factorial()); Assert.Throws<ArithmeticException>(() => _ = ((BigInteger)(-1)).Factorial());
} }
} }

View File

@ -1,14 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
public partial class ByteTests public partial class ByteTests
{ {
[TestClass] [TestFixture]
public class WrapTests public class WrapTests
{ {
[TestMethod] [Test]
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow() public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
{ {
const byte value = 10; const byte value = 10;
@ -17,10 +17,10 @@ public partial class ByteTests
byte result = value.Wrap(low, high); byte result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh() public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
{ {
const byte value = 20; const byte value = 20;
@ -29,10 +29,10 @@ public partial class ByteTests
byte result = value.Wrap(low, high); byte result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
{ {
const byte value = 30; const byte value = 30;
@ -41,10 +41,10 @@ public partial class ByteTests
byte result = value.Wrap(low, high); byte result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow() public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
{ {
const byte value = 5; const byte value = 5;
@ -53,10 +53,10 @@ public partial class ByteTests
byte result = value.Wrap(low, high); byte result = value.Wrap(low, high);
Assert.AreEqual(11, result); Assert.That(result, Is.EqualTo(11));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
{ {
const byte value = 15; const byte value = 15;
@ -65,10 +65,10 @@ public partial class ByteTests
byte result = value.Wrap(low, high); byte result = value.Wrap(low, high);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength() public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
{ {
const byte value = 10; const byte value = 10;
@ -76,10 +76,10 @@ public partial class ByteTests
byte result = value.Wrap(length); byte result = value.Wrap(length);
Assert.AreEqual(0, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength() public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
{ {
const byte value = 5; const byte value = 5;
@ -87,10 +87,10 @@ public partial class ByteTests
byte result = value.Wrap(length); byte result = value.Wrap(length);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
{ {
const byte value = 15; const byte value = 15;
@ -98,7 +98,7 @@ public partial class ByteTests
byte result = value.Wrap(length); byte result = value.Wrap(length);
Assert.AreEqual(5, result); Assert.That(result, Is.EqualTo(5));
} }
} }
} }

View File

@ -1,36 +1,36 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
[TestClass] [TestFixture]
public partial class ByteTests public partial class ByteTests
{ {
[TestMethod] [Test]
public void DigitalRootShouldBeCorrect() public void DigitalRootShouldBeCorrect()
{ {
const byte value = 238; const byte value = 238;
Assert.AreEqual(4, value.DigitalRoot()); Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.AreEqual(4, (-value).DigitalRoot()); Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
} }
[TestMethod] [Test]
public void FactorialShouldBeCorrect() public void FactorialShouldBeCorrect()
{ {
Assert.AreEqual(1L, ((byte)0).Factorial()); Assert.That(((byte)0).Factorial(), Is.EqualTo(1L));
Assert.AreEqual(1L, ((byte)1).Factorial()); Assert.That(((byte)1).Factorial(), Is.EqualTo(1L));
Assert.AreEqual(2L, ((byte)2).Factorial()); Assert.That(((byte)2).Factorial(), Is.EqualTo(2L));
Assert.AreEqual(6L, ((byte)3).Factorial()); Assert.That(((byte)3).Factorial(), Is.EqualTo(6L));
Assert.AreEqual(24L, ((byte)4).Factorial()); Assert.That(((byte)4).Factorial(), Is.EqualTo(24L));
Assert.AreEqual(120L, ((byte)5).Factorial()); Assert.That(((byte)5).Factorial(), Is.EqualTo(120L));
Assert.AreEqual(720L, ((byte)6).Factorial()); Assert.That(((byte)6).Factorial(), Is.EqualTo(720L));
Assert.AreEqual(5040L, ((byte)7).Factorial()); Assert.That(((byte)7).Factorial(), Is.EqualTo(5040L));
Assert.AreEqual(40320L, ((byte)8).Factorial()); Assert.That(((byte)8).Factorial(), Is.EqualTo(40320L));
Assert.AreEqual(362880L, ((byte)9).Factorial()); Assert.That(((byte)9).Factorial(), Is.EqualTo(362880L));
Assert.AreEqual(3628800L, ((byte)10).Factorial()); Assert.That(((byte)10).Factorial(), Is.EqualTo(3628800L));
} }
[TestMethod] [Test]
public void GreatestCommonFactor_ShouldBe1_ForPrimeNumbers() public void GreatestCommonFactor_ShouldBe1_ForPrimeNumbers()
{ {
const byte first = 5; const byte first = 5;
@ -38,10 +38,10 @@ public partial class ByteTests
byte multiple = first.GreatestCommonFactor(second); byte multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(1, multiple); Assert.That(multiple, Is.EqualTo(1));
} }
[TestMethod] [Test]
public void GreatestCommonFactor_ShouldBe6_Given12And18() public void GreatestCommonFactor_ShouldBe6_Given12And18()
{ {
const byte first = 12; const byte first = 12;
@ -49,30 +49,30 @@ public partial class ByteTests
byte multiple = first.GreatestCommonFactor(second); byte multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(6, multiple); Assert.That(multiple, Is.EqualTo(6));
} }
[TestMethod] [Test]
public void IsEvenShouldBeCorrect() public void IsEvenShouldBeCorrect()
{ {
const byte one = 1; const byte one = 1;
const byte two = 2; const byte two = 2;
Assert.IsFalse(one.IsEven()); Assert.That(one.IsEven(), Is.False);
Assert.IsTrue(two.IsEven()); Assert.That(two.IsEven());
} }
[TestMethod] [Test]
public void IsOddShouldBeCorrect() public void IsOddShouldBeCorrect()
{ {
const byte one = 1; const byte one = 1;
const byte two = 2; const byte two = 2;
Assert.IsTrue(one.IsOdd()); Assert.That(one.IsOdd());
Assert.IsFalse(two.IsOdd()); Assert.That(two.IsOdd(), Is.False);
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithValidInput() public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithValidInput()
{ {
const byte value1 = 2; const byte value1 = 2;
@ -81,10 +81,10 @@ public partial class ByteTests
byte result = value1.LowestCommonMultiple(value2); byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnZero_WhenCalledWithZero() public void LowestCommonMultiple_ShouldReturnZero_WhenCalledWithZero()
{ {
const byte value1 = 0; const byte value1 = 0;
@ -93,10 +93,10 @@ public partial class ByteTests
byte result = value1.LowestCommonMultiple(value2); byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnGreaterValue_WhenCalledWithOne() public void LowestCommonMultiple_ShouldReturnGreaterValue_WhenCalledWithOne()
{ {
const byte value1 = 1; const byte value1 = 1;
@ -106,11 +106,11 @@ public partial class ByteTests
byte result1 = value1.LowestCommonMultiple(value2); byte result1 = value1.LowestCommonMultiple(value2);
byte result2 = value2.LowestCommonMultiple(value1); byte result2 = value2.LowestCommonMultiple(value1);
Assert.AreEqual(expected, result1); Assert.That(result1, Is.EqualTo(expected));
Assert.AreEqual(expected, result2); Assert.That(result2, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void LowestCommonMultiple_ShouldReturnOtherValue_WhenCalledWithSameValue() public void LowestCommonMultiple_ShouldReturnOtherValue_WhenCalledWithSameValue()
{ {
const byte value1 = 5; const byte value1 = 5;
@ -119,25 +119,25 @@ public partial class ByteTests
byte result = value1.LowestCommonMultiple(value2); byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result); Assert.That(result, Is.EqualTo(expected));
} }
[TestMethod] [Test]
public void MultiplicativePersistence_ShouldReturn1_ForAnyDigitBeing0() public void MultiplicativePersistence_ShouldReturn1_ForAnyDigitBeing0()
{ {
Assert.AreEqual(1, ((byte)10).MultiplicativePersistence()); Assert.That(((byte)10).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(1, ((byte)201).MultiplicativePersistence()); Assert.That(((byte)201).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(1, ((byte)200).MultiplicativePersistence()); Assert.That(((byte)200).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(1, ((byte)207).MultiplicativePersistence()); Assert.That(((byte)207).MultiplicativePersistence(), Is.EqualTo(1));
} }
[TestMethod] [Test]
public void MultiplicativePersistence_ShouldBeCorrect_ForRecordHolders() public void MultiplicativePersistence_ShouldBeCorrect_ForRecordHolders()
{ {
Assert.AreEqual(0, ((byte)0).MultiplicativePersistence()); Assert.That(((byte)0).MultiplicativePersistence(), Is.Zero);
Assert.AreEqual(1, ((byte)10).MultiplicativePersistence()); Assert.That(((byte)10).MultiplicativePersistence(), Is.EqualTo(1));
Assert.AreEqual(2, ((byte)25).MultiplicativePersistence()); Assert.That(((byte)25).MultiplicativePersistence(), Is.EqualTo(2));
Assert.AreEqual(3, ((byte)39).MultiplicativePersistence()); Assert.That(((byte)39).MultiplicativePersistence(), Is.EqualTo(3));
Assert.AreEqual(4, ((byte)77).MultiplicativePersistence()); Assert.That(((byte)77).MultiplicativePersistence(), Is.EqualTo(4));
} }
} }

View File

@ -1,9 +1,9 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
[TestClass] [TestFixture]
public class ComparableTests public class ComparableTests
{ {
private class ComparableTestClass : IComparable<ComparableTestClass> private class ComparableTestClass : IComparable<ComparableTestClass>
@ -18,191 +18,191 @@ public class ComparableTests
private readonly int _upper = 10; private readonly int _upper = 10;
private readonly int _value = 5; private readonly int _value = 5;
[TestMethod] [Test]
public void Between_5_1_10_ShouldBeTrue() public void Between_5_1_10_ShouldBeTrue()
{ {
Assert.IsTrue(_value.Between(_lower, _upper)); Assert.That(_value.Between(_lower, _upper));
} }
[TestMethod] [Test]
public void Between_1_1_10_ShouldBeFalse() public void Between_1_1_10_ShouldBeFalse()
{ {
// default option is exclusive // default option is exclusive
Assert.IsFalse(_lower.Between(_lower, _upper)); Assert.That(_lower.Between(_lower, _upper), Is.False);
} }
[TestMethod] [Test]
public void Between_1_1_10_Inclusive_ShouldBeTrue() public void Between_1_1_10_Inclusive_ShouldBeTrue()
{ {
Assert.IsTrue(_lower.Between(_lower, _upper, InclusiveOptions.Inclusive)); Assert.That(_lower.Between(_lower, _upper, InclusiveOptions.Inclusive));
Assert.IsTrue(_lower.Between(_lower, _upper, InclusiveOptions.LowerInclusive)); Assert.That(_lower.Between(_lower, _upper, InclusiveOptions.LowerInclusive));
Assert.IsFalse(_lower.Between(_lower, _upper, InclusiveOptions.UpperInclusive)); Assert.That(_lower.Between(_lower, _upper, InclusiveOptions.UpperInclusive), Is.False);
} }
[TestMethod] [Test]
public void Between_10_1_10_ShouldBeFalse() public void Between_10_1_10_ShouldBeFalse()
{ {
// default option is exclusive // default option is exclusive
Assert.IsFalse(_upper.Between(_lower, _upper)); Assert.That(_upper.Between(_lower, _upper), Is.False);
} }
[TestMethod] [Test]
public void Between_10_1_10_Inclusive_ShouldBeTrue() public void Between_10_1_10_Inclusive_ShouldBeTrue()
{ {
Assert.IsTrue(_upper.Between(_lower, _upper, InclusiveOptions.Inclusive)); Assert.That(_upper.Between(_lower, _upper, InclusiveOptions.Inclusive));
Assert.IsTrue(_upper.Between(_lower, _upper, InclusiveOptions.UpperInclusive)); Assert.That(_upper.Between(_lower, _upper, InclusiveOptions.UpperInclusive));
Assert.IsFalse(_upper.Between(_lower, _upper, InclusiveOptions.LowerInclusive)); Assert.That(_upper.Between(_lower, _upper, InclusiveOptions.LowerInclusive), Is.False);
} }
[TestMethod] [Test]
public void Between_1_10_5_ShouldThrow() public void Between_1_10_5_ShouldThrow()
{ {
Assert.ThrowsException<ArgumentException>(() => _lower.Between(_upper, _value)); Assert.Throws<ArgumentException>(() => _lower.Between(_upper, _value));
} }
[TestMethod] [Test]
public void Between_Null_ShouldThrow() public void Between_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => ((ComparableTestClass?)null)!.Between(nullPointer!, nullPointer!)); Assert.Throws<ArgumentNullException>(() => ((ComparableTestClass?)null)!.Between(nullPointer!, nullPointer!));
} }
[TestMethod] [Test]
public void Clamp_3_1_5_ShouldBe3() public void Clamp_3_1_5_ShouldBe3()
{ {
Assert.AreEqual(3, 3.Clamp(1, 5)); Assert.That(3.Clamp(1, 5), Is.EqualTo(3));
} }
[TestMethod] [Test]
public void Clamp_10_1_5_ShouldBe5() public void Clamp_10_1_5_ShouldBe5()
{ {
Assert.AreEqual(5, 10.Clamp(1, 5)); Assert.That(10.Clamp(1, 5), Is.EqualTo(5));
} }
[TestMethod] [Test]
public void Clamp_n_6_5_ShouldThrow() public void Clamp_n_6_5_ShouldThrow()
{ {
Assert.ThrowsException<ArgumentException>(() => 0.Clamp(6, 5)); Assert.Throws<ArgumentException>(() => 0.Clamp(6, 5));
} }
[TestMethod] [Test]
public void Clamp_ShouldThrowArgumentNullException_GivenNullValue() public void Clamp_ShouldThrowArgumentNullException_GivenNullValue()
{ {
string comparable = null!; string comparable = null!;
Assert.ThrowsException<ArgumentNullException>(() => comparable.Clamp(string.Empty, string.Empty)); Assert.Throws<ArgumentNullException>(() => comparable.Clamp(string.Empty, string.Empty));
} }
[TestMethod] [Test]
public void GreaterThan_5_6_ShouldBeFalse() public void GreaterThan_5_6_ShouldBeFalse()
{ {
Assert.IsFalse(5.GreaterThan(6)); Assert.That(5.GreaterThan(6), Is.False);
} }
[TestMethod] [Test]
public void GreaterThan_6_5_ShouldBeTrue() public void GreaterThan_6_5_ShouldBeTrue()
{ {
Assert.IsTrue(6.GreaterThan(5)); Assert.That(6.GreaterThan(5));
} }
[TestMethod] [Test]
public void GreaterThan_5_5_ShouldBeFalse() public void GreaterThan_5_5_ShouldBeFalse()
{ {
Assert.IsFalse(5.LessThan(5)); Assert.That(5.LessThan(5), Is.False);
} }
[TestMethod] [Test]
public void GreaterThan_Null_ShouldThrow() public void GreaterThan_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.GreaterThan(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.GreaterThan(nullPointer!));
} }
[TestMethod] [Test]
public void GreaterThanOrEqualTo_5_5_ShouldBeTrue() public void GreaterThanOrEqualTo_5_5_ShouldBeTrue()
{ {
Assert.IsTrue(5.GreaterThanOrEqualTo(5)); Assert.That(5.GreaterThanOrEqualTo(5));
} }
[TestMethod] [Test]
public void GreaterThanOrEqualTo_6_5_ShouldBeTrue() public void GreaterThanOrEqualTo_6_5_ShouldBeTrue()
{ {
Assert.IsTrue(6.GreaterThanOrEqualTo(5)); Assert.That(6.GreaterThanOrEqualTo(5));
} }
[TestMethod] [Test]
public void GreaterThanOrEqualTo_5_6_ShouldBeFalse() public void GreaterThanOrEqualTo_5_6_ShouldBeFalse()
{ {
Assert.IsFalse(5.GreaterThanOrEqualTo(6)); Assert.That(5.GreaterThanOrEqualTo(6), Is.False);
} }
[TestMethod] [Test]
public void GreaterThanOrEqualTo_Null_ShouldThrow() public void GreaterThanOrEqualTo_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.GreaterThanOrEqualTo(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.GreaterThanOrEqualTo(nullPointer!));
} }
[TestMethod] [Test]
public void LessThan_Null_ShouldThrow() public void LessThan_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.LessThan(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.LessThan(nullPointer!));
} }
[TestMethod] [Test]
public void LessThan_6_5_ShouldBeFalse() public void LessThan_6_5_ShouldBeFalse()
{ {
Assert.IsFalse(6.LessThan(5)); Assert.That(6.LessThan(5), Is.False);
} }
[TestMethod] [Test]
public void LessThan_5_6_ShouldBeTrue() public void LessThan_5_6_ShouldBeTrue()
{ {
Assert.IsTrue(5.LessThan(6)); Assert.That(5.LessThan(6));
} }
[TestMethod] [Test]
public void LessThan_5_5_ShouldBeFalse() public void LessThan_5_5_ShouldBeFalse()
{ {
Assert.IsFalse(5.LessThan(5)); Assert.That(5.LessThan(5), Is.False);
} }
[TestMethod] [Test]
public void LessThanOrEqualTo_5_5_ShouldBeTrue() public void LessThanOrEqualTo_5_5_ShouldBeTrue()
{ {
Assert.IsTrue(5.LessThanOrEqualTo(5)); Assert.That(5.LessThanOrEqualTo(5));
} }
[TestMethod] [Test]
public void LessThanOrEqualTo_5_6_ShouldBeTrue() public void LessThanOrEqualTo_5_6_ShouldBeTrue()
{ {
Assert.IsTrue(5.LessThanOrEqualTo(6)); Assert.That(5.LessThanOrEqualTo(6));
} }
[TestMethod] [Test]
public void LessThanOrEqualTo_6_5_ShouldBeFalse() public void LessThanOrEqualTo_6_5_ShouldBeFalse()
{ {
Assert.IsFalse(6.LessThanOrEqualTo(5)); Assert.That(6.LessThanOrEqualTo(5), Is.False);
} }
[TestMethod] [Test]
public void LessThanOrEqualTo_Null_ShouldThrow() public void LessThanOrEqualTo_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.LessThanOrEqualTo(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.LessThanOrEqualTo(nullPointer!));
} }
[TestMethod] [Test]
public void Max_Null_ShouldThrow() public void Max_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.Max(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.Max(nullPointer!));
} }
[TestMethod] [Test]
public void Min_Null_ShouldThrow() public void Min_Null_ShouldThrow()
{ {
ComparableTestClass? nullPointer = null; ComparableTestClass? nullPointer = null;
Assert.ThrowsException<ArgumentNullException>(() => nullPointer!.Min(nullPointer!)); Assert.Throws<ArgumentNullException>(() => nullPointer!.Min(nullPointer!));
} }
} }

View File

@ -1,14 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
public partial class DecimalTests public partial class DecimalTests
{ {
[TestClass] [TestFixture]
public class WrapTests public class WrapTests
{ {
[TestMethod] [Test]
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow() public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
{ {
const decimal value = 10; const decimal value = 10;
@ -17,10 +17,10 @@ public partial class DecimalTests
decimal result = value.Wrap(low, high); decimal result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh() public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
{ {
const decimal value = 20; const decimal value = 20;
@ -29,10 +29,10 @@ public partial class DecimalTests
decimal result = value.Wrap(low, high); decimal result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
{ {
const decimal value = 30; const decimal value = 30;
@ -41,10 +41,10 @@ public partial class DecimalTests
decimal result = value.Wrap(low, high); decimal result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow() public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
{ {
const decimal value = 5; const decimal value = 5;
@ -53,10 +53,10 @@ public partial class DecimalTests
decimal result = value.Wrap(low, high); decimal result = value.Wrap(low, high);
Assert.AreEqual(15.0m, result); Assert.That(result, Is.EqualTo(15.0m));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
{ {
const decimal value = 15; const decimal value = 15;
@ -65,10 +65,10 @@ public partial class DecimalTests
decimal result = value.Wrap(low, high); decimal result = value.Wrap(low, high);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength() public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
{ {
const decimal value = 10; const decimal value = 10;
@ -76,10 +76,10 @@ public partial class DecimalTests
decimal result = value.Wrap(length); decimal result = value.Wrap(length);
Assert.AreEqual(0.0m, result); Assert.That(result, Is.EqualTo(0.0m));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength() public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
{ {
const decimal value = 5; const decimal value = 5;
@ -87,10 +87,10 @@ public partial class DecimalTests
decimal result = value.Wrap(length); decimal result = value.Wrap(length);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
{ {
const decimal value = 15; const decimal value = 15;
@ -98,7 +98,7 @@ public partial class DecimalTests
decimal result = value.Wrap(length); decimal result = value.Wrap(length);
Assert.AreEqual(5.0m, result); Assert.That(result, Is.EqualTo(5.0m));
} }
} }
} }

View File

@ -1,140 +1,173 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
[TestClass] [TestFixture]
public partial class DecimalTests public partial class DecimalTests
{ {
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeCorrect_GivenReal() public void ComplexSqrt_ShouldBeCorrect_GivenReal()
{ {
Assert.AreEqual(0.0, 0.0m.ComplexSqrt()); Assert.Multiple(() =>
Assert.AreEqual(1.4142135623730951, 2.0m.ComplexSqrt()); {
Assert.AreEqual(3.0, 9.0m.ComplexSqrt()); Assert.That(0.0m.ComplexSqrt(), Is.EqualTo((Complex)0.0));
Assert.AreEqual(4.0, 16.0m.ComplexSqrt()); Assert.That(2.0m.ComplexSqrt(), Is.EqualTo((Complex)1.4142135623730951));
Assert.AreEqual(100.0, 10000.0m.ComplexSqrt()); Assert.That(9.0m.ComplexSqrt(), Is.EqualTo((Complex)3.0));
Assert.That(16.0m.ComplexSqrt(), Is.EqualTo((Complex)4.0));
Assert.That(10000.0m.ComplexSqrt(), Is.EqualTo((Complex)100.0));
});
} }
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeImaginary_GivenNegativeValue() public void ComplexSqrt_ShouldBeImaginary_GivenNegativeValue()
{ {
Assert.AreEqual(new Complex(0, 1), (-1.0m).ComplexSqrt()); Assert.Multiple(() =>
Assert.AreEqual(new Complex(0, 1.4142135623730951), (-2.0m).ComplexSqrt()); {
Assert.AreEqual(new Complex(0, 3.0), (-9.0m).ComplexSqrt()); Assert.That((-1.0m).ComplexSqrt(), Is.EqualTo(new Complex(0, 1)));
Assert.AreEqual(new Complex(0, 4.0), (-16.0m).ComplexSqrt()); Assert.That((-2.0m).ComplexSqrt(), Is.EqualTo(new Complex(0, 1.4142135623730951)));
Assert.That((-9.0m).ComplexSqrt(), Is.EqualTo(new Complex(0, 3.0)));
Assert.That((-16.0m).ComplexSqrt(), Is.EqualTo(new Complex(0, 4.0)));
});
} }
[TestMethod] [Test]
public void IsEven_ShouldBeFalse_GivenOddNumber() public void IsEven_ShouldBeFalse_GivenOddNumber()
{ {
Assert.IsFalse((-3.0m).IsEven()); Assert.Multiple(() =>
Assert.IsFalse((-1.0m).IsEven()); {
Assert.IsFalse(1.0m.IsEven()); Assert.That((-3.0m).IsEven(), Is.False);
Assert.IsFalse(3.0m.IsEven()); Assert.That((-1.0m).IsEven(), Is.False);
Assert.That(1.0m.IsEven(), Is.False);
Assert.That(3.0m.IsEven(), Is.False);
});
} }
[TestMethod] [Test]
public void IsEven_ShouldBeTrue_GivenOddNumber() public void IsEven_ShouldBeTrue_GivenOddNumber()
{ {
Assert.IsTrue((-4.0m).IsEven()); Assert.Multiple(() =>
Assert.IsTrue((-2.0m).IsEven()); {
Assert.IsTrue(0.0m.IsEven()); Assert.That((-4.0m).IsEven());
Assert.IsTrue(2.0m.IsEven()); Assert.That((-2.0m).IsEven());
Assert.IsTrue(4.0m.IsEven()); Assert.That(0.0m.IsEven());
Assert.That(2.0m.IsEven());
Assert.That(4.0m.IsEven());
});
} }
[TestMethod] [Test]
public void IsOdd_ShouldBeFalse_GivenEvenNumber() public void IsOdd_ShouldBeFalse_GivenEvenNumber()
{ {
Assert.IsFalse((-4.0m).IsOdd()); Assert.Multiple(() =>
Assert.IsFalse((-2.0m).IsOdd()); {
Assert.IsFalse(0.0m.IsOdd()); Assert.That((-4.0m).IsOdd(), Is.False);
Assert.IsFalse(2.0m.IsOdd()); Assert.That((-2.0m).IsOdd(), Is.False);
Assert.IsFalse(4.0m.IsOdd()); Assert.That(0.0m.IsOdd(), Is.False);
Assert.That(2.0m.IsOdd(), Is.False);
Assert.That(4.0m.IsOdd(), Is.False);
});
} }
[TestMethod] [Test]
public void IsOdd_ShouldBeTrue_GivenOddNumber() public void IsOdd_ShouldBeTrue_GivenOddNumber()
{ {
Assert.IsTrue((-3.0m).IsOdd()); Assert.Multiple(() =>
Assert.IsTrue((-1.0m).IsOdd()); {
Assert.IsTrue(1.0m.IsOdd()); Assert.That((-3.0m).IsOdd());
Assert.IsTrue(3.0m.IsOdd()); Assert.That((-1.0m).IsOdd());
Assert.That(1.0m.IsOdd());
Assert.That(3.0m.IsOdd());
});
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearestInteger() public void Round_ShouldRoundToNearestInteger()
{ {
Assert.AreEqual(4.0m, 3.5m.Round()); Assert.Multiple(() =>
Assert.AreEqual(7.0m, 6.8m.Round()); {
Assert.AreEqual(7.0m, 7.2m.Round()); Assert.That(3.5m.Round(), Is.EqualTo(4.0m));
Assert.That(6.8m.Round(), Is.EqualTo(7.0m));
Assert.That(7.2m.Round(), Is.EqualTo(7.0m));
});
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearestMultiple() public void Round_ShouldRoundToNearestMultiple()
{ {
Assert.AreEqual(5.0m, 3.5m.Round(5)); Assert.Multiple(() =>
Assert.AreEqual(5.0m, 7.0m.Round(5)); {
Assert.AreEqual(10.0m, 7.5m.Round(5)); Assert.That(3.5m.Round(5), Is.EqualTo(5.0m));
Assert.That(7.0m.Round(5), Is.EqualTo(5.0m));
Assert.That(7.5m.Round(5), Is.EqualTo(10.0m));
});
} }
[TestMethod] [Test]
public void Saturate_ShouldClampValueTo1_GivenGreaterThan1() public void Saturate_ShouldClampValueTo1_GivenGreaterThan1()
{ {
Assert.AreEqual(1.0m, 1.5m.Saturate(), 1e-6m); Assert.That(1.5m.Saturate(), Is.EqualTo(1.0m));
} }
[TestMethod] [Test]
public void Saturate_ShouldClampValueTo0_GivenLessThan0() public void Saturate_ShouldClampValueTo0_GivenLessThan0()
{ {
Assert.AreEqual(0.0m, (-0.5m).Saturate(), 1e-6m); Assert.That((-0.5m).Saturate(), Is.EqualTo(0.0m));
} }
[TestMethod] [Test]
public void Saturate_ShouldReturnValue_GivenValueBetween0And1() public void Saturate_ShouldReturnValue_GivenValueBetween0And1()
{ {
Assert.AreEqual(0.5m, 0.5m.Saturate(), 1e-6m); Assert.That(0.5m.Saturate(), Is.EqualTo(0.5m));
} }
[TestMethod] [Test]
public void Sign_ShouldBeMinus1_GivenNegative() public void Sign_ShouldBeMinus1_GivenNegative()
{ {
Assert.AreEqual(-1, -1.0m.Sign()); Assert.Multiple(() =>
Assert.AreEqual(-1, -2.0m.Sign()); {
Assert.AreEqual(-1, -3.0m.Sign()); Assert.That(-1.0m.Sign(), Is.EqualTo(-1));
Assert.That(-2.0m.Sign(), Is.EqualTo(-1));
Assert.That(-3.0m.Sign(), Is.EqualTo(-1));
});
} }
[TestMethod] [Test]
public void Sign_ShouldBe0_Given0() public void Sign_ShouldBe0_Given0()
{ {
Assert.AreEqual(0, 0.0m.Sign()); Assert.That(0.0m.Sign(), Is.Zero);
} }
[TestMethod] [Test]
public void Sign_ShouldBe1_GivenPositive() public void Sign_ShouldBe1_GivenPositive()
{ {
Assert.AreEqual(1, 1.0m.Sign()); Assert.Multiple(() =>
Assert.AreEqual(1, 2.0m.Sign()); {
Assert.AreEqual(1, 3.0m.Sign()); Assert.That(1.0m.Sign(), Is.EqualTo(1));
Assert.That(2.0m.Sign(), Is.EqualTo(1));
Assert.That(3.0m.Sign(), Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void Sqrt_ShouldBeCorrect_GivenValue() public void Sqrt_ShouldBeCorrect_GivenValue()
{ {
Assert.AreEqual(0.0m, 0.0m.Sqrt()); Assert.Multiple(() =>
Assert.AreEqual(1.4142135623730950488016887242m, 2.0m.Sqrt()); {
Assert.AreEqual(3.0m, 9.0m.Sqrt()); Assert.That(0.0m.Sqrt(), Is.EqualTo(0.0m));
Assert.AreEqual(4.0m, 16.0m.Sqrt()); Assert.That(2.0m.Sqrt(), Is.EqualTo(1.4142135623730950488016887242m));
Assert.AreEqual(100.0m, 10000.0m.Sqrt()); Assert.That(9.0m.Sqrt(), Is.EqualTo(3.0m));
Assert.That(16.0m.Sqrt(), Is.EqualTo(4.0m));
Assert.That(10000.0m.Sqrt(), Is.EqualTo(100.0m));
});
} }
[TestMethod] [Test]
public void Sqrt_ShouldThrow_GivenNegativeValue() public void Sqrt_ShouldThrow_GivenNegativeValue()
{ {
Assert.ThrowsException<ArgumentException>(() => (-1.0m).Sqrt()); Assert.Throws<ArgumentException>(() => _ = (-1.0m).Sqrt());
Assert.ThrowsException<ArgumentException>(() => (-2.0m).Sqrt()); Assert.Throws<ArgumentException>(() => _ = (-2.0m).Sqrt());
Assert.ThrowsException<ArgumentException>(() => (-3.0m).Sqrt()); Assert.Throws<ArgumentException>(() => _ = (-3.0m).Sqrt());
} }
} }

View File

@ -1,14 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
public partial class DoubleTests public partial class DoubleTests
{ {
[TestClass] [TestFixture]
public class WrapTests public class WrapTests
{ {
[TestMethod] [Test]
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow() public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
{ {
const double value = 10; const double value = 10;
@ -17,10 +17,10 @@ public partial class DoubleTests
double result = value.Wrap(low, high); double result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh() public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
{ {
const double value = 20; const double value = 20;
@ -29,10 +29,10 @@ public partial class DoubleTests
double result = value.Wrap(low, high); double result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
{ {
const double value = 30; const double value = 30;
@ -41,10 +41,10 @@ public partial class DoubleTests
double result = value.Wrap(low, high); double result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow() public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
{ {
const double value = 5; const double value = 5;
@ -53,10 +53,10 @@ public partial class DoubleTests
double result = value.Wrap(low, high); double result = value.Wrap(low, high);
Assert.AreEqual(15.0, result); Assert.That(result, Is.EqualTo(15.0));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
{ {
const double value = 15; const double value = 15;
@ -65,10 +65,10 @@ public partial class DoubleTests
double result = value.Wrap(low, high); double result = value.Wrap(low, high);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength() public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
{ {
const double value = 10; const double value = 10;
@ -76,10 +76,10 @@ public partial class DoubleTests
double result = value.Wrap(length); double result = value.Wrap(length);
Assert.AreEqual(0.0, result); Assert.That(result, Is.EqualTo(0.0));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength() public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
{ {
const double value = 5; const double value = 5;
@ -87,10 +87,10 @@ public partial class DoubleTests
double result = value.Wrap(length); double result = value.Wrap(length);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
{ {
const double value = 15; const double value = 15;
@ -98,7 +98,7 @@ public partial class DoubleTests
double result = value.Wrap(length); double result = value.Wrap(length);
Assert.AreEqual(5.0, result); Assert.That(result, Is.EqualTo(5.0));
} }
} }
} }

View File

@ -1,260 +1,300 @@
using System.Numerics; using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
[TestClass] [TestFixture]
public partial class DoubleTests public partial class DoubleTests
{ {
[TestMethod] [Test]
public void DegreesToRadians_ShouldBeCorrect() public void DegreesToRadians_ShouldBeCorrect()
{ {
Assert.AreEqual(System.Math.PI, 180.0.DegreesToRadians(), 1e-6); Assert.Multiple(() =>
Assert.AreEqual(System.Math.PI * 1.5, 270.0.DegreesToRadians(), 1e-6); {
Assert.AreEqual(0.0, 0.0.DegreesToRadians(), 1e-6); Assert.That(180.0.DegreesToRadians(), Is.EqualTo(System.Math.PI).Within(1e-6));
Assert.AreEqual(0.017453292519943295, 1.0.DegreesToRadians(), 1e-6); Assert.That(270.0.DegreesToRadians(), Is.EqualTo(System.Math.PI * 1.5).Within(1e-6));
Assert.AreEqual(0.10471975511965978, 6.0.DegreesToRadians(), 1e-6); Assert.That(0.0.DegreesToRadians(), Is.EqualTo(0.0).Within(1e-6));
Assert.AreEqual(0.20943951023931956, 12.0.DegreesToRadians(), 1e-6); Assert.That(1.0.DegreesToRadians(), Is.EqualTo(0.017453292519943295).Within(1e-6));
Assert.That(6.0.DegreesToRadians(), Is.EqualTo(0.10471975511965978).Within(1e-6));
Assert.That(12.0.DegreesToRadians(), Is.EqualTo(0.20943951023931956).Within(1e-6));
});
} }
[TestMethod] [Test]
public void RadiansToDegrees_ShouldBeCorrect() public void RadiansToDegrees_ShouldBeCorrect()
{ {
Assert.AreEqual(180.0, System.Math.PI.RadiansToDegrees(), 1e-6); Assert.Multiple(() =>
Assert.AreEqual(360.0, (2.0 * System.Math.PI).RadiansToDegrees(), 1e-6); {
Assert.AreEqual(0.0, 0.0.RadiansToDegrees(), 1e-6); Assert.That(System.Math.PI.RadiansToDegrees(), Is.EqualTo(180.0).Within(1e-6));
Assert.AreEqual(1.0, 0.017453292519943295.RadiansToDegrees(), 1e-6); Assert.That((2.0 * System.Math.PI).RadiansToDegrees(), Is.EqualTo(360.0).Within(1e-6));
Assert.AreEqual(6.000000000000001, 0.10471975511965978.RadiansToDegrees(), 1e-6); // rounding errors are fun Assert.That(0.0.RadiansToDegrees(), Is.EqualTo(0.0).Within(1e-6));
Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees(), 1e-6); Assert.That(0.017453292519943295.RadiansToDegrees(), Is.EqualTo(1.0).Within(1e-6));
// rounding errors are fun
Assert.That(0.10471975511965978.RadiansToDegrees(), Is.EqualTo(6.000000000000001).Within(1e-6));
Assert.That(0.20943951023931953.RadiansToDegrees(), Is.EqualTo(12.0).Within(1e-6));
});
} }
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeCorrect_GivenReal() public void ComplexSqrt_ShouldBeCorrect_GivenReal()
{ {
Assert.AreEqual(0.0, 0.0.ComplexSqrt()); Assert.Multiple(() =>
Assert.AreEqual(1.4142135623730951, 2.0.ComplexSqrt()); {
Assert.AreEqual(3.0, 9.0.ComplexSqrt()); Assert.That(0.0.ComplexSqrt(), Is.EqualTo((Complex)0.0));
Assert.AreEqual(4.0, 16.0.ComplexSqrt()); Assert.That(2.0.ComplexSqrt(), Is.EqualTo((Complex)1.4142135623730951));
Assert.AreEqual(100.0, 10000.0.ComplexSqrt()); Assert.That(9.0.ComplexSqrt(), Is.EqualTo((Complex)3.0));
Assert.That(16.0.ComplexSqrt(), Is.EqualTo((Complex)4.0));
Assert.That(10000.0.ComplexSqrt(), Is.EqualTo((Complex)100.0));
});
} }
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeImaginary_GivenNegativeValue() public void ComplexSqrt_ShouldBeImaginary_GivenNegativeValue()
{ {
Assert.AreEqual(new Complex(0, 1), (-1.0).ComplexSqrt()); Assert.Multiple(() =>
Assert.AreEqual(new Complex(0, 1.4142135623730951), (-2.0).ComplexSqrt()); {
Assert.AreEqual(new Complex(0, 3.0), (-9.0).ComplexSqrt()); Assert.That((-1.0).ComplexSqrt(), Is.EqualTo(new Complex(0, 1)));
Assert.AreEqual(new Complex(0, 4.0), (-16.0).ComplexSqrt()); Assert.That((-2.0).ComplexSqrt(), Is.EqualTo(new Complex(0, 1.4142135623730951)));
Assert.That((-9.0).ComplexSqrt(), Is.EqualTo(new Complex(0, 3.0)));
Assert.That((-16.0).ComplexSqrt(), Is.EqualTo(new Complex(0, 4.0)));
});
} }
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeComplexInfinity_GivenInfinity() public void ComplexSqrt_ShouldBeComplexInfinity_GivenInfinity()
{ {
Assert.AreEqual(Complex.Infinity, double.NegativeInfinity.ComplexSqrt()); Assert.Multiple(() =>
Assert.AreEqual(Complex.Infinity, double.PositiveInfinity.ComplexSqrt()); {
Assert.That(double.NegativeInfinity.ComplexSqrt(), Is.EqualTo(Complex.Infinity));
Assert.That(double.PositiveInfinity.ComplexSqrt(), Is.EqualTo(Complex.Infinity));
});
} }
[TestMethod] [Test]
public void ComplexSqrt_ShouldBeNaN_GivenNaN() public void ComplexSqrt_ShouldBeNaN_GivenNaN()
{ {
Assert.AreEqual(Complex.NaN, double.NaN.ComplexSqrt()); Assert.That(double.NaN.ComplexSqrt(), Is.EqualTo(Complex.NaN));
} }
[TestMethod] [Test]
public void IsEven_ShouldBeFalse_GivenOddNumber() public void IsEven_ShouldBeFalse_GivenOddNumber()
{ {
Assert.IsFalse((-3.0).IsEven()); Assert.Multiple(() =>
Assert.IsFalse((-1.0).IsEven()); {
Assert.IsFalse(1.0.IsEven()); Assert.That((-3.0).IsEven(), Is.False);
Assert.IsFalse(3.0.IsEven()); Assert.That((-1.0).IsEven(), Is.False);
Assert.That(1.0.IsEven(), Is.False);
Assert.That(3.0.IsEven(), Is.False);
});
} }
[TestMethod] [Test]
public void IsEven_ShouldBeTrue_GivenOddNumber() public void IsEven_ShouldBeTrue_GivenOddNumber()
{ {
Assert.IsTrue((-4.0).IsEven()); Assert.Multiple(() =>
Assert.IsTrue((-2.0).IsEven()); {
Assert.IsTrue(0.0.IsEven()); Assert.That((-4.0).IsEven());
Assert.IsTrue(2.0.IsEven()); Assert.That((-2.0).IsEven());
Assert.IsTrue(4.0.IsEven()); Assert.That(0.0.IsEven());
Assert.That(2.0.IsEven());
Assert.That(4.0.IsEven());
});
} }
[TestMethod] [Test]
public void IsOdd_ShouldBeFalse_GivenEvenNumber() public void IsOdd_ShouldBeFalse_GivenEvenNumber()
{ {
Assert.IsFalse((-4.0).IsOdd()); Assert.Multiple(() =>
Assert.IsFalse((-2.0).IsOdd()); {
Assert.IsFalse(0.0.IsOdd()); Assert.That((-4.0).IsOdd(), Is.False);
Assert.IsFalse(2.0.IsOdd()); Assert.That((-2.0).IsOdd(), Is.False);
Assert.IsFalse(4.0.IsOdd()); Assert.That(0.0.IsOdd(), Is.False);
Assert.That(2.0.IsOdd(), Is.False);
Assert.That(4.0.IsOdd(), Is.False);
});
} }
[TestMethod] [Test]
public void IsOdd_ShouldBeTrue_GivenOddNumber() public void IsOdd_ShouldBeTrue_GivenOddNumber()
{ {
Assert.IsTrue((-3.0).IsOdd()); Assert.Multiple(() =>
Assert.IsTrue((-1.0).IsOdd()); {
Assert.IsTrue(1.0.IsOdd()); Assert.That((-3.0).IsOdd());
Assert.IsTrue(3.0.IsOdd()); Assert.That((-1.0).IsOdd());
Assert.That(1.0.IsOdd());
Assert.That(3.0.IsOdd());
});
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearestInteger() public void Round_ShouldRoundToNearestInteger()
{ {
Assert.AreEqual(4.0, 3.5.Round(), 1e-6); Assert.That(3.5.Round(), Is.EqualTo(4.0).Within(1e-6));
Assert.AreEqual(7.0, 6.8.Round(), 1e-6); Assert.That(6.8.Round(), Is.EqualTo(7.0).Within(1e-6));
Assert.AreEqual(7.0, 7.2.Round(), 1e-6); Assert.That(7.2.Round(), Is.EqualTo(7.0).Within(1e-6));
} }
[TestMethod] [Test]
public void Round_ShouldRoundToNearestMultiple() public void Round_ShouldRoundToNearestMultiple()
{ {
Assert.AreEqual(5.0, 3.5.Round(5), 1e-6); Assert.That(3.5.Round(5), Is.EqualTo(5.0).Within(1e-6));
Assert.AreEqual(5.0, 7.0.Round(5), 1e-6); Assert.That(7.0.Round(5), Is.EqualTo(5.0).Within(1e-6));
Assert.AreEqual(10.0, 7.5.Round(5), 1e-6); Assert.That(7.5.Round(5), Is.EqualTo(10.0).Within(1e-6));
} }
[TestMethod] [Test]
public void Saturate_ShouldClampValueTo1_GivenGreaterThan1() public void Saturate_ShouldClampValueTo1_GivenGreaterThan1()
{ {
Assert.AreEqual(1.0, 1.5.Saturate(), 1e-6); Assert.That(1.5.Saturate(), Is.EqualTo(1.0).Within(1e-6));
} }
[TestMethod] [Test]
public void Saturate_ShouldClampValueTo0_GivenLessThan0() public void Saturate_ShouldClampValueTo0_GivenLessThan0()
{ {
Assert.AreEqual(0.0, (-0.5).Saturate(), 1e-6); Assert.That((-0.5).Saturate(), Is.EqualTo(0.0).Within(1e-6));
} }
[TestMethod] [Test]
public void Saturate_ShouldReturnValue_GivenValueBetween0And1() public void Saturate_ShouldReturnValue_GivenValueBetween0And1()
{ {
Assert.AreEqual(0.5, 0.5.Saturate(), 1e-6); Assert.That(0.5.Saturate(), Is.EqualTo(0.5).Within(1e-6));
} }
[TestMethod] [Test]
public void Sign_ShouldBeMinus1_GivenNegative() public void Sign_ShouldBeMinus1_GivenNegative()
{ {
Assert.AreEqual(-1, -1.0.Sign()); Assert.Multiple(() =>
Assert.AreEqual(-1, -2.0.Sign()); {
Assert.AreEqual(-1, -3.0.Sign()); Assert.That(-1.0.Sign(), Is.EqualTo(-1));
Assert.That(-2.0.Sign(), Is.EqualTo(-1));
Assert.That(-3.0.Sign(), Is.EqualTo(-1));
});
} }
[TestMethod] [Test]
public void Sign_ShouldBe0_Given0() public void Sign_ShouldBe0_Given0()
{ {
Assert.AreEqual(0, 0.0.Sign()); Assert.That(0.0.Sign(), Is.Zero);
} }
[TestMethod] [Test]
public void Sign_ShouldBe1_GivenPositive() public void Sign_ShouldBe1_GivenPositive()
{ {
Assert.AreEqual(1, 1.0.Sign()); Assert.Multiple(() =>
Assert.AreEqual(1, 2.0.Sign()); {
Assert.AreEqual(1, 3.0.Sign()); Assert.That(1.0.Sign(), Is.EqualTo(1));
Assert.That(2.0.Sign(), Is.EqualTo(1));
Assert.That(3.0.Sign(), Is.EqualTo(1));
});
} }
[TestMethod] [Test]
public void Sqrt_ShouldBeCorrect_GivenValue() public void Sqrt_ShouldBeCorrect_GivenValue()
{ {
Assert.AreEqual(0.0, 0.0.Sqrt(), 1e-6); Assert.Multiple(() =>
Assert.AreEqual(1.414213562373095, 2.0.Sqrt(), 1e-6); {
Assert.AreEqual(3.0, 9.0.Sqrt(), 1e-6); Assert.That(0.0.Sqrt(), Is.EqualTo(0.0).Within(1e-6));
Assert.AreEqual(4.0, 16.0.Sqrt(), 1e-6); Assert.That(2.0.Sqrt(), Is.EqualTo(1.414213562373095).Within(1e-6));
Assert.AreEqual(100.0, 10000.0.Sqrt(), 1e-6); Assert.That(9.0.Sqrt(), Is.EqualTo(3.0).Within(1e-6));
Assert.That(16.0.Sqrt(), Is.EqualTo(4.0).Within(1e-6));
Assert.That(10000.0.Sqrt(), Is.EqualTo(100.0).Within(1e-6));
});
} }
[TestMethod] [Test]
public void Sqrt_ShouldBeNaN_GivenNaN() public void Sqrt_ShouldBeNaN_GivenNaN()
{ {
Assert.AreEqual(double.NaN, double.NaN.Sqrt()); Assert.That(double.NaN.Sqrt(), Is.EqualTo(double.NaN));
} }
[TestMethod] [Test]
public void Sqrt_ShouldBeNaN_GivenNegativeValue() public void Sqrt_ShouldBeNaN_GivenNegativeValue()
{ {
Assert.AreEqual(double.NaN, (-1.0).Sqrt()); Assert.Multiple(() =>
Assert.AreEqual(double.NaN, (-2.0).Sqrt()); {
Assert.AreEqual(double.NaN, (-3.0).Sqrt()); Assert.That((-1.0).Sqrt(), Is.EqualTo(double.NaN));
Assert.AreEqual(double.NaN, double.NegativeInfinity.Sqrt()); Assert.That((-2.0).Sqrt(), Is.EqualTo(double.NaN));
Assert.That((-3.0).Sqrt(), Is.EqualTo(double.NaN));
Assert.That(double.NegativeInfinity.Sqrt(), Is.EqualTo(double.NaN));
});
} }
[TestMethod] [Test]
public void Sqrt_ShouldBePositiveInfinity_GivenPositiveInfinity() public void Sqrt_ShouldBePositiveInfinity_GivenPositiveInfinity()
{ {
Assert.AreEqual(double.PositiveInfinity, double.PositiveInfinity.Sqrt()); Assert.That(double.PositiveInfinity.Sqrt(), Is.EqualTo(double.PositiveInfinity));
} }
[TestMethod] [Test]
public void Acos_ShouldBeCorrect() public void Acos_ShouldBeCorrect()
{ {
Assert.AreEqual(1.0471975511965979, 0.5.Acos(), 1e-6); Assert.That(0.5.Acos(), Is.EqualTo(1.0471975511965979).Within(1e-6));
} }
[TestMethod] [Test]
public void Acosh_ShouldBeCorrect() public void Acosh_ShouldBeCorrect()
{ {
Assert.AreEqual(0.9624236501192069, 1.5.Acosh(), 1e-6); Assert.That(1.5.Acosh(), Is.EqualTo(0.9624236501192069).Within(1e-6));
} }
[TestMethod] [Test]
public void Asin_ShouldBeCorrect() public void Asin_ShouldBeCorrect()
{ {
Assert.AreEqual(0.5235987755982989, 0.5.Asin(), 1e-6); Assert.That(0.5.Asin(), Is.EqualTo(0.5235987755982989).Within(1e-6));
} }
[TestMethod] [Test]
public void Asinh_ShouldBeCorrect() public void Asinh_ShouldBeCorrect()
{ {
Assert.AreEqual(1.1947632172871094, 1.5.Asinh(), 1e-6); Assert.That(1.5.Asinh(), Is.EqualTo(1.1947632172871094).Within(1e-6));
} }
[TestMethod] [Test]
public void Atan_ShouldBeCorrect() public void Atan_ShouldBeCorrect()
{ {
Assert.AreEqual(0.4636476090008061, 0.5.Atan(), 1e-6); Assert.That(0.5.Atan(), Is.EqualTo(0.4636476090008061).Within(1e-6));
} }
[TestMethod] [Test]
public void Atanh_ShouldBeCorrect() public void Atanh_ShouldBeCorrect()
{ {
Assert.AreEqual(0.5493061443340549, 0.5.Atanh(), 1e-6); Assert.That(0.5.Atanh(), Is.EqualTo(0.5493061443340549).Within(1e-6));
} }
[TestMethod] [Test]
public void Cos_ShouldBeCorrect() public void Cos_ShouldBeCorrect()
{ {
Assert.AreEqual(0.8775825618903728, 0.5.Cos(), 1e-6); Assert.That(0.5.Cos(), Is.EqualTo(0.8775825618903728).Within(1e-6));
} }
[TestMethod] [Test]
public void Cosh_ShouldBeCorrect() public void Cosh_ShouldBeCorrect()
{ {
Assert.AreEqual(2.352409615243247, 1.5.Cosh(), 1e-6); Assert.That(1.5.Cosh(), Is.EqualTo(2.352409615243247).Within(1e-6));
} }
[TestMethod] [Test]
public void Sin_ShouldBeCorrect() public void Sin_ShouldBeCorrect()
{ {
Assert.AreEqual(0.479425538604203, 0.5.Sin(), 1e-6); Assert.That(0.5.Sin(), Is.EqualTo(0.479425538604203).Within(1e-6));
} }
[TestMethod] [Test]
public void Sinh_ShouldBeCorrect() public void Sinh_ShouldBeCorrect()
{ {
Assert.AreEqual(2.1292794550948173, 1.5.Sinh(), 1e-6); Assert.That(1.5.Sinh(), Is.EqualTo(2.1292794550948173).Within(1e-6));
} }
[TestMethod] [Test]
public void Tan_ShouldBeCorrect() public void Tan_ShouldBeCorrect()
{ {
Assert.AreEqual(0.5463024898437905, 0.5.Tan(), 1e-6); Assert.That(0.5.Tan(), Is.EqualTo(0.5463024898437905).Within(1e-6));
} }
[TestMethod] [Test]
public void Tanh_ShouldBeCorrect() public void Tanh_ShouldBeCorrect()
{ {
Assert.AreEqual(0.46211715726000974, 0.5.Tanh(), 1e-6); Assert.That(0.5.Tanh(), Is.EqualTo(0.46211715726000974).Within(1e-6));
} }
} }

View File

@ -1,14 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
using X10D.Math; using X10D.Math;
namespace X10D.Tests.Math; namespace X10D.Tests.Math;
public partial class Int16Tests public partial class Int16Tests
{ {
[TestClass] [TestFixture]
public class WrapTests public class WrapTests
{ {
[TestMethod] [Test]
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow() public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
{ {
const short value = 10; const short value = 10;
@ -17,10 +17,10 @@ public partial class Int16Tests
short result = value.Wrap(low, high); short result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh() public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
{ {
const short value = 20; const short value = 20;
@ -29,10 +29,10 @@ public partial class Int16Tests
short result = value.Wrap(low, high); short result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
{ {
const short value = 30; const short value = 30;
@ -41,10 +41,10 @@ public partial class Int16Tests
short result = value.Wrap(low, high); short result = value.Wrap(low, high);
Assert.AreEqual(low, result); Assert.That(result, Is.EqualTo(low));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow() public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
{ {
const short value = 5; const short value = 5;
@ -53,10 +53,10 @@ public partial class Int16Tests
short result = value.Wrap(low, high); short result = value.Wrap(low, high);
Assert.AreEqual(15, result); Assert.That(result, Is.EqualTo(15));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh() public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
{ {
const short value = 15; const short value = 15;
@ -65,10 +65,10 @@ public partial class Int16Tests
short result = value.Wrap(low, high); short result = value.Wrap(low, high);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength() public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
{ {
const short value = 10; const short value = 10;
@ -76,10 +76,10 @@ public partial class Int16Tests
short result = value.Wrap(length); short result = value.Wrap(length);
Assert.AreEqual(0, result); Assert.That(result, Is.Zero);
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength() public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
{ {
const short value = 5; const short value = 5;
@ -87,10 +87,10 @@ public partial class Int16Tests
short result = value.Wrap(length); short result = value.Wrap(length);
Assert.AreEqual(value, result); Assert.That(result, Is.EqualTo(value));
} }
[TestMethod] [Test]
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength() public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
{ {
const short value = 15; const short value = 15;
@ -98,7 +98,7 @@ public partial class Int16Tests
short result = value.Wrap(length); short result = value.Wrap(length);
Assert.AreEqual(5, result); Assert.That(result, Is.EqualTo(5));
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More