mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Added mod method to MathUtils
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user