refactoring
This commit is contained in:
parent
53ac4a1cbd
commit
0ca300b35f
1 changed files with 23 additions and 17 deletions
|
@ -18,7 +18,7 @@ class CircularFifoQueueTest {
|
||||||
assertEquals(e, it.next());
|
assertEquals(e, it.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void testQueueAll(int initQueueSize, List<T> values, long removeQueueCount, List<Integer> itrRemoveIndexes) {
|
private <T> void testQueue(int initQueueSize, List<T> values, long removeQueueCount, List<Integer> itrRemoveIndexes) {
|
||||||
final Set<Integer> removeIndexesSet = new HashSet<>(itrRemoveIndexes);
|
final Set<Integer> removeIndexesSet = new HashSet<>(itrRemoveIndexes);
|
||||||
|
|
||||||
final CircularFifoQueue<T> queue = new CircularFifoQueue<>(initQueueSize);
|
final CircularFifoQueue<T> queue = new CircularFifoQueue<>(initQueueSize);
|
||||||
|
@ -58,7 +58,18 @@ class CircularFifoQueueTest {
|
||||||
testIteratorEmpty(itNew);
|
testIteratorEmpty(itNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public final <T> List<T> list(T... es) {
|
||||||
|
return Arrays.asList(es);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<Integer> range(int start, int end) {
|
||||||
|
if (end < start) throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
final List<Integer> toReturn = new ArrayList<>(end - start);
|
||||||
|
for (int i = start; i < end; i++) toReturn.add(i);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -67,23 +78,18 @@ class CircularFifoQueueTest {
|
||||||
assertThrows(NoSuchElementException.class, () -> new CircularFifoQueue<Void>().remove());
|
assertThrows(NoSuchElementException.class, () -> new CircularFifoQueue<Void>().remove());
|
||||||
assertThrows(NullPointerException.class, () -> new CircularFifoQueue<Void>().offer(null));
|
assertThrows(NullPointerException.class, () -> new CircularFifoQueue<Void>().offer(null));
|
||||||
|
|
||||||
testQueueIteratorRemove(10, Arrays.asList(1, 2, 3), 0, 2);
|
final List<Integer> empty = Collections.emptyList();
|
||||||
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));
|
|
||||||
|
|
||||||
testQueueIteratorRemove(4, Arrays.asList(1, 2, 3, 4, 5), 1, 3);
|
testQueue(10, range(0, 3), 0, list(0, 2));
|
||||||
testQueueIteratorRemove(10, Collections.emptyList());
|
testQueue(3, range(0, 3), 0, list(0, 2));
|
||||||
testQueueQueueRemove(4, Arrays.asList(1, 2, 3, 4, 5), 1);
|
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<Integer> asList, int i1) {
|
|
||||||
testQueueAll(i, asList, i1, Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testQueueIteratorRemove(int i, List<Integer> asList, Integer... asList1) {
|
|
||||||
testQueueAll(i, asList, 0, Arrays.asList(asList1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue