Skip to content

Commit e1d0c75

Browse files
committed
Found one more unsupported case in iterators. Add link to task in JavaDoc
1 parent 5d9fb63 commit e1d0c75

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main/java/by/andd3dfx/iterators/NestedIterator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* <pre>
11+
* <a href="https://leetcode.com/problems/flatten-nested-list-iterator/description/">Task description</a>
12+
*
1113
* You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.
1214
*
1315
* Implement the NestedIterator class:

src/test/java/by/andd3dfx/iterators/RecursiveIteratorTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package by.andd3dfx.iterators;
22

3+
import org.junit.Ignore;
34
import org.junit.Test;
45

56
import java.util.ArrayList;
@@ -41,6 +42,20 @@ public void testNextHasNextForComplexStructure() {
4142
assertThat(result).isEqualTo(List.of("1", "3", "9", "4", "23", "31", "88", "22", "5", "37", "11"));
4243
}
4344

45+
@Ignore("TODO: change implemetation to support this case")
46+
@Test
47+
public void testNextForListOfEmptyLists() {
48+
List<Object> list = Arrays.asList(List.of(), List.of(List.of()));
49+
var iterator = new RecursiveIterator<>(list.iterator());
50+
51+
List<String> result = new ArrayList<>();
52+
while (iterator.hasNext()) {
53+
result.add((String) iterator.next());
54+
}
55+
56+
assertThat(result).isEqualTo(List.of());
57+
}
58+
4459
@Test(expected = NoSuchElementException.class)
4560
public void callNextAfterEndOfIterator() {
4661
List<String> list = Arrays.asList("1", "3", "5", "7", "9");

0 commit comments

Comments
 (0)