Add testing for B-spline edge cases

This commit is contained in:
Bartłomiej Dach
2023-11-16 15:01:35 +09:00
parent 8112e93430
commit d4808ee3b0

View File

@@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Utils;
using osuTK;
@@ -40,5 +42,24 @@ namespace osu.Framework.Tests.MathUtils
Assert.True(Precision.AlmostEquals(approximated[28], points[6], 1e-4f));
Assert.True(Precision.AlmostEquals(approximated[10], new Vector2(-0.11415f, -0.69065f), 1e-4f));
}
[Test]
public void TestBSplineThrowsOnInvalidDegree()
{
Vector2[] points = { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, -1), new Vector2(-1, -1), new Vector2(-1, 1), new Vector2(3, 2), new Vector2(3, 0) };
Assert.Throws<ArgumentOutOfRangeException>(() => PathApproximator.BSplineToPiecewiseLinear(points, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => PathApproximator.BSplineToPiecewiseLinear(points, -5));
}
[TestCase(0)]
[TestCase(1)]
public void TestBSplineDoesNothingWhenGivenTooFewPoints(int pointCount)
{
var points = Enumerable.Repeat(new Vector2(), pointCount).ToArray();
Assert.That(PathApproximator.BSplineToPiecewiseLinear(points, 3), Is.EquivalentTo(points));
Assert.That(PathApproximator.BezierToPiecewiseLinear(points), Is.EquivalentTo(points));
}
}
}