Skip to content

Commit

Permalink
HashQueueTest added. Close #29
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Rodríguez Mier committed Nov 1, 2013
1 parent 073e605 commit 3d17b9b
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2013 Centro de Investigación en Tecnoloxías da Información (CITIUS), University of Santiago de Compostela (USC).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.usc.citius.lab.hipster.collection;


import org.junit.Test;

import java.util.Iterator;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;


public class HashQueueTest {
@Test
public void testOffer() throws Exception {
HashQueue<String> queue = new HashQueue<String>();
queue.offer("element");
assertEquals(1, queue.size());
}

@Test
public void testPoll() throws Exception {
HashQueue<String> queue = new HashQueue<String>();
queue.offer("element");
assertEquals("element", queue.poll());
assertEquals(0, queue.size());
}

@Test
public void testPeek() throws Exception {
HashQueue<String> queue = new HashQueue<String>();
queue.offer("element");
assertEquals("element", queue.peek());
assertEquals(1, queue.size());
}

@Test
public void testIterator() throws Exception {
HashQueue<String> queue = new HashQueue<String>();
String[] elements = new String[]{"element-1","element-2","element-3"};
queue.offer(elements[0]);
queue.offer(elements[1]);
queue.offer(elements[2]);
Iterator<String> it = queue.iterator();
assertTrue(it.hasNext());
int i=0;
while(it.hasNext()){
assertEquals(elements[i++],it.next());
}
assertEquals(3, queue.size());
}

@Test
public void testContains() throws Exception {
HashQueue<String> queue = new HashQueue<String>();
String[] elements = new String[]{"element-1","element-2","element-3"};
queue.offer(elements[0]);
queue.offer(elements[1]);
queue.offer(elements[2]);
assertTrue(queue.contains("element-1"));
assertTrue(queue.contains("element-2"));
assertTrue(queue.contains("element-3"));
}
}

0 comments on commit 3d17b9b

Please sign in to comment.