-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
hipster-core/src/test/java/es/usc/citius/lab/hipster/collection/HashQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |