mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-09 23:35:41 +00:00
test: switch to NUnit
This commit is contained in:
parent
ff298a8af5
commit
c54dc755ce
@ -6,18 +6,17 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1"/>
|
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1"/>
|
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,34 +1,40 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace VpSharp.Tests;
|
namespace VpSharp.Tests;
|
||||||
|
|
||||||
[TestClass]
|
internal sealed class ColorFTests
|
||||||
public class ColorFTests
|
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[Test]
|
||||||
public void Black_ToVpColorF_ShouldGive0ForProperties()
|
public void Black_ToVpColorF_ShouldGive0ForProperties()
|
||||||
{
|
{
|
||||||
ColorF color = Color.Black;
|
ColorF color = Color.Black;
|
||||||
Assert.AreEqual(color.A, 1.0f, float.Epsilon);
|
Assert.Multiple(() =>
|
||||||
Assert.AreEqual(color.R, 0.0f, float.Epsilon);
|
{
|
||||||
Assert.AreEqual(color.G, 0.0f, float.Epsilon);
|
Assert.That(color.A, Is.EqualTo(1.0f).Within(float.Epsilon));
|
||||||
Assert.AreEqual(color.B, 0.0f, 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()
|
public void Transparent_ToVpColorF_ShouldGive0ForAlpha()
|
||||||
{
|
{
|
||||||
ColorF color = Color.Transparent;
|
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()
|
public void White_ToVpColorF_ShouldGive1ForProperties()
|
||||||
{
|
{
|
||||||
ColorF color = Color.White;
|
ColorF color = Color.White;
|
||||||
Assert.AreEqual(color.A, 1.0f, float.Epsilon);
|
Assert.Multiple(() =>
|
||||||
Assert.AreEqual(color.R, 1.0f, float.Epsilon);
|
{
|
||||||
Assert.AreEqual(color.G, 1.0f, float.Epsilon);
|
Assert.That(color.A, Is.EqualTo(1.0f).Within(float.Epsilon));
|
||||||
Assert.AreEqual(color.B, 1.0f, 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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace VpSharp.Tests;
|
namespace VpSharp.Tests;
|
||||||
|
|
||||||
[TestClass]
|
internal sealed class CoordinateTests
|
||||||
public sealed class CoordinateTests
|
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[Test]
|
||||||
public void TestAbsolute()
|
public void TestAbsolute()
|
||||||
{
|
{
|
||||||
TestCoordinates("asdf", 0.0, 0.0, 0.0, 0.0, world: "asdf");
|
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);
|
TestCoordinates("2355.71S 3429.68E -0.37a 0", -3429.68, -0.37, -2355.71);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[Test]
|
||||||
public void TestRelative()
|
public void TestRelative()
|
||||||
{
|
{
|
||||||
TestCoordinates("-1.1 +0 -1.2a", 0.0, -1.2, -1.1, 0.0, true);
|
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);
|
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(
|
private static void TestCoordinates(
|
||||||
string input,
|
string input,
|
||||||
double x,
|
double x,
|
||||||
@ -41,18 +59,22 @@ public sealed class CoordinateTests
|
|||||||
Trace.WriteLine($"Parsed: {coordinates}");
|
Trace.WriteLine($"Parsed: {coordinates}");
|
||||||
Trace.WriteLine("----");
|
Trace.WriteLine("----");
|
||||||
|
|
||||||
Assert.AreEqual(x, coordinates.X);
|
Assert.Multiple(() =>
|
||||||
Assert.AreEqual(y, coordinates.Y);
|
{
|
||||||
Assert.AreEqual(z, coordinates.Z);
|
Assert.That(coordinates.X, Is.EqualTo(x));
|
||||||
Assert.AreEqual(yaw, coordinates.Yaw);
|
Assert.That(coordinates.Y, Is.EqualTo(y));
|
||||||
Assert.AreEqual(isRelative, coordinates.IsRelative);
|
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))
|
if (string.IsNullOrWhiteSpace(world))
|
||||||
{
|
{
|
||||||
Assert.IsTrue(string.IsNullOrWhiteSpace(coordinates.World));
|
Assert.IsTrue(string.IsNullOrWhiteSpace(coordinates.World));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert.AreEqual(world, coordinates.World);
|
Assert.That(coordinates.World, Is.EqualTo(world));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using NUnit.Framework;
|
||||||
using VpSharp.Internal;
|
using VpSharp.Internal;
|
||||||
|
|
||||||
namespace VpSharp.Tests;
|
namespace VpSharp.Tests;
|
||||||
|
|
||||||
[TestClass]
|
internal sealed class MarshallerTests
|
||||||
public class MarshellerTests
|
|
||||||
{
|
{
|
||||||
private static readonly Utf8StringToNative ManagedToNativeMarshaller = new();
|
private static readonly Utf8StringToNative ManagedToNativeMarshaller = new();
|
||||||
private static readonly Utf8StringToManaged NativeToManagedMarshaller = new();
|
private static readonly Utf8StringToManaged NativeToManagedMarshaller = new();
|
||||||
private static readonly Random Random = new();
|
private static readonly Random Random = new();
|
||||||
|
|
||||||
[TestMethod]
|
[Test]
|
||||||
public unsafe void MarshalNativeToManaged_ShouldReturnPointerToUtf8Bytes_GivenString()
|
public unsafe void MarshalNativeToManaged_ShouldReturnPointerToUtf8Bytes_GivenString()
|
||||||
{
|
{
|
||||||
string value = GenerateRandomString();
|
string value = GenerateRandomString();
|
||||||
byte* pointer = GetBytePointer(value, out int count);
|
byte* pointer = GetBytePointer(value, out int count);
|
||||||
string expected = Encoding.UTF8.GetString(pointer, count);
|
string expected = Encoding.UTF8.GetString(pointer, count);
|
||||||
var actual = (string)NativeToManagedMarshaller.MarshalNativeToManaged((nint)pointer);
|
var actual = (string)NativeToManagedMarshaller.MarshalNativeToManaged((nint)pointer);
|
||||||
Assert.AreEqual(expected, actual);
|
Assert.That(actual, Is.EqualTo(expected));
|
||||||
|
|
||||||
CleanUpNativeData(pointer);
|
CleanUpNativeData(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[Test]
|
||||||
public unsafe void MarshalManagedToNative_ShouldReturnPointerToUtf8Bytes_GivenString()
|
public unsafe void MarshalManagedToNative_ShouldReturnPointerToUtf8Bytes_GivenString()
|
||||||
{
|
{
|
||||||
string value = GenerateRandomString();
|
string value = GenerateRandomString();
|
||||||
@ -31,7 +31,7 @@ public class MarshellerTests
|
|||||||
string result = Encoding.UTF8.GetString(pointer, count);
|
string result = Encoding.UTF8.GetString(pointer, count);
|
||||||
|
|
||||||
Trace.WriteLine($"Test string: {value}");
|
Trace.WriteLine($"Test string: {value}");
|
||||||
Assert.AreEqual(value, result);
|
Assert.That(result, Is.EqualTo(value));
|
||||||
|
|
||||||
CleanUpNativeData(pointer);
|
CleanUpNativeData(pointer);
|
||||||
}
|
}
|
@ -1 +0,0 @@
|
|||||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
Loading…
Reference in New Issue
Block a user