Skip to content

Commit

Permalink
fix bug in AllCombinationsIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Apr 30, 2024
1 parent 6a351cd commit af4a3af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public boolean hasNext() {
return true;
}
}
return false;

return first;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public void testNormalDomain() {

@Test
public void testEmptyDomain() {
final Iterable<List<Integer>> iter =
IterableUtil.cartesianProduct(DOMAIN1, Collections.emptyList(), DOMAIN3);
final Iterable<List<Integer>> iter = IterableUtil.cartesianProduct(DOMAIN1, Collections.emptyList(), DOMAIN3);

Assert.assertEquals(IterableUtil.size(iter), 0);
Assert.assertThrows(NoSuchElementException.class, () -> iter.iterator().next());
Expand All @@ -64,4 +63,13 @@ public void testEmptyDimension() {
Assert.assertEquals(IterableUtil.size(iter), 1);
Assert.assertTrue(IterableUtil.stream(iter).allMatch(List::isEmpty));
}

@Test
public void testSingletons() {
final Iterable<List<Integer>> iter =
IterableUtil.cartesianProduct(Collections.singleton(1), Collections.singleton(2));

Assert.assertEquals(IterableUtil.size(iter), 1);
Assert.assertEquals(iter.iterator().next(), List.of(1, 2));
}
}

0 comments on commit af4a3af

Please sign in to comment.