use of java.util.ArrayDeque in project mapdb by jankotek.
the class ArrayDequeTest method testSize.
/**
* size changes when elements added and removed
*/
public void testSize() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(SIZE - i, q.size());
q.removeFirst();
}
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.size());
q.add(new Integer(i));
}
}
use of java.util.ArrayDeque in project mapdb by jankotek.
the class ArrayDequeTest method testPeekFirst.
/**
* peekFirst() returns next element, or null if empty
*/
public void testPeekFirst() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.peekFirst());
assertEquals(i, q.pollFirst());
assertTrue(q.peekFirst() == null || !q.peekFirst().equals(i));
}
assertNull(q.peekFirst());
}
use of java.util.ArrayDeque in project mapdb by jankotek.
the class ArrayDequeTest method testLastElement.
/**
* getLast() returns last element, or throws NSEE if empty
*/
public void testLastElement() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = SIZE - 1; i >= 0; --i) {
assertEquals(i, q.getLast());
assertEquals(i, q.pollLast());
}
try {
q.getLast();
shouldThrow();
} catch (NoSuchElementException success) {
}
assertNull(q.peekLast());
}
use of java.util.ArrayDeque in project mapdb by jankotek.
the class ArrayDequeTest method testFirstElement.
/**
* getFirst() returns first element, or throws NSEE if empty
*/
public void testFirstElement() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.getFirst());
assertEquals(i, q.pollFirst());
}
try {
q.getFirst();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.ArrayDeque in project mapdb by jankotek.
the class ArrayDequeTest method testRemoveFirstOccurrence.
/**
* removeFirstOccurrence(x) removes x and returns true if present
*/
public void testRemoveFirstOccurrence() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 1; i < SIZE; i += 2) {
assertTrue(q.removeFirstOccurrence(new Integer(i)));
}
for (int i = 0; i < SIZE; i += 2) {
assertTrue(q.removeFirstOccurrence(new Integer(i)));
assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
}
assertTrue(q.isEmpty());
}
Aggregations