Kotlin,如何测试(int)数组

我想找一个好的简明的方式来测试intarray

起初我试了一下

mFaces[0].mIndices shouldBe intArrayOf(0, 1, 2)

mIndices在哪里

var mIndices: IntArray = IntArray(0)

但失败。 Intellij也建议我用Array来覆盖equals()

然后我想尝试这样的事情

mFaces[0].mIndices.all { it. == index } shouldBe true

但它看起来像没有办法检索all{..}的索引或是这样的

 var p = 0 mFaces[0].mIndices.all { it == p++ } shouldBe true 

唯一的可能性?

在Java(Kotlin)中,数组通过引用而不是内容进行比较。 这意味着intArrayOf(1, 2, 3) != intArrayOf(1, 2, 3)

要比较数组的内容,您有两个选项:

  1. 使用深度比较:

    Arrays.deepequals(mFaces[0].mIndices, intArrayOf(0, 1, 2))

  2. 使用列表:

    mFaces[0].mIndices.toList() == listOf(0, 1, 2)