public void UnitMc_GetRowsForPicksC() { var expect = new int[][] { new int[] { 0 }, new int[] { 1 }, new int[] { 0, 0 }, new int[] { 0, 1 }, new int[] { 1, 1 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 1 }, new int[] { 0, 1, 1 }, new int[] { 1, 1, 1 } }; long startRank = 1; var mc0 = new Multicombination(2, 3, startRank); var beginData = new int[mc0.Picks]; mc0.CopyTo(beginData); int actualCount = 0; foreach (Multicombination mc in mc0.GetRowsForPicks(1, 3)) { Assert.IsTrue(Enumerable.SequenceEqual(expect[actualCount], mc)); Assert.IsTrue(Enumerable.SequenceEqual(mc, mc0)); ++actualCount; } Assert.AreEqual(expect.Length, actualCount); Assert.AreEqual(startRank, mc0.Rank); Assert.IsTrue(Enumerable.SequenceEqual(beginData, mc0)); }
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)); }
public void CrashMc_CopyTo_Argument() { Multicombination mc = new Multicombination(3, 3, 4); int[] nullTarget = new int[2]; mc.CopyTo(nullTarget); }
public void StressMc_Ctor2B() { // Use higher maxChoices values for a longer running test. #if STRESS const int maxChoices = 7; #else const int maxChoices = 4; #endif int counter = 0; for (int choices = 1; choices <= maxChoices; ++choices) { for (int picks = 0; picks <= choices + 2; ++picks) { long maxRank = picks == 0 ? 0 : Combinatoric.BinomialCoefficient(picks + choices - 1, picks); for (long rank = 0; rank < maxRank; ++rank) { Multicombination row1 = new Multicombination(choices, picks, rank); int[] source = new int[picks]; row1.CopyTo(source); Multicombination row2 = new Multicombination(choices, source); // verify that rank(unrank(x)) = x Assert.AreEqual(rank, row1.Rank); Assert.AreEqual(rank, row2.Rank); ++counter; } } } }
public void UnitMc_CopyTo1() { Multicombination mc3 = new Multicombination(3, 3, 4); int[] target = new int[3]; mc3.CopyTo(target); Assert.AreEqual(0, target[0]); Assert.AreEqual(1, target[1]); Assert.AreEqual(2, target[2]); }