From 3bdca006b8d79c707c2892c777be0bdaee506285 Mon Sep 17 00:00:00 2001 From: tacosontitan Date: Sat, 20 Jul 2024 22:11:45 -0500 Subject: [PATCH] Added support for multiplication functions. --- src/Hussy.Net/Math/Multiplication.cs | 139 ++++++++++++++++++ .../Math/MultiplicationTests.cs | 58 ++++++++ 2 files changed, 197 insertions(+) create mode 100644 src/Hussy.Net/Math/Multiplication.cs create mode 100644 test/Hussy.Net.Tests/Math/MultiplicationTests.cs diff --git a/src/Hussy.Net/Math/Multiplication.cs b/src/Hussy.Net/Math/Multiplication.cs new file mode 100644 index 0000000..1700d9c --- /dev/null +++ b/src/Hussy.Net/Math/Multiplication.cs @@ -0,0 +1,139 @@ +/* + Copyright 2024 tacosontitan and contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.Numerics; + +namespace Hussy.Net; + +public static partial class Hussy +{ + /// + /// Multiplies 2 by the specified . + /// + /// The input to multiply 2 by. + /// Specifies the type of . + /// + /// The specified decremented by 2. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult2(T input) + where T : IMultiplyOperators => + input * 2.To(); + + /// + /// Multiplies 3 by the specified . + /// + /// The input to multiply 3 by. + /// Specifies the type of . + /// + /// The specified decremented by 3. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult3(T input) + where T : IMultiplyOperators => + input * 3.To(); + + /// + /// Multiplies 4 by the specified . + /// + /// The input to multiply 4 by. + /// Specifies the type of . + /// + /// The specified decremented by 4. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult4(T input) + where T : IMultiplyOperators => + input * 4.To(); + + /// + /// Multiplies 5 by the specified . + /// + /// The input to multiply 5 by. + /// Specifies the type of . + /// + /// The specified decremented by 5. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult5(T input) + where T : IMultiplyOperators => + input * 5.To(); + + /// + /// Multiplies 6 by the specified . + /// + /// The input to multiply 6 by. + /// Specifies the type of . + /// + /// The specified decremented by 6. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult6(T input) + where T : IMultiplyOperators => + input * 6.To(); + + /// + /// Multiplies 7 by the specified . + /// + /// The input to multiply 7 by. + /// Specifies the type of . + /// + /// The specified decremented by 7. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult7(T input) + where T : IMultiplyOperators => + input * 7.To(); + + /// + /// Multiplies 8 by the specified . + /// + /// The input to multiply 1 by. + /// Specifies the type of . + /// + /// The specified decremented by 8. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult8(T input) + where T : IMultiplyOperators => + input * 8.To(); + + /// + /// Multiplies 9 by the specified . + /// + /// The input to multiply 9 by. + /// Specifies the type of . + /// + /// The specified decremented by 9. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult9(T input) + where T : IMultiplyOperators => + input * 9.To(); + + /// + /// Multiplies 10 by the specified . + /// + /// The input to multiply 10 by. + /// Specifies the type of . + /// + /// The specified decremented by 10. + /// + /// This method is designed to shorten functions being passed as delegates. + public static T Mult10(T input) + where T : IMultiplyOperators => + input * 10.To(); +} \ No newline at end of file diff --git a/test/Hussy.Net.Tests/Math/MultiplicationTests.cs b/test/Hussy.Net.Tests/Math/MultiplicationTests.cs new file mode 100644 index 0000000..36e4f65 --- /dev/null +++ b/test/Hussy.Net.Tests/Math/MultiplicationTests.cs @@ -0,0 +1,58 @@ +/* + Copyright 2024 tacosontitan and contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +namespace Hussy.Net.Tests.Math; + +public class MultiplicationTests +{ + private const double TestValue = 2; + + [Theory] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + public void Multiplication_ProducesCorrectResult(double target) + { + var expectedResult = TestValue * target; + var testFunction = GetFunction(target); + var actualResult = testFunction(TestValue); + + Assert.Equal(expectedResult, actualResult); + +#pragma warning disable CS8509 // The switch expression does not handle all possible values of its input type (it is not exhaustive). + + static Func GetFunction(double target) => target switch + { + 2 => Mult2, + 3 => Mult3, + 4 => Mult4, + 5 => Mult5, + 6 => Mult6, + 7 => Mult7, + 8 => Mult8, + 9 => Mult9, + 10 => Mult10 + }; + +#pragma warning restore CS8509 // The switch expression does not handle all possible values of its input type (it is not exhaustive). + } +} \ No newline at end of file