2 * Copyright 2000-2013 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.util.containers;
18 import junit.framework.Assert;
19 import org.junit.Test;
22 * @author Sergey Simonchik
24 public class CharArrayQueueTest {
27 public void testSingleAdd() throws Exception {
28 CharArrayQueue queue = new CharArrayQueue(0);
31 Assert.assertEquals(1, queue.size());
32 Assert.assertEquals(value, queue.poll());
33 Assert.assertEquals(-1, queue.poll());
37 public void testResize1() throws Exception {
38 CharArrayQueue queue = new CharArrayQueue(4);
39 char[] buf = new char[] {'1', '2', '3', '4', '5'};
41 Assert.assertEquals(queue.size(), buf.length);
43 Assert.assertEquals(c, queue.poll());
45 Assert.assertEquals(-1, queue.poll());
49 public void testResize2() throws Exception {
50 CharArrayQueue queue = new CharArrayQueue(4);
51 char[] buf = new char[] {'1', '2', '3', '4', '5', '6', '7', '8'};
53 Assert.assertEquals(queue.size(), buf.length);
54 Assert.assertEquals(buf[0], queue.poll());
55 Assert.assertEquals(buf[1], queue.poll());
60 queue.addAll(buf); // array resize with myHead > myTail
61 Assert.assertEquals(queue.size(), buf.length * 2);
62 for (int i = 2; i < buf.length; i++) {
63 Assert.assertEquals(buf[i], queue.poll());
65 Assert.assertEquals(v, queue.poll());
66 Assert.assertEquals(v, queue.poll());
68 Assert.assertEquals(c, queue.poll());
70 Assert.assertEquals(-1, queue.poll());
74 public void testAddString() throws Exception {
75 CharArrayQueue queue = new CharArrayQueue(2);
77 Assert.assertEquals(0, queue.size());
79 Assert.assertEquals('a', queue.poll());
80 Assert.assertEquals('b', queue.poll());
81 Assert.assertEquals('c', queue.poll());
82 Assert.assertEquals(-1, queue.poll());