Search in sources :

Example 31 with ArrayDeque

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));
    }
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 32 with ArrayDeque

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());
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 33 with ArrayDeque

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());
}
Also used : ArrayDeque(java.util.ArrayDeque) NoSuchElementException(java.util.NoSuchElementException)

Example 34 with ArrayDeque

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) {
    }
}
Also used : ArrayDeque(java.util.ArrayDeque) NoSuchElementException(java.util.NoSuchElementException)

Example 35 with ArrayDeque

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());
}
Also used : ArrayDeque(java.util.ArrayDeque)

Aggregations

ArrayDeque (java.util.ArrayDeque)217 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)36 IOException (java.io.IOException)27 HashMap (java.util.HashMap)23 List (java.util.List)20 HashSet (java.util.HashSet)19 Map (java.util.Map)17 Deque (java.util.Deque)11 Iterator (java.util.Iterator)10 NoSuchElementException (java.util.NoSuchElementException)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 File (java.io.File)7 Path (java.nio.file.Path)7 Random (java.util.Random)7 ByteBuffer (java.nio.ByteBuffer)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 HttpFields (org.eclipse.jetty.http.HttpFields)5 Name (com.github.anba.es6draft.ast.scope.Name)4 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)4