来自kotlinlang.org的这个片段中的test(0)是什么?

时间:2017-08-11 09:34:43

标签: unit-testing testing kotlin

我试图解决"运行"在KotlinKoans页面here

这是我的实施

package runs

fun runs(a: IntArray): Int {
    var numberOfRuns = 1;

    for (index in 0..a.size-2) {
        if (a[index+1] != a[index]) numberOfRuns++
    }

    return numberOfRuns
}

这是针对实现运行的测试套件

class Tests {

    @Test fun testRuns1() {
        test(0)
    }

    @Test fun testRuns2() {
        test(1, 1)
    }

    @Test fun testRuns3() {
        test(3, 1, 2, 3)
    }

    @Test fun testRuns4() {
        test(3, 1, 2, 2, 3)
    }

    @Test fun testRuns5() {
        test(3, 1, 1, 2, 3)
    }

    @Test fun testRuns6() {
        test(1, 1, 1, 1, 1)
    }

    @Test fun testRuns7() {
        test(3, 1, 1, 1, 0, 1, 1)
    }

    @Test fun testRuns8() {
        test(3, 1, 1, 1, 0, 1)
    }

    @Test fun testRuns9() {
        test(5, 1, 0, 1, 0, 1)
    }
}

fun test(expected: Int, vararg data: Int) {
    assertEquals(expected, runs(data), "\ndata = ${Arrays.toString(data)}")
}

除了testRuns1()之外的所有测试通道,我都不了解test(0)的作用,因为test()函数将两个参数作为输入,一个期望值和实际值。我错过了什么?

0 个答案:

没有答案