MultidimensionalCounter implements Iterable<Integer> { public Iterator iterator() { return new Iterator(); } MultidimensionalCounter(int ... size); Iterator iterator(); int getDimension(); int[] getCounts(int index); int getCount(int ... c); int getSize(); int[] getSizes(); @Override String toString();  }
@Test public void testIterator() { final int dim1 = 3; final int dim2 = 4; final MultidimensionalCounter.Iterator iter = new MultidimensionalCounter(dim1, dim2).iterator(); final int max = dim1 * dim2; for (int i = 0; i < max; i++) { Assert.assertTrue(iter.hasNext()); iter.next(); } Assert.assertFalse(iter.hasNext()); }
@Test(expected=NoSuchElementException.class) public void testIteratorNoMoreElements() { final MultidimensionalCounter.Iterator iter = new MultidimensionalCounter(4, 2).iterator(); while (iter.hasNext()) { iter.next(); } iter.next(); }