Combinations implements Iterable<int[]> { public Comparator<int[]> comparator() { return new LexicographicComparator(n, k); } Combinations(int n,
                        int k); private  Combinations(int n,
                         int k,
                         IterationOrder iterationOrder); int getN(); int getK(); Iterator<int[]> iterator(); Comparator<int[]> comparator();  }
@Test(expected=DimensionMismatchException.class) public void testLexicographicComparatorWrongIterate1() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); comp.compare(new int[] {1}, new int[] {0, 1, 2}); }
@Test(expected=DimensionMismatchException.class) public void testLexicographicComparatorWrongIterate2() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); comp.compare(new int[] {0, 1, 2}, new int[] {0, 1, 2, 3}); }
@Test(expected=OutOfRangeException.class) public void testLexicographicComparatorWrongIterate3() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); comp.compare(new int[] {1, 2, 5}, new int[] {0, 1, 2}); }
@Test(expected=OutOfRangeException.class) public void testLexicographicComparatorWrongIterate4() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); comp.compare(new int[] {1, 2, 4}, new int[] {-1, 1, 2}); }
@Test public void testLexicographicComparator() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); Assert.assertEquals(1, comp.compare(new int[] {1, 2, 4}, new int[] {1, 2, 3})); Assert.assertEquals(-1, comp.compare(new int[] {0, 1, 4}, new int[] {0, 2, 4})); Assert.assertEquals(0, comp.compare(new int[] {1, 3, 4}, new int[] {1, 3, 4})); }
@Test public void testLexicographicComparatorUnsorted() { final int n = 5; final int k = 3; final Comparator<int[]> comp = new Combinations(n, k).comparator(); Assert.assertEquals(1, comp.compare(new int[] {1, 4, 2}, new int[] {1, 3, 2})); Assert.assertEquals(-1, comp.compare(new int[] {0, 4, 1}, new int[] {0, 4, 2})); Assert.assertEquals(0, comp.compare(new int[] {1, 4, 3}, new int[] {1, 3, 4})); }