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

CombinationsTest() private method

private CombinationsTest ( ) : void
return void
        public void CombinationsTest()
        {
            // Let's say we would like to generate all possible combinations
            // of length 2 containing the elements (1, 2, 3). To enumerate all
            // those combinations, we can use:

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

            List<int[]> combinations = new List<int[]>();
            foreach (var p in Combinatorics.Combinations(values, length))
                combinations.Add(p);

            Assert.AreEqual(3, combinations.Count);
            Assert.IsTrue(combinations[0].IsEqual(new[] { 1, 2 }));
            Assert.IsTrue(combinations[1].IsEqual(new[] { 1, 3 }));
            Assert.IsTrue(combinations[2].IsEqual(new[] { 2, 3 }));
        }
    }