以下是测试用例。
@Test public void testArrayDequePollFirst() { Dequedeque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); deque.pollFirst(); Assert.assertEquals(deque.size(), 3); Assert.assertArrayEquals(deque.toArray(), new String[]{"2", "a2", "a3"}); } @Test public void testArrayDequePeek01() { Deque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); String tmp = deque.peek(); Assert.assertEquals(tmp, "a3"); Assert.assertEquals(deque.size(), 4); Assert.assertArrayEquals(deque.toArray(), new String[]{"1", "2", "a2", "a3"}); } @Test public void testArrayDequePeek02() { Deque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); String tmp = deque.peekFirst(); Assert.assertEquals(tmp, "1"); Assert.assertEquals(deque.size(), 4); Assert.assertArrayEquals(deque.toArray(), new String[]{"1", "2", "a2", "a3"}); } @Test public void testArrayDequePeek03() { Deque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); String tmp = deque.peekLast(); Assert.assertEquals(tmp, "a3"); Assert.assertEquals(deque.size(), 4); Assert.assertArrayEquals(deque.toArray(), new String[]{"1", "2", "a2", "a3"}); } @Test public void testArrayDequePollLast() { Deque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); deque.pollLast(); Assert.assertArrayEquals(deque.toArray(), new String[]{"1", "2", "a2"}); } @Test public void testArrayDequePush() { ArrayDeque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); deque.push("a4"); Assert.assertEquals("a4", deque.pollFirst()); } @Test public void testArrayDequePush02() { ArrayDeque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); deque.push("a4"); deque.pop(); deque.pop(); Assert.assertEquals("2", deque.pollFirst()); } @Test public void testArrayDequePush03() { ArrayDeque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("a2"); deque.add("a3"); deque.push("a4"); deque.pop(); String tmp = deque.pop(); Assert.assertEquals("1", tmp); } @Test public void testArrayDequeOffer() { ArrayDeque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("3"); deque.add("4"); deque.offer("5"); String tmp = deque.pollLast(); Assert.assertEquals("5", tmp); } @Test public void testArrayDequeOfferFirst() { ArrayDeque deque = new ArrayDeque<>(); deque.add("1"); deque.add("2"); deque.add("3"); deque.add("4"); deque.offerFirst("5"); String tmp = deque.peekFirst(); Assert.assertEquals("5", tmp); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)