diff --git a/X10D.Tests/src/Core/ComparableTests.cs b/X10D.Tests/src/Core/ComparableTests.cs deleted file mode 100644 index 582ef40..0000000 --- a/X10D.Tests/src/Core/ComparableTests.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace X10D.Tests.Core; - -/// -/// Tests for . -/// -[TestClass] -public class ComparableTests -{ - /// - /// Tests - /// - [TestMethod] - public void Between() - { - const int lower = 5; - const int upper = 15; - const int value = 10; - - Assert.IsTrue(value.Between(lower, upper), "value.Between(lower, upper)"); - Assert.IsFalse(lower.Between(value, upper), "lower.Between(value, upper)"); - Assert.IsFalse(upper.Between(lower, value), "upper.Between(lower, value)"); - - Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.UpperInclusive), "upper.Between(lower, upper, Clusivity.UpperInclusive)"); - Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.Inclusive), "upper.Between(lower, upper, Clusivity.Inclusive)"); - Assert.IsFalse(upper.Between(lower, upper, InclusiveOptions.LowerInclusive), "upper.Between(lower, upper, Clusivity.LowerInclusive)"); - - Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.LowerInclusive), "lower.Between(lower, upper, Clusivity.LowerInclusive)"); - Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.Inclusive), "lower.Between(lower, upper, Clusivity.Inclusive)"); - Assert.IsFalse(lower.Between(lower, upper, InclusiveOptions.UpperInclusive), "lower.Between(lower, upper, Clusivity.UpperInclusive)"); - } - - /// - /// Tests - /// - [TestMethod] - public void Clamp() - { - const int lower = 5; - const int upper = 10; - const int value = 15; - - Assert.AreEqual(upper, value.Clamp(lower, upper)); - Assert.AreEqual(upper, lower.Clamp(upper, value)); - Assert.AreEqual(upper, upper.Clamp(lower, value)); - } - - /// - /// Tests - /// - [TestMethod] - public void GreaterThan() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(second.GreaterThan(first)); - Assert.IsFalse(first.GreaterThan(second)); - } - - /// - /// Tests - /// - [TestMethod] - public void GreaterThanOrEqualTo() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(second.GreaterThanOrEqualTo(first)); - Assert.IsTrue(second.GreaterThanOrEqualTo(second)); - Assert.IsTrue(first.GreaterThanOrEqualTo(first)); - Assert.IsFalse(first.GreaterThanOrEqualTo(second)); - } - - /// - /// Tests - /// - [TestMethod] - public void LessThan() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(first.LessThan(second)); - Assert.IsFalse(second.LessThan(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void LessThanOrEqualTo() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(first.LessThanOrEqualTo(second)); - Assert.IsTrue(first.LessThanOrEqualTo(first)); - Assert.IsTrue(second.LessThanOrEqualTo(second)); - Assert.IsFalse(second.LessThanOrEqualTo(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void Max() - { - const int first = 5; - const int second = 10; - - Assert.AreEqual(second, first.Max(second)); - Assert.AreEqual(second, second.Max(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void Min() - { - const int first = 5; - const int second = 10; - - Assert.AreEqual(first, first.Min(second)); - Assert.AreEqual(first, second.Min(first)); - } -} \ No newline at end of file diff --git a/X10D.Tests/src/Math/ComparableTests.cs b/X10D.Tests/src/Math/ComparableTests.cs new file mode 100644 index 0000000..dd71c7d --- /dev/null +++ b/X10D.Tests/src/Math/ComparableTests.cs @@ -0,0 +1,201 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Math; + +namespace X10D.Tests.Math; + +[TestClass] +public class ComparableTests +{ + private class ComparableTestClass : IComparable + { + public int CompareTo(ComparableTestClass? other) + { + return 0; + } + } + + private readonly int _lower = 1; + private readonly int _upper = 10; + private readonly int _value = 5; + + [TestMethod] + public void Between_5_1_10_ShouldBeTrue() + { + Assert.IsTrue(_value.Between(_lower, _upper)); + } + + [TestMethod] + public void Between_1_1_10_ShouldBeFalse() + { + // default option is exclusive + Assert.IsFalse(_lower.Between(_lower, _upper)); + } + + [TestMethod] + public void Between_1_1_10_Inclusive_ShouldBeTrue() + { + Assert.IsTrue(_lower.Between(_lower, _upper, InclusiveOptions.Inclusive)); + Assert.IsTrue(_lower.Between(_lower, _upper, InclusiveOptions.LowerInclusive)); + Assert.IsFalse(_lower.Between(_lower, _upper, InclusiveOptions.UpperInclusive)); + } + + [TestMethod] + public void Between_10_1_10_ShouldBeFalse() + { + // default option is exclusive + Assert.IsFalse(_upper.Between(_lower, _upper)); + } + + [TestMethod] + public void Between_10_1_10_Inclusive_ShouldBeTrue() + { + Assert.IsTrue(_upper.Between(_lower, _upper, InclusiveOptions.Inclusive)); + Assert.IsTrue(_upper.Between(_lower, _upper, InclusiveOptions.UpperInclusive)); + Assert.IsFalse(_upper.Between(_lower, _upper, InclusiveOptions.LowerInclusive)); + } + + [TestMethod] + public void Between_1_10_5_ShouldThrow() + { + Assert.ThrowsException(() => _lower.Between(_upper, _value)); + } + + [TestMethod] + public void Between_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => ((ComparableTestClass?)null)!.Between(nullPointer!, nullPointer!)); + } + + [TestMethod] + public void Clamp_3_1_5_ShouldBe3() + { + Assert.AreEqual(3, 3.Clamp(1, 5)); + } + + [TestMethod] + public void Clamp_10_1_5_ShouldBe5() + { + Assert.AreEqual(5, 10.Clamp(1, 5)); + } + + [TestMethod] + public void Clamp_n_6_5_ShouldThrow() + { + Assert.ThrowsException(() => 0.Clamp(6, 5)); + } + + [TestMethod] + public void GreaterThan_5_6_ShouldBeFalse() + { + Assert.IsFalse(5.GreaterThan(6)); + } + + [TestMethod] + public void GreaterThan_6_5_ShouldBeTrue() + { + Assert.IsTrue(6.GreaterThan(5)); + } + + [TestMethod] + public void GreaterThan_5_5_ShouldBeFalse() + { + Assert.IsFalse(5.LessThan(5)); + } + + [TestMethod] + public void GreaterThan_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.GreaterThan(nullPointer!)); + } + + [TestMethod] + public void GreaterThanOrEqualTo_5_5_ShouldBeTrue() + { + Assert.IsTrue(5.GreaterThanOrEqualTo(5)); + } + + [TestMethod] + public void GreaterThanOrEqualTo_6_5_ShouldBeTrue() + { + Assert.IsTrue(6.GreaterThanOrEqualTo(5)); + } + + [TestMethod] + public void GreaterThanOrEqualTo_5_6_ShouldBeFalse() + { + Assert.IsFalse(5.GreaterThanOrEqualTo(6)); + } + + [TestMethod] + public void GreaterThanOrEqualTo_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.GreaterThanOrEqualTo(nullPointer!)); + } + + [TestMethod] + public void LessThan_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.LessThan(nullPointer!)); + } + + [TestMethod] + public void LessThan_6_5_ShouldBeFalse() + { + Assert.IsFalse(6.LessThan(5)); + } + + [TestMethod] + public void LessThan_5_6_ShouldBeTrue() + { + Assert.IsTrue(5.LessThan(6)); + } + + [TestMethod] + public void LessThan_5_5_ShouldBeFalse() + { + Assert.IsFalse(5.LessThan(5)); + } + + [TestMethod] + public void LessThanOrEqualTo_5_5_ShouldBeTrue() + { + Assert.IsTrue(5.LessThanOrEqualTo(5)); + } + + [TestMethod] + public void LessThanOrEqualTo_5_6_ShouldBeTrue() + { + Assert.IsTrue(5.LessThanOrEqualTo(6)); + } + + [TestMethod] + public void LessThanOrEqualTo_6_5_ShouldBeFalse() + { + Assert.IsFalse(6.LessThanOrEqualTo(5)); + } + + [TestMethod] + public void LessThanOrEqualTo_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.LessThanOrEqualTo(nullPointer!)); + } + + [TestMethod] + public void Max_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.Max(nullPointer!)); + } + + [TestMethod] + public void Min_Null_ShouldThrow() + { + ComparableTestClass? nullPointer = null; + Assert.ThrowsException(() => nullPointer!.Min(nullPointer!)); + } +} diff --git a/X10D/src/ComparableExtensions/ComparableExtensions.cs b/X10D/src/Math/ComparableExtensions.cs similarity index 99% rename from X10D/src/ComparableExtensions/ComparableExtensions.cs rename to X10D/src/Math/ComparableExtensions.cs index cc12eb2..a382ba4 100644 --- a/X10D/src/ComparableExtensions/ComparableExtensions.cs +++ b/X10D/src/Math/ComparableExtensions.cs @@ -1,6 +1,6 @@ using System.Globalization; -namespace X10D; +namespace X10D.Math; /// /// Extension methods for . diff --git a/X10D/src/ComparableExtensions/InclusiveOptions.cs b/X10D/src/Math/InclusiveOptions.cs similarity index 93% rename from X10D/src/ComparableExtensions/InclusiveOptions.cs rename to X10D/src/Math/InclusiveOptions.cs index 9c00810..1c78197 100644 --- a/X10D/src/ComparableExtensions/InclusiveOptions.cs +++ b/X10D/src/Math/InclusiveOptions.cs @@ -1,7 +1,7 @@ -namespace X10D; +namespace X10D.Math; /// -/// Provides options for clusivity. +/// Provides options for clusivity. /// [Flags] public enum InclusiveOptions : byte