Accord.Tests.Math.CombinatoricsTest.PermutationsTest C# (CSharp) Method

PermutationsTest() private method

private PermutationsTest ( ) : void
return void
        public void PermutationsTest()
        {
            // Let's say we would like to generate all possible permutations
            // of the elements (1, 2, 3). In order to enumerate all those
            // permutations, we can use:

            int[] values = { 1, 2, 3 };

            List<int[]> permutations = new List<int[]>();
            foreach (var p in Combinatorics.Permutations(values))
                permutations.Add(p);

            Assert.AreEqual(6, permutations.Count);
            Assert.IsTrue(permutations[0].IsEqual(new[] { 1, 2, 3 }));
            Assert.IsTrue(permutations[1].IsEqual(new[] { 1, 3, 2 }));
            Assert.IsTrue(permutations[2].IsEqual(new[] { 2, 1, 3 }));
            Assert.IsTrue(permutations[3].IsEqual(new[] { 2, 3, 1 }));
            Assert.IsTrue(permutations[4].IsEqual(new[] { 3, 1, 2 }));
            Assert.IsTrue(permutations[5].IsEqual(new[] { 3, 2, 1 }));
        }