feat: Added mod method to MathUtils

This commit is contained in:
Chris Cameron
2019-09-09 10:06:08 -04:00
parent b09f614ef5
commit 45ee3e70b0
4 changed files with 29 additions and 7 deletions

View File

@@ -1,14 +1,13 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Tests
{
[TestFixture, UsedImplicitly]
[TestFixture]
public sealed class MathUtilsTest
{
[Test, UsedImplicitly]
[Test]
public void ClampTest()
{
Assert.AreEqual(MathUtils.Clamp(-10, 0, 0), 0);
@@ -24,7 +23,7 @@ namespace ICD.Common.Utils.Tests
Assert.AreEqual(MathUtils.Clamp(20, 10, 10), 10);
}
[Test, UsedImplicitly]
[Test]
public void MapRangeTest()
{
Assert.AreEqual(5, MathUtils.MapRange(-100, 100, 0, 10, 0));
@@ -40,7 +39,7 @@ namespace ICD.Common.Utils.Tests
Assert.AreEqual(100, MathUtils.MapRange(0, 10, 0, 100, 10));
}
[Test, UsedImplicitly]
[Test]
public void GetRangesTest()
{
IEnumerable<int> values = new [] { 1, 3, 5, 6, 7, 8, 9, 10, 12 };
@@ -61,11 +60,21 @@ namespace ICD.Common.Utils.Tests
Assert.AreEqual(12, ranges[3][1]);
}
[Test, UsedImplicitly]
[Test]
public void RoundToNearestTest()
{
IEnumerable<int> values = new [] { 0, 15, 30, 45 };
Assert.AreEqual(15, MathUtils.RoundToNearest(21, values));
}
[TestCase(10, 10, 0)]
[TestCase(-10, 10, 0)]
[TestCase(9, 3, 0)]
[TestCase(3, 2, 1)]
[TestCase(-3, 2, 1)]
public void ModTest(int value, int mod, int expected)
{
Assert.AreEqual(expected, MathUtils.Mod(value, mod));
}
}
}