diff --git a/src/Numerics.Tests/CombinatoricsTests/PermutationTests.cs b/src/Numerics.Tests/CombinatoricsTests/PermutationTests.cs index 67d1f4a2..eb0e73ab 100644 --- a/src/Numerics.Tests/CombinatoricsTests/PermutationTests.cs +++ b/src/Numerics.Tests/CombinatoricsTests/PermutationTests.cs @@ -25,6 +25,20 @@ namespace MathNet.Numerics.Tests.CombinatoricsTests } } + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public void NumberOfPermutationsGeneratedMatchesNFactorial(int n) + { + // See the xml comment on lazy enumeration danger. + var permutations = Combinatorics.GenerateAllPermutations(n).Select(pi => pi.AsEnumerable().ToArray()).ToArray(); + var count = permutations.Distinct(_comparer).Count(); + var expected = Combinatorics.Permutations(n); + Assert.AreEqual(expected,count); + } + [TestCase(2,5,0,1,4,3)] public void InversePermutationInverts(params int[] permutation)