Split up test project

Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
This commit is contained in:
PJB3005
2025-12-16 01:36:53 +01:00
parent 095c5f58d9
commit 788e9386fd
284 changed files with 849 additions and 595 deletions

View File

@@ -0,0 +1,36 @@
using System.Numerics;
using NUnit.Framework;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.UnitTesting;
namespace Robust.Client.Tests.Graphics
{
[TestFixture, Parallelizable, TestOf(typeof(Eye))]
internal sealed class EyeTest
{
[Test]
public void Constructor_DefaultZoom_isTwo()
{
var eye = new Eye();
Assert.That(eye.Zoom, Is.Approximately(Vector2.One*2f));
}
[Test]
public void Constructor_DefaultPosition_isZero()
{
var eye = new Eye();
Assert.That(eye.Position, Is.EqualTo(MapCoordinates.Nullspace));
}
[Test]
public void Constructor_DefaultDrawFov_isTrue()
{
var eye = new Eye();
Assert.That(eye.DrawFov, Is.True);
}
}
}

View File

@@ -0,0 +1,40 @@
using System.Numerics;
using NUnit.Framework;
using Robust.Client.Graphics;
using Robust.Shared.Maths;
namespace Robust.Client.Tests.Graphics
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
[TestOf(typeof(StyleBox))]
internal sealed class StyleBoxTest
{
[Test]
public void TestGetEnvelopBox()
{
var styleBox = new StyleBoxFlat();
Assert.That(
styleBox.GetEnvelopBox(Vector2.Zero, new Vector2(50, 50), 1),
Is.EqualTo(new UIBox2(0, 0, 50, 50)));
styleBox.ContentMarginLeftOverride = 3;
styleBox.ContentMarginTopOverride = 5;
styleBox.ContentMarginRightOverride = 7;
styleBox.ContentMarginBottomOverride = 11;
Assert.That(
styleBox.GetEnvelopBox(Vector2.Zero, new Vector2(50, 50), 1),
Is.EqualTo(new UIBox2(0, 0, 60, 66)));
Assert.That(
styleBox.GetEnvelopBox(new Vector2(10, 10), new Vector2(50, 50), 1),
Is.EqualTo(new UIBox2(10, 10, 70, 76)));
Assert.That(
styleBox.GetEnvelopBox(new Vector2(10, 10), new Vector2(50, 50), 2.0f),
Is.EqualTo(new UIBox2(10, 10, 80, 92)));
}
}
}

View File

@@ -0,0 +1,85 @@
using NUnit.Framework;
using Robust.Shared.Graphics;
using YamlDotNet.RepresentationModel;
namespace Robust.Client.Tests.Graphics
{
[TestFixture]
internal sealed class TextureLoadParametersTest
{
[Test]
public void TestLoadEmptyYaml()
{
// Test whether it defaults for empty YAML.
var yaml = new YamlMappingNode();
var loaded = TextureLoadParameters.FromYaml(yaml);
var defaultParams = TextureLoadParameters.Default;
Assert.That(loaded.SampleParameters.Filter, Is.EqualTo(defaultParams.SampleParameters.Filter));
Assert.That(loaded.SampleParameters.WrapMode, Is.EqualTo(defaultParams.SampleParameters.WrapMode));
Assert.That(loaded.Srgb, Is.EqualTo(defaultParams.Srgb));
}
[Test]
public void TestLoadEmptySamplingYaml()
{
// Test whether it defaults for empty YAML.
var yaml = _getMapping("sample: {}\n");
var loaded = TextureLoadParameters.FromYaml(yaml);
var defaultParams = TextureLoadParameters.Default;
Assert.That(loaded.SampleParameters.Filter, Is.EqualTo(defaultParams.SampleParameters.Filter));
Assert.That(loaded.SampleParameters.WrapMode, Is.EqualTo(defaultParams.SampleParameters.WrapMode));
}
[Test]
public void TestLoadYamlOne()
{
var yaml = _getMapping(TestDataOne);
var loaded = TextureLoadParameters.FromYaml(yaml);
Assert.That(loaded.SampleParameters.Filter, Is.EqualTo(true));
Assert.That(loaded.SampleParameters.WrapMode, Is.EqualTo(TextureWrapMode.Repeat));
Assert.That(loaded.Srgb, Is.EqualTo(false));
}
[Test]
public void TestLoadYamlTwo()
{
var yaml = _getMapping(TestDataTwo);
var loaded = TextureLoadParameters.FromYaml(yaml);
Assert.That(loaded.SampleParameters.Filter, Is.EqualTo(false));
Assert.That(loaded.SampleParameters.WrapMode, Is.EqualTo(TextureWrapMode.MirroredRepeat));
}
[Test]
public void TestLoadYamlThree()
{
var yaml = _getMapping(TestDataThree);
var loaded = TextureLoadParameters.FromYaml(yaml);
Assert.That(loaded.SampleParameters.WrapMode, Is.EqualTo(TextureWrapMode.None));
}
private YamlMappingNode _getMapping(string data)
{
var yamlStream = new YamlStream();
yamlStream.Load(new StringReader(data));
return (YamlMappingNode) yamlStream.Documents[0].RootNode;
}
private const string TestDataOne = @"
sample:
filter: true
wrap: repeat
srgb: false
";
private const string TestDataTwo = @"
sample:
filter: false
wrap: mirrored_repeat
";
private const string TestDataThree = @"
sample:
wrap: none
";
}
}

View File

@@ -0,0 +1,22 @@
using NUnit.Framework;
using Robust.Client.Input;
namespace Robust.Client.Tests.Input
{
[Parallelizable(ParallelScope.All)]
public sealed class KeyboardTest
{
public static IEnumerable<object[]> TestCases =>
((Keyboard.Key[]) Enum.GetValues(typeof(Keyboard.Key)))
.Where(p => p.ToString().Contains("Mouse"))
.Select(p => new object[] {p, true});
[Test]
[TestCaseSource(nameof(TestCases))]
[TestCase(Keyboard.Key.A, false)]
public void TestKeyboardIsMouseKey(Keyboard.Key key, bool isMouse)
{
Assert.That(key.IsMouseKey(), Is.EqualTo(isMouse));
}
}
}

View File

@@ -0,0 +1,108 @@
using NUnit.Framework;
using Robust.Client.ResourceManagement;
namespace Robust.Client.Tests.ResourceManagement
{
[TestOf(typeof(RSIResource))]
[Parallelizable(ParallelScope.All)]
[TestFixture]
public sealed class RsiResourceTest
{
/// <summary>
/// Simple test in which the delays are already identical so nothing should change much.
/// </summary>
[Test]
public void TestFoldDelaysIdentical()
{
var delays = new[]
{
new float[] {5, 5, 5, 5},
new float[] {5, 5, 5, 5},
new float[] {5, 5, 5, 5},
new float[] {5, 5, 5, 5},
};
var (newDelays, indices) = RSIResource.FoldDelays(delays);
Assert.That(newDelays, Is.EqualTo(new[] {5f, 5f, 5f, 5f}));
for (var i = 0; i < 4; i++)
{
var o = i * 4;
Assert.That(indices[i], Is.EqualTo(new[] {o, o + 1, o + 2, o + 3}));
}
}
/// <summary>
/// Test in which the delays are different but equal amount of frames.
/// </summary>
[Test]
public void TestFoldDelaysDifferent()
{
var delays = new[]
{
new float[] {5, 5, 5, 5},
new float[] {5, 7, 3, 5},
new float[] {5, 5, 5, 5},
new float[] {5, 5, 5, 5},
};
var (newDelays, indices) = RSIResource.FoldDelays(delays);
Assert.That(newDelays, Is.EqualTo(new[] {5f, 5f, 2f, 3f, 5f}));
Assert.That(indices[0], Is.EqualTo(new[] {0, 1, 2, 2, 3}));
Assert.That(indices[1], Is.EqualTo(new[] {4, 5, 5, 6, 7}));
Assert.That(indices[2], Is.EqualTo(new[] {8, 9, 10, 10, 11}));
Assert.That(indices[3], Is.EqualTo(new[] {12, 13, 14, 14, 15}));
}
/// <summary>
/// Test in which the delays are different but equal amount of frames.
/// </summary>
[Test]
public void TestFoldFramesDifferent()
{
var delays = new[]
{
new float[] {5, 5, 5, 5},
new float[] {5, 5, 5, 5},
new float[] {5, 5, 10},
new float[] {5, 5, 5, 5},
};
var (newDelays, indices) = RSIResource.FoldDelays(delays);
Assert.That(newDelays, Is.EqualTo(new[] {5f, 5f, 5f, 5f}));
Assert.That(indices[0], Is.EqualTo(new[] {0, 1, 2, 3}));
Assert.That(indices[1], Is.EqualTo(new[] {4, 5, 6, 7}));
Assert.That(indices[2], Is.EqualTo(new[] {8, 9, 10, 10}));
Assert.That(indices[3], Is.EqualTo(new[] {11, 12, 13, 14}));
}
/// <summary>
/// The very complicated test where a ton of stuff goes down.
/// </summary>
[Test]
public void TestFoldWild()
{
var delays = new[]
{
new float[] {1, 9},
new float[] {3, 3, 3, 1},
new float[] {7, 1, 2},
new float[] {5, 2, 2, 1},
};
var (newDelays, indices) = RSIResource.FoldDelays(delays);
Assert.That(newDelays, Is.EqualTo(new[] {1f, 2f, 2f, 1f, 1f, 1f, 1f, 1f}));
Assert.That(indices[0], Is.EqualTo(new[] {0, 1, 1, 1, 1, 1, 1, 1}));
Assert.That(indices[1], Is.EqualTo(new[] {2, 2, 3, 3, 4, 4, 4, 5}));
Assert.That(indices[2], Is.EqualTo(new[] {6, 6, 6, 6, 6, 7, 8, 8}));
Assert.That(indices[3], Is.EqualTo(new[] {9, 9, 9, 10, 10, 11, 11, 12}));
}
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\MSBuild\Robust.Engine.props"/>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>
<PackageReference Include="NUnit.Analyzers"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Robust.Client\Robust.Client.csproj" />
<ProjectReference Include="..\Robust.Shared.Maths.Tests\Robust.Shared.Maths.Tests.csproj" />
<ProjectReference Include="..\Robust.Shared.Maths\Robust.Shared.Maths.csproj"/>
<ProjectReference Include="..\Robust.Shared.Maths.Testing\Robust.Shared.Maths.Testing.csproj"/>
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj"/>
</ItemGroup>
<Import Project="..\MSBuild\Robust.Properties.targets"/>
</Project>

View File

@@ -0,0 +1,35 @@
using System.Numerics;
using NUnit.Framework;
using Robust.Client.Graphics.Clyde;
using Robust.Shared.Maths;
using Robust.UnitTesting;
namespace Robust.Client.Tests.Sprite;
[TestFixture]
[TestOf(typeof(Clyde))]
public sealed class TransformCenteredBoxTest
{
private static IEnumerable<(Box2 box, float angle, Vector2 offset, Vector2 scale)> _args =
[
(Box2.UnitCentered, 0f, new Vector2(0f,0f), new Vector2(1f,-1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(0f, 0f), new Vector2(1f, -1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1f, -1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1.25f, -0.32f)),
(new Box2(1,2,3,4), MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1.25f, -0.32f)),
];
[Test]
public void TestTransformCenteredBox([ValueSource(nameof(_args))]
(Box2 box, float angle, Vector2 offset, Vector2 scale) args)
{
var result = Clyde.TransformCenteredBox(args.box, args.angle, args.offset, args.scale);
var expected = Matrix3x2.CreateRotation(args.angle).TransformBox(args.box).Translated(args.offset);
expected = new(
expected.Left * args.scale.X,
expected.Top * args.scale.Y,
expected.Right * args.scale.X,
expected.Bottom * args.scale.Y);
Assert.That(result, Is.Approximately(expected));
}
}