Move groupingByEachCount together with the new Grouping samples

This commit is contained in:
Ilya Gorbunov
2018-09-28 18:15:48 +03:00
parent 039d41679e
commit 3a40e3f041
9 changed files with 21 additions and 17 deletions
@@ -369,17 +369,7 @@ class Collections {
assertTrue(mutableNamesByTeam == namesByTeam)
}
@Sample
fun groupingByEachCount() {
val words = "one two three four five six seven eight nine ten".split(' ')
val frequenciesByFirstChar = words.groupingBy { it.first() }.eachCount()
println("Counting first letters:")
assertPrints(frequenciesByFirstChar, "{o=1, t=3, f=2, s=2, e=1, n=1}")
val moreWords = "eleven twelve".split(' ')
val moreFrequencies = moreWords.groupingBy { it.first() }.eachCountTo(frequenciesByFirstChar.toMutableMap())
assertPrints(moreFrequencies, "{o=1, t=4, f=2, s=2, e=2, n=1}")
}
@Sample
fun joinTo() {
@@ -10,6 +10,20 @@ import java.util.stream.Collector
import kotlin.test.*
class Grouping {
@Sample
fun groupingByEachCount() {
val words = "one two three four five six seven eight nine ten".split(' ')
val frequenciesByFirstChar = words.groupingBy { it.first() }.eachCount()
println("Counting first letters:")
assertPrints(frequenciesByFirstChar, "{o=1, t=3, f=2, s=2, e=1, n=1}")
val moreWords = "eleven twelve".split(' ')
val moreFrequencies = moreWords.groupingBy { it.first() }.eachCountTo(frequenciesByFirstChar.toMutableMap())
assertPrints(moreFrequencies, "{o=1, t=4, f=2, s=2, e=2, n=1}")
}
@Sample
fun aggregateEvenAndOdd() {
val intList = listOf(0, 1, 2, 3, 4, 5, 6)