Introduce sumOf with various selector types

#KT-11253
This commit is contained in:
Ilya Gorbunov
2020-04-26 23:00:08 +03:00
parent bdd53ee9cd
commit 6a24becd1d
13 changed files with 1932 additions and 2 deletions
@@ -62,6 +62,18 @@ class BigNumbersTest {
assertEquals(BigInteger("2"), c)
}
@Test fun sumOfBigInteger() {
val numbers = (1..10).map { it.toBigInteger() }
val i55 = 55.toBigInteger()
assertEquals(i55, numbers.sumOf { it })
assertEquals(i55, numbers.asSequence().sumOf { it })
assertEquals(i55, numbers.toTypedArray().sumOf { it })
val chars = ('0'..'9').joinToString("")
assertEquals(i55, chars.sumOf { it.toString().toBigInteger().inc() })
assertEquals(i55, chars.toCharArray().sumOf { it.toString().toBigInteger().inc() })
}
@Test fun testBigDecimal() {
val a = BigDecimal("2")
val b = BigDecimal("3")
@@ -103,5 +115,17 @@ class BigNumbersTest {
assertEquals(d4, d7 / d2)
assertEquals(d1, d7 / d5)
}
@Test fun sumOfBigDecimal() {
val numbers = (1..10).map { it.toBigDecimal() }
val d55 = 55.toBigDecimal()
assertEquals(d55, numbers.sumOf { it })
assertEquals(d55, numbers.asSequence().sumOf { it })
assertEquals(d55, numbers.toTypedArray().sumOf { it })
val chars = ('0'..'9').joinToString("")
assertEquals(d55, chars.sumOf { it.toString().toBigDecimal().inc() })
assertEquals(d55, chars.toCharArray().sumOf { it.toString().toBigDecimal().inc() })
}
}