Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tunit #167

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="TUnit" Version="0.2.212" />
<PackageVersion Include="Open.ChannelExtensions" Version="8.5.0" />
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
Expand All @@ -34,4 +32,4 @@
<GlobalPackageReference Include="GitVersion.MsBuild" Version="5.12.0" />
<GlobalPackageReference Include="Speckle.InterfaceGenerator" Version="0.9.6" />
</ItemGroup>
</Project>
</Project>
33 changes: 14 additions & 19 deletions tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Arc))]
public class ArcTests
{
private Plane TestPlaneCounterClockwise
Expand Down Expand Up @@ -39,7 +40,7 @@ private Plane TestPlaneClockwise
}
}

[Test]
[Fact]
public void CanCreateArc_HalfCircle_CounterClockwise()
{
const string UNITS = Units.Meters;
Expand All @@ -52,17 +53,14 @@ public void CanCreateArc_HalfCircle_CounterClockwise()
units = UNITS,
};

Assert.That(Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)), Is.EqualTo(0).Within(0.0001));
Assert.That(
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)),
Is.EqualTo(0).Within(0.0001)
);
Assert.That(counterClockwiseArc.measure - Math.PI, Is.EqualTo(0).Within(0.0001));
Assert.That(counterClockwiseArc.radius, Is.EqualTo(1).Within(0.0001));
Assert.That(counterClockwiseArc.length, Is.EqualTo(Math.PI).Within(0.0001));
Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)).ShouldBe(0, 0.0001);
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)).ShouldBe(0, 0.0001);
(counterClockwiseArc.measure - Math.PI).ShouldBe(0, 0.0001);
counterClockwiseArc.radius.ShouldBe(1, 0.0001);
counterClockwiseArc.length.ShouldBe(Math.PI, 0.0001);
}

[Test]
[Fact]
public void CanCreateArc_HalfCircle_Clockwise()
{
const string UNITS = Units.Meters;
Expand All @@ -75,13 +73,10 @@ public void CanCreateArc_HalfCircle_Clockwise()
units = UNITS,
};

Assert.That(Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)), Is.EqualTo(0).Within(0.0001));
Assert.That(
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)),
Is.EqualTo(0).Within(0.0001)
);
Assert.That(counterClockwiseArc.measure - Math.PI, Is.EqualTo(0).Within(0.0001));
Assert.That(counterClockwiseArc.radius, Is.EqualTo(1).Within(0.0001));
Assert.That(counterClockwiseArc.length, Is.EqualTo(Math.PI).Within(0.0001));
Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)).ShouldBe(0, 0.0001);
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)).ShouldBe(0, 0.0001);
(counterClockwiseArc.measure - Math.PI).ShouldBe(0, 0.0001);
counterClockwiseArc.radius.ShouldBe(1, 0.0001);
counterClockwiseArc.length.ShouldBe(Math.PI, 0.0001);
}
}
9 changes: 5 additions & 4 deletions tests/Speckle.Objects.Tests.Unit/Geometry/BoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Box))]
public class BoxTests
{
private Plane TestPlane
Expand All @@ -23,7 +24,7 @@ private Plane TestPlane
}
}

[Test]
[Fact]
public void CanCreateBox()
{
const string UNITS = Units.Meters;
Expand All @@ -36,7 +37,7 @@ public void CanCreateBox()
units = UNITS,
};

Assert.That(box.area, Is.EqualTo(2 * (2 * 4 + 2 * 6 + 4 * 6)).Within(0.0001));
Assert.That(box.volume, Is.EqualTo(2 * 4 * 6).Within(0.0001));
box.area.ShouldBe(2 * (2 * 4 + 2 * 6 + 4 * 6), 0.0001);
box.volume.ShouldBe(2 * 4 * 6, 0.0001);
}
}
9 changes: 5 additions & 4 deletions tests/Speckle.Objects.Tests.Unit/Geometry/CircleTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Circle))]
public class CircleTests
{
private Plane TestPlane
Expand All @@ -23,7 +24,7 @@ private Plane TestPlane
}
}

[Test]
[Fact]
public void CanCreateCircle()
{
const string UNITS = Units.Meters;
Expand All @@ -34,7 +35,7 @@ public void CanCreateCircle()
units = UNITS,
};

Assert.That(circle.length, Is.EqualTo(2 * Math.PI * 5).Within(0.0001));
Assert.That(circle.area, Is.EqualTo(Math.PI * 5 * 5).Within(0.0001));
circle.length.ShouldBe(2 * Math.PI * 5, 0.0001);
circle.area.ShouldBe(Math.PI * 5 * 5, 0.0001);
}
}
19 changes: 12 additions & 7 deletions tests/Speckle.Objects.Tests.Unit/Geometry/MeshTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Mesh))]
public class MeshTests
{
private static Mesh[] s_testCaseSource = { CreateBlenderStylePolygon(), CreateRhinoStylePolygon() };
public static readonly IEnumerable<object[]> TestCaseSource = new object[][]
{
[CreateBlenderStylePolygon()],
[CreateRhinoStylePolygon()],
};

[Test, TestCaseSource(nameof(s_testCaseSource))]
[Theory, MemberData(nameof(TestCaseSource))]
public void CanAlignVertices(Mesh inPolygon)
{
inPolygon.AlignVerticesWithTexCoordsByIndex();

Assert.That(inPolygon.VerticesCount, Is.EqualTo(inPolygon.TextureCoordinatesCount));
inPolygon.VerticesCount.ShouldBe(inPolygon.TextureCoordinatesCount);

var expectedPolygon = CreateRhinoStylePolygon();

Assert.That(inPolygon.vertices, Is.EquivalentTo(expectedPolygon.vertices));
Assert.That(inPolygon.faces, Is.EquivalentTo(expectedPolygon.faces));
Assert.That(inPolygon.textureCoordinates, Is.EquivalentTo(expectedPolygon.textureCoordinates));
inPolygon.vertices.ShouldBeEquivalentTo(expectedPolygon.vertices);
inPolygon.faces.ShouldBeEquivalentTo(expectedPolygon.faces);
inPolygon.textureCoordinates.ShouldBeEquivalentTo(expectedPolygon.textureCoordinates);
}

private static Mesh CreateRhinoStylePolygon()
Expand Down
52 changes: 31 additions & 21 deletions tests/Speckle.Objects.Tests.Unit/Geometry/PointTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Point))]
public class PointTests
{
[Test]
[Fact]
[SuppressMessage(
"Assertion",
"NUnit2010:Use EqualConstraint for better assertion messages in case of failure",
Expand All @@ -22,33 +23,42 @@ public void TestNull()

Assert.Multiple(() =>
{
Assert.That(a == b, Is.True);
Assert.That(a != b, Is.False);
Assert.That(b == a, Is.True);
Assert.That(b != a, Is.False);
(a == b).ShouldBeTrue();
(a != b).ShouldBeFalse();
(b == a).ShouldBeTrue();
(b != a).ShouldBeFalse();

Assert.That(a == c, Is.False);
Assert.That(a != c, Is.True);
Assert.That(c == a, Is.False);
Assert.That(c != a, Is.True);
(a == c).ShouldBeTrue();
(a != c).ShouldBeFalse();
(c == a).ShouldBeTrue();
(c != a).ShouldBeFalse();
});
}

[Test]
[TestCase(1, 1, 1, "m", 1, 1, 1, "m", ExpectedResult = true)]
[TestCase(1, 1, 1, "m", 0, 1, 1, "m", ExpectedResult = false)]
[TestCase(1, 1, 1, "m", 1, 0, 1, "m", ExpectedResult = false)]
[TestCase(1, 1, 1, "m", 1, 1, 0, "m", ExpectedResult = false)]
[TestCase(1, 1, 1, "", 1, 1, 1, "", ExpectedResult = true)]
[TestCase(1, 1, 1, null, 1, 1, 1, null, ExpectedResult = true)]
[TestCase(1, 1, 1, "m", 1, 1, 1, "meters", ExpectedResult = false)]
[TestCase(1, 1, 1, "m", 1, 1, 1, "M", ExpectedResult = false)]
[Theory]
[InlineData(1, 1, 1, "m", 1, 1, 1, "m", true)]
[InlineData(1, 1, 1, "m", 0, 1, 1, "m", false)]
[InlineData(1, 1, 1, "m", 1, 0, 1, "m", false)]
[InlineData(1, 1, 1, "m", 1, 1, 0, "m", false)]
[InlineData(1, 1, 1, "", 1, 1, 1, "", true)]
[InlineData(1, 1, 1, "m", 1, 1, 1, "meters", false)]
[InlineData(1, 1, 1, "m", 1, 1, 1, "M", false)]
// Units
public bool TestEqual(double x1, double y1, double z1, string units1, double x2, double y2, double z2, string units2)
public void TestEqual(
double x1,
double y1,
double z1,
string units1,
double x2,
double y2,
double z2,
string units2,
bool result
)
{
Point p1 = new(x1, y1, z1, units1);
Point p2 = new(x2, y2, z2, units2);

return p1 == p2;
(p1 == p2).ShouldBe(result);
}
}
61 changes: 28 additions & 33 deletions tests/Speckle.Objects.Tests.Unit/Geometry/TransformTests.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
using System.Collections;
using NUnit.Framework;
using Shouldly;
using Speckle.DoubleNumerics;
using Speckle.Objects.Other;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Transform))]
public class TransformTests
{
private const float FLOAT_TOLERANCE = 1e-6f;

[Test, TestCaseSource(nameof(TransformTestCases))]
[Theory, MemberData(nameof(TransformTestCases))]
public void ArrayBackAndForth(Matrix4x4 data)
{
var start = new Transform() { matrix = data, units = Units.None };
var asArr = Transform.CreateMatrix(start.ToArray());
var end = new Transform() { matrix = asArr, units = Units.None };

Assert.That(end.matrix, Is.EqualTo(data));
end.matrix.ShouldBe(data);
}

[Test, TestCaseSource(nameof(TransformTestCases))]
[Theory, MemberData(nameof(TransformTestCases))]
public void ConvertToUnits(Matrix4x4 data)
{
const float SF = 1000f;
Expand All @@ -38,15 +39,15 @@ public void ConvertToUnits(Matrix4x4 data)

Assert.Multiple(() =>
{
Assert.That(mms.X, Is.EqualTo(ms.X).Within(FLOAT_TOLERANCE), "Expect scale x to be unchanged");
Assert.That(mms.Y, Is.EqualTo(ms.Y).Within(FLOAT_TOLERANCE), "Expect scale y to be unchanged");
Assert.That(mms.Z, Is.EqualTo(ms.Z).Within(FLOAT_TOLERANCE), "Expect scale z to be unchanged");
mms.X.ShouldBe(ms.X, FLOAT_TOLERANCE, "Expect scale x to be unchanged");
mms.Y.ShouldBe(ms.Y, FLOAT_TOLERANCE, "Expect scale y to be unchanged");
mms.Z.ShouldBe(ms.Z, FLOAT_TOLERANCE, "Expect scale z to be unchanged");

Assert.That(Quaternion.Dot(mr, mmr), Is.LessThan(1).Within(FLOAT_TOLERANCE), "Expect rot x to be equivalent");
Quaternion.Dot(mr, mmr).ShouldBeLessThan(1d, "Expect rot x to be equivalent");

Assert.That(mmt.X, Is.EqualTo(mt.X * SF).Within(FLOAT_TOLERANCE), $"Expect translation x to be scaled by {SF}");
Assert.That(mmt.Y, Is.EqualTo(mt.Y * SF).Within(FLOAT_TOLERANCE), $"Expect translation y to be scaled by {SF}");
Assert.That(mmt.Z, Is.EqualTo(mt.Z * SF).Within(FLOAT_TOLERANCE), $"Expect translation z to be scaled by {SF}");
mmt.X.ShouldBe(mt.X * SF, FLOAT_TOLERANCE, $"Expect translation x to be scaled by {SF}");
mmt.Y.ShouldBe(mt.Y * SF, FLOAT_TOLERANCE, $"Expect translation y to be scaled by {SF}");
mmt.Z.ShouldBe(mt.Z * SF, FLOAT_TOLERANCE, $"Expect translation z to be scaled by {SF}");
});
}

Expand All @@ -55,46 +56,40 @@ public void ConvertToUnits(Matrix4x4 data)
/// All with non-negative scale and rotation (for ease of testing scale and rot independently)
/// </summary>
/// <returns></returns>
private static IEnumerable TransformTestCases()
public static IEnumerable<object[]> TransformTestCases()
{
var t = new Vector3(128.128f, 255.255f, 512.512f);
var r = Quaternion.CreateFromYawPitchRoll(1.9f, 0.6666667f, 0.5f);
var s = new Vector3(123f, 32f, 0.5f);

yield return new TestCaseData(Matrix4x4.Identity).SetName("{m} Identity Matrix");
yield return [Matrix4x4.Identity];

yield return new TestCaseData(Matrix4x4.CreateTranslation(t)).SetName("{m} Translation Only (positive)");
yield return [Matrix4x4.CreateTranslation(t)];

yield return new TestCaseData(Matrix4x4.CreateTranslation(t * -Vector3.UnitX)).SetName("{m} Translation Only -X");
yield return [Matrix4x4.CreateTranslation(t * -Vector3.UnitX)];

yield return new TestCaseData(Matrix4x4.CreateTranslation(t * -Vector3.UnitY)).SetName("{m} Translation Only -Y");
yield return [Matrix4x4.CreateTranslation(t * -Vector3.UnitY)];

yield return new TestCaseData(Matrix4x4.CreateTranslation(t * -Vector3.UnitZ)).SetName("{m} Translation Only -Z");
yield return [Matrix4x4.CreateTranslation(t * -Vector3.UnitZ)];

yield return new TestCaseData(Matrix4x4.CreateTranslation(-t)).SetName("{m} Translation Only -XYZ ");
yield return [Matrix4x4.CreateTranslation(-t)];

yield return new TestCaseData(Matrix4x4.CreateFromYawPitchRoll(0.5f, 0.0f, 0.0f)).SetName("{m} Rotation Only X ");
yield return [Matrix4x4.CreateFromYawPitchRoll(0.5f, 0.0f, 0.0f)];

yield return new TestCaseData(Matrix4x4.CreateFromYawPitchRoll(0.0f, 0.5f, 0.0f)).SetName("{m} Rotation Only Y ");
yield return [Matrix4x4.CreateFromYawPitchRoll(0.0f, 0.5f, 0.0f)];

yield return new TestCaseData(Matrix4x4.CreateFromYawPitchRoll(0.0f, 0.0f, 0.5f)).SetName("{m} Rotation Only Z ");
yield return [Matrix4x4.CreateFromYawPitchRoll(0.0f, 0.0f, 0.5f)];

yield return new TestCaseData(Matrix4x4.CreateFromYawPitchRoll(0.5f, 0.5f, 0.5f)).SetName("{m} Rotation Only XYZ ");
yield return [Matrix4x4.CreateFromYawPitchRoll(0.5f, 0.5f, 0.5f)];

yield return new TestCaseData(Matrix4x4.CreateFromQuaternion(r)).SetName("{m} Rotation Only");
yield return [Matrix4x4.CreateFromQuaternion(r)];

yield return new TestCaseData(Matrix4x4.Identity + Matrix4x4.CreateScale(s)).SetName("{m} Scale Only");
yield return [Matrix4x4.Identity + Matrix4x4.CreateScale(s)];

yield return new TestCaseData(Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r)).SetName(
"{m} Translation + Rotation"
);
yield return [Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r)];

yield return new TestCaseData(
Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r) + Matrix4x4.CreateScale(s)
).SetName("{m} Translation + Rotation + Scale");
yield return [Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r) + Matrix4x4.CreateScale(s)];

yield return new TestCaseData(
Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r) + Matrix4x4.CreateScale(-s)
).SetName("{m} Translation + Rotation + -Scale");
yield return [Matrix4x4.CreateTranslation(t) + Matrix4x4.CreateFromQuaternion(r) + Matrix4x4.CreateScale(-s)];
}
}
Loading
Loading