From 63b8fbc187b325b7a37fc3a4f62eb7ae3ebbca76 Mon Sep 17 00:00:00 2001 From: Daniel Sword Date: Mon, 19 Nov 2018 20:10:15 -0800 Subject: [PATCH] Combinatorics: add tests for generated permutations. --- .../CombinatoricsTests/PermutationTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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)