1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:58:48 +00:00

[ci skip] Add unit tests for ScaleRange

Add Aggressive implementations, and annotate as Pure
This commit is contained in:
Oliver Booth 2023-02-26 13:33:01 +00:00
parent 81f1a7c1e0
commit d1454a1170
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
2 changed files with 26 additions and 0 deletions

View File

@ -83,4 +83,18 @@ public class MathUtilityTests
Assert.AreEqual(1.0, doubleResult); Assert.AreEqual(1.0, doubleResult);
Assert.AreEqual(1.0f, floatResult); Assert.AreEqual(1.0f, floatResult);
} }
[TestMethod]
public void ScaleRangeDouble_ShouldScaleRange_GivenItsValues()
{
double result = MathUtility.ScaleRange(0.5, 0.0, 1.0, 5.0, 10.0);
Assert.AreEqual(7.5, result);
}
[TestMethod]
public void ScaleRangeSingle_ShouldScaleRange_GivenItsValues()
{
float result = MathUtility.ScaleRange(0.5f, 0.0f, 1.0f, 5.0f, 10.0f);
Assert.AreEqual(7.5f, result);
}
} }

View File

@ -244,6 +244,12 @@ public static class MathUtility
/// <param name="newMin">The new minimum value.</param> /// <param name="newMin">The new minimum value.</param>
/// <param name="newMax">The new maximum value.</param> /// <param name="newMax">The new maximum value.</param>
/// <returns>The scaled value.</returns> /// <returns>The scaled value.</returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax) public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax)
{ {
float oldRange = oldMax - oldMin; float oldRange = oldMax - oldMin;
@ -261,6 +267,12 @@ public static class MathUtility
/// <param name="newMin">The new minimum value.</param> /// <param name="newMin">The new minimum value.</param>
/// <param name="newMax">The new maximum value.</param> /// <param name="newMax">The new maximum value.</param>
/// <returns>The scaled value.</returns> /// <returns>The scaled value.</returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax) public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax)
{ {
double oldRange = oldMax - oldMin; double oldRange = oldMax - oldMin;