测试类怎么写啊
package jp.co.worksap.recruiting;
public inte易做图ce ExamImmutableQueue<E> {
public ExamImmutableQueue<E>enqueue(E e);
public ExamImmutableQueue<E> dequeue();
public E peek();
public int size();
}
package jp.co.worksap.recruiting;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class ExamImmutableQueueImpl<E> implements ExamImmutableQueue<E>{
private List<E> queue;
public ExamImmutableQueueImpl(){
queue=new ArrayList<E>();
}
private ExamImmutableQueueImpl(List<E> queue){
this.queue=queue;
}
@Override
public ExamImmutableQueue<E> dequeue() {
if(queue.isEmpty()){
throw new NoSuchElementException();
}
List<E> clone=new ArrayList<E>(queue);
clone.remove(0);
return new ExamImmutableQueueImpl<E>(clone);
}
@Override
public ExamImmutableQueue<E> enqueue(E e) {
if(e==null){
throw new IllegalArgumentException();
}
List<E> clone=new ArrayList<E>(queue);
clone.add(e);
return new ExamImmutableQueueImpl<E>(clone);
}
@Override
public E peek() {
if(queue.isEmpty()){
throw new NoSuchElementException();
}
return queue.get(0);
}
@Override
public int size() {
return queue.size();
}
}
package jp.co.worksap.recruiting;
/**
* The Queue class represents a first-in-first-out(FIFO) queue of objects.
* And this class can look at the object which has the highest(or lowest or so) value
* So every object onto the queue must be comparable to each other.
* @param<E>
*/
public inte易做图ce ExamPeekableQueue <E extends Comparable<E>> {
public void enqueue(E e);
public E dequeue();
public E peekMedian();
public E peekMaximum();
public E peekMinimum();
public int size();
}
package jp.co.worksap.recruiting;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.NoSuchElementException;
public class ExamPeekableQueueImpl<E extends Comparable<E>> implements ExamPeekableQueue<E> {
private LinkedList<E> queue;
public ExamPeekableQueueImpl(){
queue=new LinkedList<E>();
}
@Override
public void enqueue(E e) {
if(e==null){
throw new IllegalArgumentException();
}
queue.addLast(e);
}
@Override
public E dequeue() {
if(queue.isEmpty()){
throw new NoSuchElementException();
}
return queue.removeFirst();
}
@Override
public E peekMedian() {
Collections.sort(queue);
E e = null;
int i = 0;
for(Iterator it = queue.iterator();it.hasNext();)
{
if(i<queue.size()/2+1)
{
e = (E) it.next();
i++;
}
else
{
break;
}
}
return e;
}
@Override
public E peekMaximum() {
E e = queue.peek();
for(int i=0;i<queue.size();i++){
E temp=(E)queue.get(i);
if(e.compareTo(temp)<=0){
e=temp;
}
}
return e;
}
@Override
public E peekMinimum() {
E e = queue.peek();
for(int i=0;i<queue.size();i++){
E temp=(E)queue.get(i);
if(e.compareTo(temp)>=0){
e=temp;
}
}
return e;
}
@Override
public int size() {
return queue.size();
}
}
--------------------编程问答--------------------
Junit
补充:Java , Eclipse