private <T> void assertNextPermutation( List<T> expectedPermutation, Iterator<List<T>> permutations) { assertTrue("Expected another permutation, but there was none.", permutations.hasNext()); assertEquals(expectedPermutation, permutations.next()); }
public void testToStringImplWithNullEntries() throws Exception { List<String> list = Lists.newArrayList(); list.add("foo"); list.add(null); assertEquals(list.toString(), Collections2.toStringImpl(list)); } }
private <T> void assertPermutationsCount(int expected, Collection<List<T>> permutationSet) { assertEquals(expected, permutationSet.size()); Iterator<List<T>> permutations = permutationSet.iterator(); for (int i = 0; i < expected; i++) { assertTrue(permutations.hasNext()); permutations.next(); } assertNoMorePermutations(permutations); }
public void testPermutationSetSizeOverflow() { // 13 elements overflow an int assertEquals( Integer.MAX_VALUE, Collections2.permutations(newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)).size()); // 21 elements overflow a long assertEquals( Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)) .size()); assertEquals( Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)) .size()); }
public void testPermutationSetEmpty() { Collection<List<Integer>> permutationSet = Collections2.permutations(Collections.<Integer>emptyList()); assertEquals(1, permutationSet.size()); assertTrue(permutationSet.contains(Collections.<Integer>emptyList())); Iterator<List<Integer>> permutations = permutationSet.iterator(); assertNextPermutation(Collections.<Integer>emptyList(), permutations); assertNoMorePermutations(permutations); }
public void testOrderedPermutationSetSizeOverflow() { // 12 elements won't overflow assertEquals( 479001600 /*12!*/, Collections2.orderedPermutations(newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) .size()); // 13 elements overflow an int assertEquals( Integer.MAX_VALUE, Collections2.orderedPermutations(newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)) .size()); // 21 elements overflow a long assertEquals( Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)) .size()); // Almost force an overflow in the binomial coefficient calculation assertEquals( 1391975640 /*C(34,14)*/, Collections2.orderedPermutations(concat(nCopies(20, 1), nCopies(14, 2))).size()); // Do force an overflow in the binomial coefficient calculation assertEquals( Integer.MAX_VALUE, Collections2.orderedPermutations(concat(nCopies(21, 1), nCopies(14, 2))).size()); }
public void testOrderedPermutationSetEmpty() { List<Integer> list = newArrayList(); Collection<List<Integer>> permutationSet = Collections2.orderedPermutations(list); assertEquals(1, permutationSet.size()); assertThat(permutationSet).contains(list); Iterator<List<Integer>> permutations = permutationSet.iterator(); assertNextPermutation(Lists.<Integer>newArrayList(), permutations); assertNoMorePermutations(permutations); }
public void testToStringImplWithNullEntries() throws Exception { List<String> list = Lists.newArrayList(); list.add("foo"); list.add(null); assertEquals(list.toString(), Collections2.toStringImpl(list)); }
public void testPermutationSetSizeOverflow() { // 13 elements overflow an int assertEquals(Integer.MAX_VALUE, Collections2.permutations(newArrayList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)).size()); // 21 elements overflow a long assertEquals(Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)).size()); assertEquals(Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)).size()); }
private <T> void assertNextPermutation(List<T> expectedPermutation, Iterator<List<T>> permutations) { assertTrue("Expected another permutation, but there was none.", permutations.hasNext()); assertEquals(expectedPermutation, permutations.next()); }
private <T> void assertPermutationsCount(int expected, Collection<List<T>> permutationSet) { assertEquals(expected, permutationSet.size()); Iterator<List<T>> permutations = permutationSet.iterator(); for (int i = 0; i < expected; i++) { assertTrue(permutations.hasNext()); permutations.next(); } assertNoMorePermutations(permutations); }
public void testOrderedPermutationSetSizeOverflow() { // 12 elements won't overflow assertEquals(479001600 /*12!*/, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)).size()); // 13 elements overflow an int assertEquals(Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)).size()); // 21 elements overflow a long assertEquals(Integer.MAX_VALUE, Collections2.orderedPermutations( newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)).size()); // Almost force an overflow in the binomial coefficient calculation assertEquals(1391975640 /*C(34,14)*/, Collections2.orderedPermutations( concat(nCopies(20, 1), nCopies(14, 2))).size()); // Do force an overflow in the binomial coefficient calculation assertEquals(Integer.MAX_VALUE, Collections2.orderedPermutations( concat(nCopies(21, 1), nCopies(14, 2))).size()); }
public void testPermutationSetEmpty() { Collection<List<Integer>> permutationSet = Collections2.permutations(Collections.<Integer>emptyList()); assertEquals(1, permutationSet.size()); assertTrue(permutationSet.contains(Collections.<Integer> emptyList())); Iterator<List<Integer>> permutations = permutationSet.iterator(); assertNextPermutation(Collections.<Integer> emptyList(), permutations); assertNoMorePermutations(permutations); }
public void testOrderedPermutationSetEmpty() { List<Integer> list = newArrayList(); Collection<List<Integer>> permutationSet = Collections2.orderedPermutations(list); assertEquals(1, permutationSet.size()); assertThat(permutationSet).contains(list); Iterator<List<Integer>> permutations = permutationSet.iterator(); assertNextPermutation(Lists.<Integer>newArrayList(), permutations); assertNoMorePermutations(permutations); }