Extending the validity range of the check.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1517338 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2013-08-25 17:06:55 +00:00
parent ad35857d0f
commit 5151780b34
1 changed files with 7 additions and 5 deletions

View File

@ -379,6 +379,9 @@ public class CombinatoricsUtilsTest {
combinationsIterator = CombinatoricsUtils.combinationsIterator(0, 0); combinationsIterator = CombinatoricsUtils.combinationsIterator(0, 0);
checkIterator(combinationsIterator, 0, 0); checkIterator(combinationsIterator, 0, 0);
combinationsIterator = CombinatoricsUtils.combinationsIterator(4, 2); combinationsIterator = CombinatoricsUtils.combinationsIterator(4, 2);
checkIterator(combinationsIterator, 4, 2);
combinationsIterator = CombinatoricsUtils.combinationsIterator(123, 2);
checkIterator(combinationsIterator, 123, 2);
} }
/** /**
@ -386,8 +389,6 @@ public class CombinatoricsUtilsTest {
* increasing sequence of b(n,k) arrays, each having length k * increasing sequence of b(n,k) arrays, each having length k
* and each array itself increasing. * and each array itself increasing.
* *
* Note: the lexicographic order check only works for n < 10.
*
* @param iterator * @param iterator
* @param n size of universe * @param n size of universe
* @param k size of subsets * @param k size of subsets
@ -398,7 +399,7 @@ public class CombinatoricsUtilsTest {
while (iterator.hasNext()) { while (iterator.hasNext()) {
final int[] iterate = iterator.next(); final int[] iterate = iterator.next();
Assert.assertEquals(k, iterate.length); Assert.assertEquals(k, iterate.length);
final long curLex = lexNorm(iterate); final long curLex = lexNorm(iterate, n);
Assert.assertTrue(curLex > lastLex); Assert.assertTrue(curLex > lastLex);
lastLex = curLex; lastLex = curLex;
length++; length++;
@ -431,12 +432,13 @@ public class CombinatoricsUtilsTest {
* For example [3,2,1] returns 123. * For example [3,2,1] returns 123.
* *
* @param iterate input array * @param iterate input array
* @param n size of universe
* @return lexicographic norm * @return lexicographic norm
*/ */
private long lexNorm(int[] iterate) { private long lexNorm(int[] iterate, int n) {
long ret = 0; long ret = 0;
for (int i = iterate.length - 1; i >= 0; i--) { for (int i = iterate.length - 1; i >= 0; i--) {
ret += iterate[i] * ArithmeticUtils.pow(10l, (long) i); ret += iterate[i] * ArithmeticUtils.pow(n, (long) i);
} }
return ret; return ret;
} }