diff --git a/src/Numerics/Combinatorics.cs b/src/Numerics/Combinatorics.cs index 1c9f52d6..f7178aaf 100644 --- a/src/Numerics/Combinatorics.cs +++ b/src/Numerics/Combinatorics.cs @@ -48,7 +48,7 @@ namespace MathNet.Numerics return 0; } - throw new NotImplementedException(); + return Math.Floor(0.5 + Math.Exp(SpecialFunctions.FactorialLn(n) - SpecialFunctions.FactorialLn(n - k))); } /// @@ -67,4 +67,4 @@ namespace MathNet.Numerics return Math.Pow(n, k); } } -} +} \ No newline at end of file diff --git a/src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs b/src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs index fa99763d..9733646b 100644 --- a/src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs +++ b/src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs @@ -33,7 +33,7 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests [TestFixture] public class CombinatoricsCountingTest { - [Test, Ignore("Depending on Special Functions")] + [Test] [Row(0, 0, 1)] [Row(1, 0, 1)] [Row(10, 0, 1)] @@ -44,7 +44,10 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests [Row(10, 10, 3628800)] public void CanCountVariations(int n, int k, long expected) { - Assert.AreEqual(expected, Combinatorics.Variations(n, k), "Count the number of variations without repetition"); + Assert.AreEqual( + expected, + Combinatorics.Variations(n, k), + "Count the number of variations without repetition"); } [Test] @@ -56,7 +59,10 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests [Row(-1, 1)] public void OutOfRangeVariationsMustCountToZero(int n, int k) { - Assert.AreEqual(0, Combinatorics.Variations(n, k), "The number of variations without repetition but out of the range must be 0."); + Assert.AreEqual( + 0, + Combinatorics.Variations(n, k), + "The number of variations without repetition but out of the range must be 0."); } [Test] @@ -71,7 +77,10 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests [Row(10, 11, 100000000000)] public void CanCountVariationsWithRepetition(int n, int k, long expected) { - Assert.AreEqual(expected, Combinatorics.VariationsWithRepetition(n, k), "Count the number of variations with repetition"); + Assert.AreEqual( + expected, + Combinatorics.VariationsWithRepetition(n, k), + "Count the number of variations with repetition"); } [Test] @@ -82,7 +91,10 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests [Row(-1, 1)] public void OutOfRangeVariationsWithRepetitionMustCountToZero(int n, int k) { - Assert.AreEqual(0, Combinatorics.VariationsWithRepetition(n, k), "The number of variations with repetition but out of the range must be 0."); + Assert.AreEqual( + 0, + Combinatorics.VariationsWithRepetition(n, k), + "The number of variations with repetition but out of the range must be 0."); } } -} +} \ No newline at end of file