BAEL-1370 Added test to show usage of ArrayDeque. (#3128)
This commit is contained in:
parent
6435d5723a
commit
04dc60bd12
|
@ -0,0 +1,50 @@
|
|||
package com.baeldung.arraydeque;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ArrayDequeTest {
|
||||
|
||||
@Test
|
||||
public void whenOffer_addsAtLast() {
|
||||
final Deque<String> deque = new ArrayDeque<>();
|
||||
|
||||
deque.offer("first");
|
||||
deque.offer("second");
|
||||
|
||||
assertEquals("second", deque.getLast());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPoll_removesFirst() {
|
||||
final Deque<String> deque = new ArrayDeque<>();
|
||||
|
||||
deque.offer("first");
|
||||
deque.offer("second");
|
||||
|
||||
assertEquals("first", deque.poll());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPush_addsAtFirst() {
|
||||
final Deque<String> deque = new ArrayDeque<>();
|
||||
|
||||
deque.push("first");
|
||||
deque.push("second");
|
||||
|
||||
assertEquals("second", deque.getFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPop_removesLast() {
|
||||
final Deque<String> deque = new ArrayDeque<>();
|
||||
|
||||
deque.push("first");
|
||||
deque.push("second");
|
||||
|
||||
assertEquals("second", deque.pop());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue