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

Fixed parentheses terms

parent fe3b78a1
......@@ -55,16 +55,17 @@ public class MyParenthesesTreeIteratorTest {
Iterator<Character> iterator = MyTreeTest.getIterator(treeString);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < treeString.length(); i++)
for (int i = 0; i < treeString.length() - 1; i++)
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);
fail("Iterator has fewer elements than expected: " + (i + 1) + "/" + (treeString.length() - 1), e);
}
assertEquals(treeString, builder.toString(), "Characters returned by iterator does not equal expected");
assertEquals(treeString.substring(0, treeString.length() - 1), builder.toString(),
"Characters returned by iterator does not equal expected");
assertThrows(NoSuchElementException.class, iterator::next, "Iterator has more elements than expected");
}
......@@ -72,20 +73,20 @@ public class MyParenthesesTreeIteratorTest {
@ArgumentsSource(RandomTreeProvider.class)
public void testHasNext(String treeString) throws ReflectiveOperationException {
requireTest(MyTreeTest.class.getDeclaredMethod("testIterator"));
requireTest(MyParenthesesTreeIteratorTest.class.getDeclaredMethod("testNext", String.class), "()");
requireTest(MyParenthesesTreeIteratorTest.class.getDeclaredMethod("testNext", String.class), "()\n");
Iterator<Character> iterator = MyTreeTest.getIterator(treeString);
for (int i = 0; i < treeString.length(); i++, iterator.next())
for (int i = 0; i < treeString.length() - 1; i++, iterator.next())
assertTrue(iterator.hasNext(),
"Iterator should not have reached end yet, number of elements: " + (i + 1) + "/" + treeString.length());
"Iterator should not have reached end yet, number of elements: " + (i + 1) + "/" + (treeString.length() - 1));
assertFalse(iterator.hasNext(), "Iterator has more elements than expected");
}
@Test
public void testRemove() throws ReflectiveOperationException {
Iterator<Character> iterator = MyTreeTest.getIterator("");
Iterator<Character> iterator = MyTreeTest.getIterator("\n");
assertThrows(UnsupportedOperationException.class, iterator::remove);
}
......
......@@ -162,7 +162,7 @@ public class MyTreeTest {
public void testIterator() throws ReflectiveOperationException {
requireTest(MyParenthesesTreeIteratorTest.class);
Object instance = constructor.newInstance(new StringReader(""), RANDOM.nextBoolean());
Object instance = constructor.newInstance(new StringReader("\n"), false);
assertEquals(MyParenthesesTreeIteratorTest.myParenthesesTreeIteratorClass, iterator.invoke(instance).getClass(),
"Returned object does not have type MyParenthesesTreeIterator");
......@@ -181,8 +181,10 @@ public class MyTreeTest {
assertTrue((Boolean) isIsomorphic.invoke(instance1, instance2), "Trees are isomorphic");
assertTrue((Boolean) isIsomorphic.invoke(instance2, instance1), "Trees are isomorphic");
assertTrue((Boolean) isIsomorphic.invoke(instance1, instance1), "Trees are isomorphic");
assertTrue((Boolean) isIsomorphic.invoke(instance2, instance2), "Trees are isomorphic");
String nonIsomorphicTreeString = "(((((())))))";
String nonIsomorphicTreeString = "(((((())))))\n";
Object nonIsomorphicInstance = constructor.newInstance(new StringReader(nonIsomorphicTreeString), false);
assertFalse((Boolean) isIsomorphic.invoke(instance1, nonIsomorphicInstance), "Trees are not isomorphic");
......
......@@ -14,7 +14,7 @@ public class RandomTreeProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.generate(() -> Arguments.of(randomTreeString(MAX_TREE_DEPTH))).limit(MAX_STREAM_SIZE);
return Stream.generate(() -> Arguments.of(randomTreeString(MAX_TREE_DEPTH) + '\n')).limit(MAX_STREAM_SIZE);
}
public static String randomTreeString(int maxTreeDepth) {
......
......@@ -14,16 +14,16 @@ public class TreeProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("()()", false),
Arguments.of("(())(()())", false),
Arguments.of("", false),
Arguments.of("()()\n", false),
Arguments.of("(())(()())\n", false),
Arguments.of("\n", false),
Arguments.of("()\n()", false),
Arguments.of("()\nabc", false),
Arguments.of("\n()", false),
Arguments.of("abc", true),
Arguments.of("(()))", true),
Arguments.of(")()()", true),
Arguments.of("(((()()))", true)
Arguments.of("", true),
Arguments.of("abc\n", true),
Arguments.of("(()))\n", true),
Arguments.of(")()()\n", true),
Arguments.of("(((()()))\n", true)
);
}
......
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