Add debugging for oving5

This commit is contained in:
Andreas Omholt Olsen
2026-02-15 17:13:35 +01:00
parent 250553c438
commit 1a6645482b
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package oving5.debugging;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class StringMergingIteratorProgram {
public static void main(String[] args) throws Exception {
Iterator<String> one = List.of("a", "b").iterator();
Iterator<String> two = List.of("c", "d", "e").iterator();
StringMergingIterator mergeIterator = new StringMergingIterator(one, two);
List<String> values = new ArrayList<>();
while (mergeIterator.hasNext()) {
values.add(mergeIterator.next());
}
List<String> expectedOutput = List.of("a", "c", "b", "d", "e");
if (values.size() != expectedOutput.size()) {
throw new Exception(
"The merged output did not contain the expected number of values. Try using "
+ "the VS Code debugger to see the difference between the lists");
}
for (int i = 0; i < expectedOutput.size(); i++) {
if (!values.get(i).equals(expectedOutput.get(i))) {
throw new Exception(
"The iterator did not correctly merge the output. Try using the VS Code "
+ "debugger to see the difference between the lists");
}
}
System.out.println(
"Success! StringMergingIterator correctly merged the output of the two lists");
}
}