Verify index expectations for reduceIndexed/reduceRightIndexed

This commit is contained in:
Ilya Gorbunov
2016-01-28 18:03:33 +03:00
parent 1357c77d0b
commit 4f1418bb72
2 changed files with 36 additions and 0 deletions
@@ -223,6 +223,15 @@ class CollectionTest {
list.reduceIndexed { index, a, b -> if (index == 3) a else a + b }
}
expect(5) {
listOf(2, 3).reduceIndexed { index, acc: Number, e ->
assertEquals(1, index)
assertEquals(2, acc)
assertEquals(3, e)
acc.toInt() + e
}
}
assertTrue(assertFails {
arrayListOf<Int>().reduceIndexed { index, a, b -> a + b }
} is UnsupportedOperationException)
@@ -234,6 +243,15 @@ class CollectionTest {
list.reduceRightIndexed { index, a, b -> if (index == 0) b else a + b }
}
expect(1) {
listOf(2, 3).reduceRightIndexed { index, e, acc: Number ->
assertEquals(0, index)
assertEquals(3, acc)
assertEquals(2, e)
acc.toInt() - e
}
}
assertTrue(assertFails {
arrayListOf<Int>().reduceRightIndexed { index, a, b -> a + b }
} is UnsupportedOperationException)