diff --git a/ICD.Common.Utils.Tests/Attributes/RangeAttributeTest.cs b/ICD.Common.Utils.Tests/Attributes/RangeAttributeTest.cs index 45c5a13..c53793f 100644 --- a/ICD.Common.Utils.Tests/Attributes/RangeAttributeTest.cs +++ b/ICD.Common.Utils.Tests/Attributes/RangeAttributeTest.cs @@ -46,6 +46,37 @@ namespace ICD.Common.Utils.Tests.Attributes Assert.AreEqual(expected, RangeAttribute.RemapFromDouble(value, type)); } + [TestCase(short.MinValue, typeof(ushort), ushort.MinValue)] + [TestCase(short.MaxValue, typeof(ushort), short.MaxValue)] + public static void Clamp(object value, Type type, object expected) + { + Assert.AreEqual(expected, RangeAttribute.Clamp(value, type)); + } + + [TestCase(double.MinValue, typeof(ushort), ushort.MinValue)] + [TestCase(double.MaxValue, typeof(ushort), ushort.MaxValue)] + public void Clamp(double value, Type type, double expected) + { + Assert.AreEqual(expected, RangeAttribute.Clamp(value, type)); + } + + [TestCase(short.MinValue, typeof(ushort), ushort.MinValue)] + [TestCase(short.MaxValue, typeof(ushort), ushort.MaxValue)] + public void RemapTest(object value, Type type, object expected) + { + Assert.AreEqual(expected, RangeAttribute.Remap(value, type)); + } + + public void ClampMinMaxThenRemapTest(object min, object max, object value, Type type, object expected) + { + Assert.AreEqual(expected, new RangeAttribute(min, max).ClampMinMaxThenRemap(value, type)); + } + + public void RemapMinMaxTest(object min, object max, object value, object expected) + { + Assert.AreEqual(expected, new RangeAttribute(min, max).RemapMinMax(value)); + } + #endregion } } diff --git a/ICD.Common.Utils/Attributes/RangeAttribute.cs b/ICD.Common.Utils/Attributes/RangeAttribute.cs index 7220488..ac304f5 100644 --- a/ICD.Common.Utils/Attributes/RangeAttribute.cs +++ b/ICD.Common.Utils/Attributes/RangeAttribute.cs @@ -385,9 +385,7 @@ namespace ICD.Common.Utils.Attributes throw new ArgumentException("Source value is not numeric"); double intermediate = RemapToDouble(value); - object remapped = RemapFromDouble(intermediate, type); - - return Convert.ChangeType(remapped, value.GetType(), CultureInfo.InvariantCulture); + return RemapFromDouble(intermediate, type); } ///