Verified Commit e4d1e3b1 authored by Daniel Mangold's avatar Daniel Mangold
Browse files

Fixed requirements for testNext(String) and testHasNext(String) in MyParenthesesTreeIteratorTest

parent 32971507
......@@ -50,26 +50,35 @@ public class MyParenthesesTreeIteratorTest {
@ParameterizedTest
@ArgumentsSource(RandomTreeProvider.class)
public void testNext(String treeString) throws ReflectiveOperationException {
requireTest(MyTreeTest.class.getDeclaredMethod("testIterator"), "()");
requireTest(MyTreeTest.class.getDeclaredMethod("testIterator"));
Iterator<Character> iterator = MyTreeTest.getIterator(treeString);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < treeString.length(); i++)
assertEquals(treeString.charAt(i), iterator.next(), "Character returned by iterator does not equal expected");
try {
Character next = iterator.next();
builder.append(next != null ? next : "");
} catch (NoSuchElementException e) {
fail("Iterator has fewer elements than expected: " + (i + 1) + "/" + treeString.length(), e);
}
assertEquals(treeString, builder.toString(), "Characters returned by iterator does not equal expected");
assertThrows(NoSuchElementException.class, iterator::next, "Iterator has more elements than expected");
}
@ParameterizedTest
@ArgumentsSource(RandomTreeProvider.class)
public void testHasNext(String treeString) throws ReflectiveOperationException {
requireTest(MyTreeTest.class.getDeclaredMethod("testIterator"), "()");
requireTest(MyTreeTest.class.getDeclaredMethod("testIterator"));
requireTest(MyParenthesesTreeIteratorTest.class.getDeclaredMethod("testNext", String.class), "()");
Iterator<Character> iterator = MyTreeTest.getIterator(treeString);
for (int i = 0; i < treeString.length(); i++, iterator.next())
assertTrue(iterator.hasNext(), "Iterator should not have reached end yet");
assertTrue(iterator.hasNext(),
"Iterator should not have reached end yet, number of elements: " + (i + 1) + "/" + treeString.length());
assertFalse(iterator.hasNext(), "Iterator has more elements than expected");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment