Clean warnings and refactor stdlib tests.
Merge RangeJVMTest into RangeTest.
This commit is contained in:
@@ -760,7 +760,7 @@ class ArraysTest {
|
||||
expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceIndexed { index, a, b -> if (index != 2) (a - b).toShort() else a.toShort() } }
|
||||
|
||||
assertFailsWith<UnsupportedOperationException> {
|
||||
intArrayOf().reduceIndexed { index, a, b -> a + b }
|
||||
intArrayOf().reduceIndexed { index, a, b -> index + a + b }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ class ArraysTest {
|
||||
expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceRightIndexed { index, a, b -> if (index != 1) (a - b).toShort() else a.toShort() } }
|
||||
|
||||
assertFailsWith<UnsupportedOperationException> {
|
||||
intArrayOf().reduceRightIndexed { index, a, b -> a + b }
|
||||
intArrayOf().reduceRightIndexed { index, a, b -> index + a + b }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1056,6 +1056,7 @@ class ArraysTest {
|
||||
val arr1: Array<Array<Int>> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6))
|
||||
val arr2: Array<out Array<Int>> = arr1
|
||||
val arr3: Array<out Array<out Int>> = arr1
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val arr4: Array<Array<out Int>> = arr1 as Array<Array<out Int>>
|
||||
|
||||
val expected = listOf(1, 2, 3, 4, 5, 6)
|
||||
|
||||
@@ -215,8 +215,3 @@ class CollectionJVMTest {
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun assertTypeEquals(expected: Any?, actual: Any?) {
|
||||
assertEquals(expected?.javaClass, actual?.javaClass)
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ class CollectionTest {
|
||||
}
|
||||
|
||||
assertFailsWith<UnsupportedOperationException> {
|
||||
arrayListOf<Int>().reduceIndexed { index, a, b -> a + b }
|
||||
arrayListOf<Int>().reduceIndexed { index, a, b -> index + a + b }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ class CollectionTest {
|
||||
}
|
||||
|
||||
assertFailsWith<UnsupportedOperationException> {
|
||||
arrayListOf<Int>().reduceRightIndexed { index, a, b -> a + b }
|
||||
arrayListOf<Int>().reduceRightIndexed { index, a, b -> index + a + b }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,6 +626,7 @@ class CollectionTest {
|
||||
|
||||
// lists throw an exception if out of range
|
||||
assertFails {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val outOfBounds = list[2]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package test.collections
|
||||
|
||||
import test.*
|
||||
import kotlin.test.*
|
||||
|
||||
public fun <T> compare(expected: T, actual: T, block:CompareContext<T>.() -> Unit) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class GroupingTest {
|
||||
|
||||
val elements = listOf("foo", "bar", "flea", "zoo", "biscuit")
|
||||
val result = elements.groupingBy { it.first() }
|
||||
.fold({ k, e -> Collector<Char, String>(k)}, { k, acc, e -> acc.accumulateIfEven(e) })
|
||||
.fold({ k, _ -> Collector<Char, String>(k)}, { _, acc, e -> acc.accumulateIfEven(e) })
|
||||
|
||||
val ordered = result.values.sortedBy { it.key }.map { it.toPair() }
|
||||
assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea"), 'z' to emptyList()), ordered)
|
||||
@@ -62,8 +62,8 @@ class GroupingTest {
|
||||
val moreElements = listOf("fire", "zero")
|
||||
val result2 = moreElements.groupingBy { it.first() }
|
||||
.foldTo(HashMap(result),
|
||||
{ k, e -> error("should not be called for $k") },
|
||||
{ k, acc, e -> acc.accumulateIfEven(e) })
|
||||
{ k, _ -> error("should not be called for $k") },
|
||||
{ _, acc, e -> acc.accumulateIfEven(e) })
|
||||
|
||||
val ordered2 = result2.values.sortedBy { it.key }.map { it.toPair() }
|
||||
assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea", "fire"), 'z' to listOf("zero")), ordered2)
|
||||
@@ -75,12 +75,12 @@ class GroupingTest {
|
||||
val elements = listOf("foo", "bar", "flea", "zoo", "biscuit")
|
||||
fun Char.isVowel() = this in "aeiou"
|
||||
fun String.countVowels() = count(Char::isVowel)
|
||||
val maxVowels = elements.groupingBy { it.first() }.reduce { k, a, b -> maxOfBy(a, b, String::countVowels) }
|
||||
val maxVowels = elements.groupingBy { it.first() }.reduce { _, a, b -> maxOfBy(a, b, String::countVowels) }
|
||||
|
||||
assertEquals(mapOf('f' to "foo", 'b' to "biscuit", 'z' to "zoo"), maxVowels)
|
||||
|
||||
val elements2 = listOf("bar", "z", "fork")
|
||||
val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { k, acc, e -> acc + e }
|
||||
val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { _, acc, e -> acc + e }
|
||||
|
||||
assertEquals(mapOf('f' to "foofork", 'b' to "biscuitbar", 'z' to "zooz"), concats)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package test.collections
|
||||
|
||||
import org.junit.Test
|
||||
import test.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun <T> iterableOf(vararg items: T): Iterable<T> = Iterable { items.iterator() }
|
||||
@@ -200,7 +201,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
assertTrue(data === newData)
|
||||
|
||||
// static types test
|
||||
val list: ArrayList<Int> = arrayListOf(1, 2, 3).onEach { }
|
||||
assertStaticTypeIs<ArrayList<Int>>(arrayListOf(1, 2, 3).onEach { })
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package test.collections
|
||||
|
||||
import kotlin.test.*
|
||||
import test.*
|
||||
import org.junit.Test
|
||||
|
||||
class MapTest {
|
||||
|
||||
// just a static type check
|
||||
fun <T> assertStaticTypeIs(value: T) {}
|
||||
|
||||
@Test fun getOrElse() {
|
||||
val data = mapOf<String, Int>()
|
||||
val a = data.getOrElse("foo") { 2 }
|
||||
@@ -109,7 +107,9 @@ class MapTest {
|
||||
assertTrue(map === newMap)
|
||||
|
||||
// static types test
|
||||
val m: HashMap<String, String> = hashMapOf("a" to "b").onEach { }
|
||||
assertStaticTypeIs<HashMap<String, String>>(
|
||||
hashMapOf("a" to "b").onEach { }
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun stream() {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SequenceTest {
|
||||
}
|
||||
|
||||
@Test fun filterIndexed() {
|
||||
assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, value -> index % 2 == 1 }.take(5).toList())
|
||||
assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, _ -> index % 2 == 1 }.take(5).toList())
|
||||
}
|
||||
|
||||
@Test fun filterNullable() {
|
||||
|
||||
Reference in New Issue
Block a user