小编Vam*_*yer的帖子

如果java中有多个输出,如何使用单元测试?

如何测试返回斐波那契数列的类?我在这段代码中使用了迭代器。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)

java unit-testing fibonacci

2
推荐指数
1
解决办法
91
查看次数

标签 统计

fibonacci ×1

java ×1

unit-testing ×1