コード例 #1
0
        public void UnitMc_GetRows()
        {
            var expect = new int[][]
            {
                new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 1 }, new int[] { 0, 0, 0, 2 },
                new int[] { 0, 0, 1, 1 }, new int[] { 0, 0, 1, 2 }, new int[] { 0, 0, 2, 2 },
                new int[] { 0, 1, 1, 1 }, new int[] { 0, 1, 1, 2 }, new int[] { 0, 1, 2, 2 },
                new int[] { 0, 2, 2, 2 }, new int[] { 1, 1, 1, 1 }, new int[] { 1, 1, 1, 2 },
                new int[] { 1, 1, 2, 2 }, new int[] { 1, 2, 2, 2 }, new int[] { 2, 2, 2, 2 }
            };

            long startRank = 2;
            var  mc0       = new Multicombination(3, 4, startRank);

            Assert.AreEqual(expect.Length, mc0.RowCount);
            var beginData = new int[4];

            mc0.CopyTo(beginData);

            int actualCount = 0;

            foreach (Multicombination mc in mc0.GetRows())
            {
                long expectRank = (actualCount + startRank) % expect.Length;
                Assert.AreEqual(expectRank, mc.Rank);
                Assert.AreEqual(expectRank, mc0.Rank);
                Assert.IsTrue(Enumerable.SequenceEqual(expect[expectRank], mc));
                Assert.IsTrue(Enumerable.SequenceEqual(mc, mc0));
                ++actualCount;
            }

            Assert.AreEqual(expect.Length, actualCount);
            Assert.AreEqual(startRank, mc0.Rank);
            Assert.IsTrue(Enumerable.SequenceEqual(beginData, mc0));
        }
コード例 #2
0
        public void UnitMc_GetRows0Empty()
        {
            Multicombination mc = new Multicombination();

            foreach (Multicombination row in mc.GetRows())
            {
                Assert.Fail("Empty multicombo iterates");
            }
        }
コード例 #3
0
        static void Main()
        {
            var mc = new Multicombination(choices: 4, picks: 3);

            Console.WriteLine($"n={mc.Choices}, k={mc.Picks}:\n");

            foreach (var row in mc.GetRows())
            {
                Console.WriteLine($"{row.Rank,2}:  {row}");
            }
        }