1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-12 22:35:42 +00:00

test: switch to NUnit

This commit is contained in:
Oliver Booth 2024-05-23 11:57:56 +01:00
parent ff298a8af5
commit c54dc755ce
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
5 changed files with 63 additions and 37 deletions

View File

@ -6,18 +6,17 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1"/>
<PackageReference Include="MSTest.TestFramework" Version="3.1.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="3.14.0"/>
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
</ItemGroup>
<ItemGroup>

View File

@ -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));
});
}
}

View File

@ -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));
}
}
}

View File

@ -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);
}

View File

@ -1 +0,0 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;