diff --git a/SQ-2023-H6/src/test/java/org/usi/sq/util/CircularFifoQueueTest.java b/SQ-2023-H6/src/test/java/org/usi/sq/util/CircularFifoQueueTest.java index 264e6de..a779e38 100644 --- a/SQ-2023-H6/src/test/java/org/usi/sq/util/CircularFifoQueueTest.java +++ b/SQ-2023-H6/src/test/java/org/usi/sq/util/CircularFifoQueueTest.java @@ -18,7 +18,7 @@ class CircularFifoQueueTest { assertEquals(e, it.next()); } - private void testQueueAll(int initQueueSize, List values, long removeQueueCount, List itrRemoveIndexes) { + private void testQueue(int initQueueSize, List values, long removeQueueCount, List itrRemoveIndexes) { final Set removeIndexesSet = new HashSet<>(itrRemoveIndexes); final CircularFifoQueue queue = new CircularFifoQueue<>(initQueueSize); @@ -58,7 +58,18 @@ class CircularFifoQueueTest { testIteratorEmpty(itNew); } + @SafeVarargs + public final List list(T... es) { + return Arrays.asList(es); + } + public final List range(int start, int end) { + if (end < start) throw new IllegalArgumentException(); + + final List toReturn = new ArrayList<>(end - start); + for (int i = start; i < end; i++) toReturn.add(i); + return toReturn; + } @Test @@ -67,23 +78,18 @@ class CircularFifoQueueTest { assertThrows(NoSuchElementException.class, () -> new CircularFifoQueue().remove()); assertThrows(NullPointerException.class, () -> new CircularFifoQueue().offer(null)); - testQueueIteratorRemove(10, Arrays.asList(1, 2, 3), 0, 2); - testQueueIteratorRemove(3, Arrays.asList(1, 2, 3), 0, 2); - testQueueIteratorRemove(3, Arrays.asList(1, 2, 3), 0, 2); - testQueueIteratorRemove(2, Arrays.asList(1, 2, 3)); - testQueueIteratorRemove(4, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9), 1, 3); - testQueueAll(7, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), 4, Arrays.asList(1, 3)); + final List empty = Collections.emptyList(); - testQueueIteratorRemove(4, Arrays.asList(1, 2, 3, 4, 5), 1, 3); - testQueueIteratorRemove(10, Collections.emptyList()); - testQueueQueueRemove(4, Arrays.asList(1, 2, 3, 4, 5), 1); + testQueue(10, range(0, 3), 0, list(0, 2)); + testQueue(3, range(0, 3), 0, list(0, 2)); + testQueue(3, range(0, 3), 0, list(0, 2)); + testQueue(2, range(0, 3), 0, empty); + testQueue(4, range(0, 9), 0, list(1, 3)); + testQueue(7, range(0, 13), 4, list(1, 3)); + testQueue(7, range(0, 13), 2, list(0, 2, 4, 5, 6)); + testQueue(4, range(0, 5), 0, list(1, 3)); + testQueue(10, empty, 0, empty); + testQueue(4, range(0, 5), 1, empty); } - private void testQueueQueueRemove(int i, List asList, int i1) { - testQueueAll(i, asList, i1, Collections.emptyList()); - } - - private void testQueueIteratorRemove(int i, List asList, Integer... asList1) { - testQueueAll(i, asList, 0, Arrays.asList(asList1)); - } }