diff --git a/src/UnitTests/NumberTheoryTests/GcdRelatedTest.cs b/src/UnitTests/NumberTheoryTests/GcdRelatedTest.cs index b839bb34..caad8985 100644 --- a/src/UnitTests/NumberTheoryTests/GcdRelatedTest.cs +++ b/src/UnitTests/NumberTheoryTests/GcdRelatedTest.cs @@ -64,6 +64,21 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests Assert.AreEqual(1 << 18, IntegerTheory.GreatestCommonDivisor(1 << 18, 1 << 20), "Gcd(1>>18,1<<20)"); } + [Test] + public void ExtendedGcdHandlesNormalInputCorrectly() + { + long x, y; + + Assert.AreEqual(3, IntegerTheory.ExtendedGreatestCommonDivisor(6, 15, out x, out y), "Egcd(6,15)"); + Assert.AreEqual(3, 6 * x + 15 * y, "Egcd(6,15) -> a*x+b*y"); + + Assert.AreEqual(3, IntegerTheory.ExtendedGreatestCommonDivisor(-6, 15, out x, out y), "Egcd(-6,15)"); + Assert.AreEqual(3, -6 * x + 15 * y, "Egcd(-6,15) -> a*x+b*y"); + + Assert.AreEqual(3, IntegerTheory.ExtendedGreatestCommonDivisor(-6, -15, out x, out y), "Egcd(-6,-15)"); + Assert.AreEqual(3, -6 * x + -15 * y, "Egcd(-6,-15) -> a*x+b*y"); + } + [Test] public void ListGcdHandlesNormalInputCorrectly() { @@ -81,6 +96,14 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests Assert.AreEqual(100, IntegerTheory.GreatestCommonDivisor(-100), "Gcd(-100)"); } + [Test] + public void ListGcdChecksForNullArguments() + { + Assert.Throws( + typeof (ArgumentNullException), + () => IntegerTheory.GreatestCommonDivisor(null)); + } + [Test] public void LcmHandlesNormalInputCorrectly() { @@ -127,5 +150,13 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests Assert.AreEqual(1, IntegerTheory.LeastCommonMultiple(), "Lcm()"); Assert.AreEqual(100, IntegerTheory.LeastCommonMultiple(-100), "Lcm(-100)"); } + + [Test] + public void ListLcmChecksForNullArguments() + { + Assert.Throws( + typeof(ArgumentNullException), + () => IntegerTheory.LeastCommonMultiple(null)); + } } }