From c54dc755cec395f039eb53b9cd37dce5cada4926 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 23 May 2024 11:57:56 +0100 Subject: [PATCH] test: switch to NUnit --- VpSharp.Tests/VpSharp.Tests.csproj | 11 +++-- VpSharp.Tests/src/ColorFTests.cs | 34 ++++++++------- VpSharp.Tests/src/CoordinateTests.cs | 42 ++++++++++++++----- ...{MarshellerTests.cs => MarshallerTests.cs} | 12 +++--- VpSharp.Tests/src/Usings.cs | 1 - 5 files changed, 63 insertions(+), 37 deletions(-) rename VpSharp.Tests/src/{MarshellerTests.cs => MarshallerTests.cs} (92%) delete mode 100644 VpSharp.Tests/src/Usings.cs diff --git a/VpSharp.Tests/VpSharp.Tests.csproj b/VpSharp.Tests/VpSharp.Tests.csproj index 3d19802..9cdce9d 100644 --- a/VpSharp.Tests/VpSharp.Tests.csproj +++ b/VpSharp.Tests/VpSharp.Tests.csproj @@ -6,18 +6,17 @@ enable false + true true + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + diff --git a/VpSharp.Tests/src/ColorFTests.cs b/VpSharp.Tests/src/ColorFTests.cs index 295beed..47ef73e 100644 --- a/VpSharp.Tests/src/ColorFTests.cs +++ b/VpSharp.Tests/src/ColorFTests.cs @@ -1,34 +1,40 @@ using System.Drawing; +using NUnit.Framework; namespace VpSharp.Tests; -[TestClass] -public class ColorFTests +internal sealed class ColorFTests { - [TestMethod] + [Test] public void Black_ToVpColorF_ShouldGive0ForProperties() { ColorF color = Color.Black; - Assert.AreEqual(color.A, 1.0f, float.Epsilon); - Assert.AreEqual(color.R, 0.0f, float.Epsilon); - Assert.AreEqual(color.G, 0.0f, float.Epsilon); - Assert.AreEqual(color.B, 0.0f, float.Epsilon); + Assert.Multiple(() => + { + Assert.That(color.A, Is.EqualTo(1.0f).Within(float.Epsilon)); + Assert.That(color.R, Is.EqualTo(0.0f).Within(float.Epsilon)); + Assert.That(color.G, Is.EqualTo(0.0f).Within(float.Epsilon)); + Assert.That(color.B, Is.EqualTo(0.0f).Within(float.Epsilon)); + }); } - [TestMethod] + [Test] public void Transparent_ToVpColorF_ShouldGive0ForAlpha() { ColorF color = Color.Transparent; - Assert.AreEqual(color.A, 0.0f, float.Epsilon); + Assert.That(color.A, Is.EqualTo(0.0f).Within(float.Epsilon)); } - [TestMethod] + [Test] public void White_ToVpColorF_ShouldGive1ForProperties() { ColorF color = Color.White; - Assert.AreEqual(color.A, 1.0f, float.Epsilon); - Assert.AreEqual(color.R, 1.0f, float.Epsilon); - Assert.AreEqual(color.G, 1.0f, float.Epsilon); - Assert.AreEqual(color.B, 1.0f, float.Epsilon); + Assert.Multiple(() => + { + Assert.That(color.A, Is.EqualTo(1.0f).Within(float.Epsilon)); + Assert.That(color.R, Is.EqualTo(1.0f).Within(float.Epsilon)); + Assert.That(color.G, Is.EqualTo(1.0f).Within(float.Epsilon)); + Assert.That(color.B, Is.EqualTo(1.0f).Within(float.Epsilon)); + }); } } diff --git a/VpSharp.Tests/src/CoordinateTests.cs b/VpSharp.Tests/src/CoordinateTests.cs index 8f50f8c..a7d55a8 100644 --- a/VpSharp.Tests/src/CoordinateTests.cs +++ b/VpSharp.Tests/src/CoordinateTests.cs @@ -1,11 +1,11 @@ using System.Diagnostics; +using NUnit.Framework; namespace VpSharp.Tests; -[TestClass] -public sealed class CoordinateTests +internal sealed class CoordinateTests { - [TestMethod] + [Test] public void TestAbsolute() { TestCoordinates("asdf", 0.0, 0.0, 0.0, 0.0, world: "asdf"); @@ -16,7 +16,7 @@ public sealed class CoordinateTests TestCoordinates("2355.71S 3429.68E -0.37a 0", -3429.68, -0.37, -2355.71); } - [TestMethod] + [Test] public void TestRelative() { TestCoordinates("-1.1 +0 -1.2a", 0.0, -1.2, -1.1, 0.0, true); @@ -24,6 +24,24 @@ public sealed class CoordinateTests TestCoordinates("+1 +1 +1a", 1.0, 1.0, 1.0, 0.0, true); } + [Test] + public void ToString_ShouldReturnFormattedString_GivenCoordinates() + { + Coordinates coordinates = Coordinates.Parse("10n 5e 1a 123"); + string result = coordinates.ToString(); + + Assert.That(result, Is.EqualTo("10.00n 5.00e 1.00a 123.00")); + } + + [Test] + public void ToString_ShouldReturnFormattedString_GivenArguments() + { + Coordinates coordinates = Coordinates.Parse("10n 5e 1a 123"); + string result = coordinates.ToString("0"); + + Assert.That(result, Is.EqualTo("10n 5e 1a 123")); + } + private static void TestCoordinates( string input, double x, @@ -41,18 +59,22 @@ public sealed class CoordinateTests Trace.WriteLine($"Parsed: {coordinates}"); Trace.WriteLine("----"); - Assert.AreEqual(x, coordinates.X); - Assert.AreEqual(y, coordinates.Y); - Assert.AreEqual(z, coordinates.Z); - Assert.AreEqual(yaw, coordinates.Yaw); - Assert.AreEqual(isRelative, coordinates.IsRelative); + Assert.Multiple(() => + { + Assert.That(coordinates.X, Is.EqualTo(x)); + Assert.That(coordinates.Y, Is.EqualTo(y)); + Assert.That(coordinates.Z, Is.EqualTo(z)); + Assert.That(coordinates.Yaw, Is.EqualTo(yaw)); + Assert.That(coordinates.IsRelative, Is.EqualTo(isRelative)); + }); + if (string.IsNullOrWhiteSpace(world)) { Assert.IsTrue(string.IsNullOrWhiteSpace(coordinates.World)); } else { - Assert.AreEqual(world, coordinates.World); + Assert.That(coordinates.World, Is.EqualTo(world)); } } } diff --git a/VpSharp.Tests/src/MarshellerTests.cs b/VpSharp.Tests/src/MarshallerTests.cs similarity index 92% rename from VpSharp.Tests/src/MarshellerTests.cs rename to VpSharp.Tests/src/MarshallerTests.cs index 97d0e8b..96cf878 100644 --- a/VpSharp.Tests/src/MarshellerTests.cs +++ b/VpSharp.Tests/src/MarshallerTests.cs @@ -1,29 +1,29 @@ using System.Diagnostics; using System.Text; +using NUnit.Framework; using VpSharp.Internal; namespace VpSharp.Tests; -[TestClass] -public class MarshellerTests +internal sealed class MarshallerTests { private static readonly Utf8StringToNative ManagedToNativeMarshaller = new(); private static readonly Utf8StringToManaged NativeToManagedMarshaller = new(); private static readonly Random Random = new(); - [TestMethod] + [Test] public unsafe void MarshalNativeToManaged_ShouldReturnPointerToUtf8Bytes_GivenString() { string value = GenerateRandomString(); byte* pointer = GetBytePointer(value, out int count); string expected = Encoding.UTF8.GetString(pointer, count); var actual = (string)NativeToManagedMarshaller.MarshalNativeToManaged((nint)pointer); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); CleanUpNativeData(pointer); } - [TestMethod] + [Test] public unsafe void MarshalManagedToNative_ShouldReturnPointerToUtf8Bytes_GivenString() { string value = GenerateRandomString(); @@ -31,7 +31,7 @@ public class MarshellerTests string result = Encoding.UTF8.GetString(pointer, count); Trace.WriteLine($"Test string: {value}"); - Assert.AreEqual(value, result); + Assert.That(result, Is.EqualTo(value)); CleanUpNativeData(pointer); } diff --git a/VpSharp.Tests/src/Usings.cs b/VpSharp.Tests/src/Usings.cs deleted file mode 100644 index 540383d..0000000 --- a/VpSharp.Tests/src/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting;