-
Notifications
You must be signed in to change notification settings - Fork 1
/
MinMaxCountAvg.kt
34 lines (30 loc) · 939 Bytes
/
MinMaxCountAvg.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.kollektions.examples.consumers
import org.kollektions.consumers.*
import org.kollektions.transformations.mapTo
import java.math.BigDecimal
import java.util.*
import kotlin.test.Test
import kotlin.test.assertEquals
class MinMaxCountAvg {
@Test
fun iterateOnceGetSeveralResults() {
val actual = (1..10).asSequence()
.consume(min(),
max(),
count(),
avgOfInt(),
mapTo { it: Int -> it.toLong() }.avgOfLong(),
mapTo { it: Int -> BigDecimal.valueOf(it.toLong()) }.avgOfBigDecimal()
)
print(actual)
assertEquals(
listOf(Optional.of(1),
Optional.of(10),
10L,
Optional.of(BigDecimal("5.50")),
Optional.of(BigDecimal("5.50")),
Optional.of(BigDecimal("5.50"))
),
actual)
}
}