From 8b7d3be09ef3d7579e72b28b1305231289a2dda2 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Fri, 1 Apr 2022 13:52:06 +0200 Subject: [PATCH] move source to gradle source dir --- src/main/java/aud/exam/prep/Main.java | 11 +++++ src/{ => main/java}/aud/exam/prep/Pair.java | 0 .../java}/aud/exam/prep/Pointer.java | 0 .../aud/exam/prep/SequenceProcessor.java | 0 .../aud/exam/prep/array/ArrayIterator.java | 0 .../java}/aud/exam/prep/array/Arrays.java | 0 .../aud/exam/prep/array/FullyUsedArray.java | 0 .../prep/array/FullyUsedArrayProcessor.java | 0 .../IterativeFullyUsedArrayProcessor.java | 0 .../exam/prep/array/PartiallyUsedArray.java | 0 .../RecursiveFullyUsedArrayProcessor.java | 0 .../aud/exam/prep/list/DoubleListItem.java | 0 .../prep/list/DoubleListItemProcessor.java | 0 .../IterativeDoubleListItemProcessor.java | 0 .../IterativeSingleListItemProcessor.java | 0 .../java}/aud/exam/prep/list/ListItem.java | 0 .../aud/exam/prep/list/ListItemIterator.java | 0 .../RecursiveDoubleListItemProcessor.java | 0 .../RecursiveSingleListItemProcessor.java | 0 .../aud/exam/prep/list/SingleListItem.java | 0 .../prep/list/SingleListItemProcessor.java | 0 .../exam/prep/tree/BinaryTreeIterator.java | 0 .../aud/exam/prep/tree/BinaryTreeNode.java | 0 .../aud/exam/prep/tree/MutliWayTreeNode.java | 0 .../tree/OrderedBinaryTreeNodeProcessor.java | 0 .../exam/prep/tree/OrderedTreeProcessor.java | 3 ++ ...cursiveOrderedBinaryTreeNodeProcessor.java | 42 +++++++++++++++-- .../java}/aud/exam/prep/tree/Stack.java | 0 .../aud/exam/prep/tree/TernaryTreeNode.java | 0 .../aud/exam/prep/DoubleLatinProvider.java | 2 +- .../aud/exam/prep/DoubleListProvider.java | 0 .../aud/exam/prep/DuplicateListProvider.java | 0 .../aud/exam/prep/ListOfRunsProvider.java | 0 .../java}/aud/exam/prep/ListProvider.java | 0 .../aud/exam/prep/SequenceProcessorTest.java | 0 .../test/java}/aud/exam/prep/Tests.java | 0 .../IterativeFullyUsedArrayProcessorTest.java | 0 .../RecursiveFullyUsedArrayProcessorTest.java | 0 .../list/DoubleListItemProcessorTest.java | 0 .../IterativeDoubleListItemProcessorTest.java | 0 .../IterativeSingleListItemProcessorTest.java | 0 .../RecursiveDoubleListItemProcessorTest.java | 0 .../RecursiveSingleListItemProcessorTest.java | 0 .../OrderedBinaryTreeNodeProcessorTest.java | 0 .../prep/tree/OrderedTreeProcessorTest.java | 45 ++++++++++++++++++- ...iveOrderedBinaryTreeNodeProcessorTest.java | 0 46 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/main/java/aud/exam/prep/Main.java rename src/{ => main/java}/aud/exam/prep/Pair.java (100%) rename src/{ => main/java}/aud/exam/prep/Pointer.java (100%) rename src/{ => main/java}/aud/exam/prep/SequenceProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/array/ArrayIterator.java (100%) rename src/{ => main/java}/aud/exam/prep/array/Arrays.java (100%) rename src/{ => main/java}/aud/exam/prep/array/FullyUsedArray.java (100%) rename src/{ => main/java}/aud/exam/prep/array/FullyUsedArrayProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/array/IterativeFullyUsedArrayProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/array/PartiallyUsedArray.java (100%) rename src/{ => main/java}/aud/exam/prep/array/RecursiveFullyUsedArrayProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/DoubleListItem.java (100%) rename src/{ => main/java}/aud/exam/prep/list/DoubleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/IterativeDoubleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/IterativeSingleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/ListItem.java (100%) rename src/{ => main/java}/aud/exam/prep/list/ListItemIterator.java (100%) rename src/{ => main/java}/aud/exam/prep/list/RecursiveDoubleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/RecursiveSingleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/list/SingleListItem.java (100%) rename src/{ => main/java}/aud/exam/prep/list/SingleListItemProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/BinaryTreeIterator.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/BinaryTreeNode.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/MutliWayTreeNode.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessor.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/OrderedTreeProcessor.java (96%) rename src/{ => main/java}/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java (90%) rename src/{ => main/java}/aud/exam/prep/tree/Stack.java (100%) rename src/{ => main/java}/aud/exam/prep/tree/TernaryTreeNode.java (100%) rename {test => src/test/java}/aud/exam/prep/DoubleLatinProvider.java (94%) rename {test => src/test/java}/aud/exam/prep/DoubleListProvider.java (100%) rename {test => src/test/java}/aud/exam/prep/DuplicateListProvider.java (100%) rename {test => src/test/java}/aud/exam/prep/ListOfRunsProvider.java (100%) rename {test => src/test/java}/aud/exam/prep/ListProvider.java (100%) rename {test => src/test/java}/aud/exam/prep/SequenceProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/Tests.java (100%) rename {test => src/test/java}/aud/exam/prep/array/IterativeFullyUsedArrayProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/array/RecursiveFullyUsedArrayProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/list/DoubleListItemProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/list/IterativeDoubleListItemProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/list/IterativeSingleListItemProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/list/RecursiveDoubleListItemProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/list/RecursiveSingleListItemProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessorTest.java (100%) rename {test => src/test/java}/aud/exam/prep/tree/OrderedTreeProcessorTest.java (86%) rename {test => src/test/java}/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessorTest.java (100%) diff --git a/src/main/java/aud/exam/prep/Main.java b/src/main/java/aud/exam/prep/Main.java new file mode 100644 index 0000000..c607a3e --- /dev/null +++ b/src/main/java/aud/exam/prep/Main.java @@ -0,0 +1,11 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package aud.exam.prep; + +public class Main { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} \ No newline at end of file diff --git a/src/aud/exam/prep/Pair.java b/src/main/java/aud/exam/prep/Pair.java similarity index 100% rename from src/aud/exam/prep/Pair.java rename to src/main/java/aud/exam/prep/Pair.java diff --git a/src/aud/exam/prep/Pointer.java b/src/main/java/aud/exam/prep/Pointer.java similarity index 100% rename from src/aud/exam/prep/Pointer.java rename to src/main/java/aud/exam/prep/Pointer.java diff --git a/src/aud/exam/prep/SequenceProcessor.java b/src/main/java/aud/exam/prep/SequenceProcessor.java similarity index 100% rename from src/aud/exam/prep/SequenceProcessor.java rename to src/main/java/aud/exam/prep/SequenceProcessor.java diff --git a/src/aud/exam/prep/array/ArrayIterator.java b/src/main/java/aud/exam/prep/array/ArrayIterator.java similarity index 100% rename from src/aud/exam/prep/array/ArrayIterator.java rename to src/main/java/aud/exam/prep/array/ArrayIterator.java diff --git a/src/aud/exam/prep/array/Arrays.java b/src/main/java/aud/exam/prep/array/Arrays.java similarity index 100% rename from src/aud/exam/prep/array/Arrays.java rename to src/main/java/aud/exam/prep/array/Arrays.java diff --git a/src/aud/exam/prep/array/FullyUsedArray.java b/src/main/java/aud/exam/prep/array/FullyUsedArray.java similarity index 100% rename from src/aud/exam/prep/array/FullyUsedArray.java rename to src/main/java/aud/exam/prep/array/FullyUsedArray.java diff --git a/src/aud/exam/prep/array/FullyUsedArrayProcessor.java b/src/main/java/aud/exam/prep/array/FullyUsedArrayProcessor.java similarity index 100% rename from src/aud/exam/prep/array/FullyUsedArrayProcessor.java rename to src/main/java/aud/exam/prep/array/FullyUsedArrayProcessor.java diff --git a/src/aud/exam/prep/array/IterativeFullyUsedArrayProcessor.java b/src/main/java/aud/exam/prep/array/IterativeFullyUsedArrayProcessor.java similarity index 100% rename from src/aud/exam/prep/array/IterativeFullyUsedArrayProcessor.java rename to src/main/java/aud/exam/prep/array/IterativeFullyUsedArrayProcessor.java diff --git a/src/aud/exam/prep/array/PartiallyUsedArray.java b/src/main/java/aud/exam/prep/array/PartiallyUsedArray.java similarity index 100% rename from src/aud/exam/prep/array/PartiallyUsedArray.java rename to src/main/java/aud/exam/prep/array/PartiallyUsedArray.java diff --git a/src/aud/exam/prep/array/RecursiveFullyUsedArrayProcessor.java b/src/main/java/aud/exam/prep/array/RecursiveFullyUsedArrayProcessor.java similarity index 100% rename from src/aud/exam/prep/array/RecursiveFullyUsedArrayProcessor.java rename to src/main/java/aud/exam/prep/array/RecursiveFullyUsedArrayProcessor.java diff --git a/src/aud/exam/prep/list/DoubleListItem.java b/src/main/java/aud/exam/prep/list/DoubleListItem.java similarity index 100% rename from src/aud/exam/prep/list/DoubleListItem.java rename to src/main/java/aud/exam/prep/list/DoubleListItem.java diff --git a/src/aud/exam/prep/list/DoubleListItemProcessor.java b/src/main/java/aud/exam/prep/list/DoubleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/DoubleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/DoubleListItemProcessor.java diff --git a/src/aud/exam/prep/list/IterativeDoubleListItemProcessor.java b/src/main/java/aud/exam/prep/list/IterativeDoubleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/IterativeDoubleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/IterativeDoubleListItemProcessor.java diff --git a/src/aud/exam/prep/list/IterativeSingleListItemProcessor.java b/src/main/java/aud/exam/prep/list/IterativeSingleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/IterativeSingleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/IterativeSingleListItemProcessor.java diff --git a/src/aud/exam/prep/list/ListItem.java b/src/main/java/aud/exam/prep/list/ListItem.java similarity index 100% rename from src/aud/exam/prep/list/ListItem.java rename to src/main/java/aud/exam/prep/list/ListItem.java diff --git a/src/aud/exam/prep/list/ListItemIterator.java b/src/main/java/aud/exam/prep/list/ListItemIterator.java similarity index 100% rename from src/aud/exam/prep/list/ListItemIterator.java rename to src/main/java/aud/exam/prep/list/ListItemIterator.java diff --git a/src/aud/exam/prep/list/RecursiveDoubleListItemProcessor.java b/src/main/java/aud/exam/prep/list/RecursiveDoubleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/RecursiveDoubleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/RecursiveDoubleListItemProcessor.java diff --git a/src/aud/exam/prep/list/RecursiveSingleListItemProcessor.java b/src/main/java/aud/exam/prep/list/RecursiveSingleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/RecursiveSingleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/RecursiveSingleListItemProcessor.java diff --git a/src/aud/exam/prep/list/SingleListItem.java b/src/main/java/aud/exam/prep/list/SingleListItem.java similarity index 100% rename from src/aud/exam/prep/list/SingleListItem.java rename to src/main/java/aud/exam/prep/list/SingleListItem.java diff --git a/src/aud/exam/prep/list/SingleListItemProcessor.java b/src/main/java/aud/exam/prep/list/SingleListItemProcessor.java similarity index 100% rename from src/aud/exam/prep/list/SingleListItemProcessor.java rename to src/main/java/aud/exam/prep/list/SingleListItemProcessor.java diff --git a/src/aud/exam/prep/tree/BinaryTreeIterator.java b/src/main/java/aud/exam/prep/tree/BinaryTreeIterator.java similarity index 100% rename from src/aud/exam/prep/tree/BinaryTreeIterator.java rename to src/main/java/aud/exam/prep/tree/BinaryTreeIterator.java diff --git a/src/aud/exam/prep/tree/BinaryTreeNode.java b/src/main/java/aud/exam/prep/tree/BinaryTreeNode.java similarity index 100% rename from src/aud/exam/prep/tree/BinaryTreeNode.java rename to src/main/java/aud/exam/prep/tree/BinaryTreeNode.java diff --git a/src/aud/exam/prep/tree/MutliWayTreeNode.java b/src/main/java/aud/exam/prep/tree/MutliWayTreeNode.java similarity index 100% rename from src/aud/exam/prep/tree/MutliWayTreeNode.java rename to src/main/java/aud/exam/prep/tree/MutliWayTreeNode.java diff --git a/src/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessor.java b/src/main/java/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessor.java similarity index 100% rename from src/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessor.java rename to src/main/java/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessor.java diff --git a/src/aud/exam/prep/tree/OrderedTreeProcessor.java b/src/main/java/aud/exam/prep/tree/OrderedTreeProcessor.java similarity index 96% rename from src/aud/exam/prep/tree/OrderedTreeProcessor.java rename to src/main/java/aud/exam/prep/tree/OrderedTreeProcessor.java index 4e5579f..36747c9 100644 --- a/src/aud/exam/prep/tree/OrderedTreeProcessor.java +++ b/src/main/java/aud/exam/prep/tree/OrderedTreeProcessor.java @@ -3,6 +3,7 @@ package aud.exam.prep.tree; import aud.exam.prep.Pointer; import java.util.Comparator; +import java.util.function.Predicate; /** * Instances of this interface can work with any "valid" tree of type T. @@ -27,6 +28,8 @@ public interface OrderedTreeProcessor { boolean removeAll(Pointer t, V v, Comparator cmp); + T removeIf(T t, Predicate pred); + V max(T t); V secondMax(T t); diff --git a/src/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java b/src/main/java/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java similarity index 90% rename from src/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java rename to src/main/java/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java index c4bcbcc..37353c8 100644 --- a/src/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java +++ b/src/main/java/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessor.java @@ -3,6 +3,7 @@ package aud.exam.prep.tree; import aud.exam.prep.Pointer; import java.util.Comparator; +import java.util.function.Predicate; public class RecursiveOrderedBinaryTreeNodeProcessor extends OrderedBinaryTreeNodeProcessor { @@ -221,6 +222,42 @@ public class RecursiveOrderedBinaryTreeNodeProcessor extends OrderedBinaryTre return removeAllWithCountRec(node.right, v, cmp, node, true); } + @Override + public BinaryTreeNode removeIf(BinaryTreeNode root, Predicate pred) { + if (root == null) { + return null; + } + root.left = removeIf(root.left, pred); + root.right = removeIf(root.right, pred); + + if (pred.test(root.key)) { + + if (root.left == null) { + return root.right; + } else if (root.right == null) { + return root.left; + } else { + root.key = removeRightMostNode(root.left, root, false); + } + } + + return root; + } + + V removeRightMostNode(BinaryTreeNode node, BinaryTreeNode prev, boolean right) { + if (node.right != null) { + return removeRightMostNode(node.right, node, true); + } + + if (right) { + prev.right = node.left; + } else { + prev.left = node.left; + } + + return node.key; + } + @Override public V max(BinaryTreeNode tree) { if (tree == null) { @@ -273,10 +310,7 @@ public class RecursiveOrderedBinaryTreeNodeProcessor extends OrderedBinaryTre @Override public boolean isBalanced(BinaryTreeNode tree) { - if (tree == null) { - return true; - } - return false; + return tree == null; } @Override diff --git a/src/aud/exam/prep/tree/Stack.java b/src/main/java/aud/exam/prep/tree/Stack.java similarity index 100% rename from src/aud/exam/prep/tree/Stack.java rename to src/main/java/aud/exam/prep/tree/Stack.java diff --git a/src/aud/exam/prep/tree/TernaryTreeNode.java b/src/main/java/aud/exam/prep/tree/TernaryTreeNode.java similarity index 100% rename from src/aud/exam/prep/tree/TernaryTreeNode.java rename to src/main/java/aud/exam/prep/tree/TernaryTreeNode.java diff --git a/test/aud/exam/prep/DoubleLatinProvider.java b/src/test/java/aud/exam/prep/DoubleLatinProvider.java similarity index 94% rename from test/aud/exam/prep/DoubleLatinProvider.java rename to src/test/java/aud/exam/prep/DoubleLatinProvider.java index 2ca29ff..ecca8ce 100644 --- a/test/aud/exam/prep/DoubleLatinProvider.java +++ b/src/test/java/aud/exam/prep/DoubleLatinProvider.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; public class DoubleLatinProvider implements ArgumentsProvider { @Override - public Stream provideArguments(ExtensionContext extensionContext) throws Exception { + public Stream provideArguments(ExtensionContext extensionContext) { return Stream .generate(() -> Arguments.of(randomLatin(), randomLatin())) diff --git a/test/aud/exam/prep/DoubleListProvider.java b/src/test/java/aud/exam/prep/DoubleListProvider.java similarity index 100% rename from test/aud/exam/prep/DoubleListProvider.java rename to src/test/java/aud/exam/prep/DoubleListProvider.java diff --git a/test/aud/exam/prep/DuplicateListProvider.java b/src/test/java/aud/exam/prep/DuplicateListProvider.java similarity index 100% rename from test/aud/exam/prep/DuplicateListProvider.java rename to src/test/java/aud/exam/prep/DuplicateListProvider.java diff --git a/test/aud/exam/prep/ListOfRunsProvider.java b/src/test/java/aud/exam/prep/ListOfRunsProvider.java similarity index 100% rename from test/aud/exam/prep/ListOfRunsProvider.java rename to src/test/java/aud/exam/prep/ListOfRunsProvider.java diff --git a/test/aud/exam/prep/ListProvider.java b/src/test/java/aud/exam/prep/ListProvider.java similarity index 100% rename from test/aud/exam/prep/ListProvider.java rename to src/test/java/aud/exam/prep/ListProvider.java diff --git a/test/aud/exam/prep/SequenceProcessorTest.java b/src/test/java/aud/exam/prep/SequenceProcessorTest.java similarity index 100% rename from test/aud/exam/prep/SequenceProcessorTest.java rename to src/test/java/aud/exam/prep/SequenceProcessorTest.java diff --git a/test/aud/exam/prep/Tests.java b/src/test/java/aud/exam/prep/Tests.java similarity index 100% rename from test/aud/exam/prep/Tests.java rename to src/test/java/aud/exam/prep/Tests.java diff --git a/test/aud/exam/prep/array/IterativeFullyUsedArrayProcessorTest.java b/src/test/java/aud/exam/prep/array/IterativeFullyUsedArrayProcessorTest.java similarity index 100% rename from test/aud/exam/prep/array/IterativeFullyUsedArrayProcessorTest.java rename to src/test/java/aud/exam/prep/array/IterativeFullyUsedArrayProcessorTest.java diff --git a/test/aud/exam/prep/array/RecursiveFullyUsedArrayProcessorTest.java b/src/test/java/aud/exam/prep/array/RecursiveFullyUsedArrayProcessorTest.java similarity index 100% rename from test/aud/exam/prep/array/RecursiveFullyUsedArrayProcessorTest.java rename to src/test/java/aud/exam/prep/array/RecursiveFullyUsedArrayProcessorTest.java diff --git a/test/aud/exam/prep/list/DoubleListItemProcessorTest.java b/src/test/java/aud/exam/prep/list/DoubleListItemProcessorTest.java similarity index 100% rename from test/aud/exam/prep/list/DoubleListItemProcessorTest.java rename to src/test/java/aud/exam/prep/list/DoubleListItemProcessorTest.java diff --git a/test/aud/exam/prep/list/IterativeDoubleListItemProcessorTest.java b/src/test/java/aud/exam/prep/list/IterativeDoubleListItemProcessorTest.java similarity index 100% rename from test/aud/exam/prep/list/IterativeDoubleListItemProcessorTest.java rename to src/test/java/aud/exam/prep/list/IterativeDoubleListItemProcessorTest.java diff --git a/test/aud/exam/prep/list/IterativeSingleListItemProcessorTest.java b/src/test/java/aud/exam/prep/list/IterativeSingleListItemProcessorTest.java similarity index 100% rename from test/aud/exam/prep/list/IterativeSingleListItemProcessorTest.java rename to src/test/java/aud/exam/prep/list/IterativeSingleListItemProcessorTest.java diff --git a/test/aud/exam/prep/list/RecursiveDoubleListItemProcessorTest.java b/src/test/java/aud/exam/prep/list/RecursiveDoubleListItemProcessorTest.java similarity index 100% rename from test/aud/exam/prep/list/RecursiveDoubleListItemProcessorTest.java rename to src/test/java/aud/exam/prep/list/RecursiveDoubleListItemProcessorTest.java diff --git a/test/aud/exam/prep/list/RecursiveSingleListItemProcessorTest.java b/src/test/java/aud/exam/prep/list/RecursiveSingleListItemProcessorTest.java similarity index 100% rename from test/aud/exam/prep/list/RecursiveSingleListItemProcessorTest.java rename to src/test/java/aud/exam/prep/list/RecursiveSingleListItemProcessorTest.java diff --git a/test/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessorTest.java b/src/test/java/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessorTest.java similarity index 100% rename from test/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessorTest.java rename to src/test/java/aud/exam/prep/tree/OrderedBinaryTreeNodeProcessorTest.java diff --git a/test/aud/exam/prep/tree/OrderedTreeProcessorTest.java b/src/test/java/aud/exam/prep/tree/OrderedTreeProcessorTest.java similarity index 86% rename from test/aud/exam/prep/tree/OrderedTreeProcessorTest.java rename to src/test/java/aud/exam/prep/tree/OrderedTreeProcessorTest.java index 2bb695e..a720f83 100644 --- a/test/aud/exam/prep/tree/OrderedTreeProcessorTest.java +++ b/src/test/java/aud/exam/prep/tree/OrderedTreeProcessorTest.java @@ -10,6 +10,9 @@ import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import static aud.exam.prep.Tests.CMP; import static org.junit.jupiter.api.Assertions.*; @@ -69,7 +72,7 @@ public abstract class OrderedTreeProcessorTest { assertIterableEquals(list, processor.iterate(t)); } - private T asTree(List list) { + protected T asTree(List list) { T t = processor.newEmptyTree(); for (var n : list) { @@ -168,6 +171,46 @@ public abstract class OrderedTreeProcessorTest { } } + @ParameterizedTest + @ArgumentsSource(ListProvider.class) + void testThat_removeIfWorks(List list) { + T t = asTree(list); + list.sort(CMP); + + for (var toRemove : getRemovals(list)) { + Predicate pred = n -> + Objects.equals(n, toRemove); + + list.removeIf(pred); + + t = processor.removeIf(t, pred); + + assertTrue(processor.check(t, CMP)); + assertIterableEquals(list, processor.iterate(t)); + } + } + + List getRemovals(List list) { + var start = -100 + list + .stream() + .min(CMP) + .orElse(0); + + var end = 100 + list + .stream() + .max(CMP) + .orElse(0); + + var removals = IntStream + .rangeClosed(start, end) + .boxed() + .collect(Collectors.toList()); + + Collections.shuffle(removals, Tests.RANDOM); + + return removals; + } + @ParameterizedTest @ArgumentsSource(ListProvider.class) void printATree(List list) { diff --git a/test/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessorTest.java b/src/test/java/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessorTest.java similarity index 100% rename from test/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessorTest.java rename to src/test/java/aud/exam/prep/tree/RecursiveOrderedBinaryTreeNodeProcessorTest.java