如何测试返回斐波那契数列的类?我在这段代码中使用了迭代器。FibonacciIteratorTest 类如下。
public class FibonacciIterator implements Iterator<Integer>, Iterable<Integer>{
private int num1;
private int num2;
private int num3;
private int count;
private int to;
public FibonacciIterator(int to){
this.num1 = 0;
this.num2 = 1;
this.to = to;
this.count = -1;
}
public static Iterable<Integer> to(int num){
return new FibonacciIterator(num);
}
@Override
public Iterator<Integer> iterator(){
return this;
}
@Override
public boolean hasNext(){
if(count < to){
count++;
return true;
}
return false;
}
@Override
public Integer next(){
if(count < 2){
return count;
}
num3 …Run Code Online (Sandbox Code Playgroud)