public void UnitCn_GetRowsForAllPicks() { var expect = new int[][] { new int[] { 0 }, new int[] { 1 }, new int[] { 2 }, new int[] { 3 }, new int[] { 0, 1 }, new int[] { 0, 2 }, new int[] { 0, 3 }, new int[] { 1, 2 }, new int[] { 1, 3 }, new int[] { 2, 3 } }; long startRank = 5; var cn0 = new Combination(4, 2, startRank); var beginData = new int[cn0.Picks]; cn0.CopyTo(beginData); int actualCount = 0; foreach (Combination cn in cn0.GetRowsForAllPicks()) { Assert.IsTrue(Enumerable.SequenceEqual(expect[actualCount], cn)); Assert.IsTrue(Enumerable.SequenceEqual(cn, cn0)); ++actualCount; } Assert.AreEqual(expect.Length, actualCount); Assert.AreEqual(startRank, cn0.Rank); Assert.IsTrue(Enumerable.SequenceEqual(beginData, cn0)); }
public void UnitCn_GetRows() { var expect = new int[][] { new int[] { 0, 1, 2 }, new int[] { 0, 1, 3 }, new int[] { 0, 1, 4 }, new int[] { 0, 2, 3 }, new int[] { 0, 2, 4 }, new int[] { 0, 3, 4 }, new int[] { 1, 2, 3 }, new int[] { 1, 2, 4 }, new int[] { 1, 3, 4 }, new int[] { 2, 3, 4 } }; long startRank = 2; var cn0 = new Combination(5, 3, startRank); Assert.AreEqual(expect.Length, cn0.RowCount); var beginData = new int[3]; cn0.CopyTo(beginData); long actualCount = 0; foreach (Combination cn in cn0.GetRows()) { long expectRank = (actualCount + startRank) % expect.Length; Assert.AreEqual(expectRank, cn.Rank); Assert.AreEqual(expectRank, cn0.Rank); Assert.IsTrue(Enumerable.SequenceEqual(expect[cn.Rank], cn)); Assert.IsTrue(Enumerable.SequenceEqual(cn, cn0)); ++actualCount; } Assert.AreEqual(expect.Length, actualCount); Assert.AreEqual(startRank, cn0.Rank); Assert.IsTrue(Enumerable.SequenceEqual(beginData, cn0)); }
public void CrashCn_CopyTo_Argument() { Combination cn = new Combination(3, 3, 4); int[] nullTarget = new int[2]; cn.CopyTo(nullTarget); }
public void StressCn_Ctor2B() { // Use higher maxChoices values for a longer running test. #if STRESS const int maxChoices = 16; #else const int maxChoices = 5; #endif int counter = 0; for (int choices = 0; choices <= maxChoices; ++choices) { for (int picks = 0; picks <= choices; ++picks) { long maxRows = Combinatoric.BinomialCoefficient(choices, picks); for (int rank = 0; rank < maxRows; ++rank) { Combination row1 = new Combination(choices, picks, rank); int[] source = new int[picks]; row1.CopyTo(source); Combination row2 = new Combination(choices, source); // verify that rank(unrank(x)) = x Assert.AreEqual(rank, row1.Rank); Assert.AreEqual(rank, row2.Rank); ++counter; } } } }
public void UnitCn_CopyTo1() { Combination cn3 = new Combination(3, 3, 4); int[] target = new int[3]; cn3.CopyTo(target); Assert.AreEqual(0, target[0]); Assert.AreEqual(1, target[1]); Assert.AreEqual(2, target[2]); }