|
|
@ -64,6 +64,21 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests |
|
|
Assert.AreEqual(1 << 18, IntegerTheory.GreatestCommonDivisor(1 << 18, 1 << 20), "Gcd(1>>18,1<<20)"); |
|
|
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] |
|
|
[Test] |
|
|
public void ListGcdHandlesNormalInputCorrectly() |
|
|
public void ListGcdHandlesNormalInputCorrectly() |
|
|
{ |
|
|
{ |
|
|
@ -81,6 +96,14 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests |
|
|
Assert.AreEqual(100, IntegerTheory.GreatestCommonDivisor(-100), "Gcd(-100)"); |
|
|
Assert.AreEqual(100, IntegerTheory.GreatestCommonDivisor(-100), "Gcd(-100)"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
public void ListGcdChecksForNullArguments() |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.Throws( |
|
|
|
|
|
typeof (ArgumentNullException), |
|
|
|
|
|
() => IntegerTheory.GreatestCommonDivisor(null)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Test] |
|
|
[Test] |
|
|
public void LcmHandlesNormalInputCorrectly() |
|
|
public void LcmHandlesNormalInputCorrectly() |
|
|
{ |
|
|
{ |
|
|
@ -127,5 +150,13 @@ namespace MathNet.Numerics.UnitTests.NumberTheoryTests |
|
|
Assert.AreEqual(1, IntegerTheory.LeastCommonMultiple(), "Lcm()"); |
|
|
Assert.AreEqual(1, IntegerTheory.LeastCommonMultiple(), "Lcm()"); |
|
|
Assert.AreEqual(100, IntegerTheory.LeastCommonMultiple(-100), "Lcm(-100)"); |
|
|
Assert.AreEqual(100, IntegerTheory.LeastCommonMultiple(-100), "Lcm(-100)"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
public void ListLcmChecksForNullArguments() |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.Throws( |
|
|
|
|
|
typeof(ArgumentNullException), |
|
|
|
|
|
() => IntegerTheory.LeastCommonMultiple(null)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|