Covering stdlib with tests.
This commit is contained in:
@@ -2,6 +2,5 @@ package test.collections
|
|||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LinkedSetTest : OrderedIterableTests<Set<String>>(setOf("foo", "bar"), setOf<String>())
|
|
||||||
class LinkedListTest : OrderedIterableTests<LinkedList<String>>(linkedListOf("foo", "bar"), linkedListOf<String>())
|
class LinkedListTest : OrderedIterableTests<LinkedList<String>>(linkedListOf("foo", "bar"), linkedListOf<String>())
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class IterableWrapper<T>(collection: Iterable<T>) : Iterable<T> {
|
|||||||
|
|
||||||
class IterableTest : IterableTests<Iterable<String>>(iterableOf("foo", "bar"), iterableOf<String>())
|
class IterableTest : IterableTests<Iterable<String>>(iterableOf("foo", "bar"), iterableOf<String>())
|
||||||
class SetTest : IterableTests<Set<String>>(setOf("foo", "bar"), setOf<String>())
|
class SetTest : IterableTests<Set<String>>(setOf("foo", "bar"), setOf<String>())
|
||||||
|
class LinkedSetTest : IterableTests<LinkedHashSet<String>>(linkedSetOf("foo", "bar"), linkedSetOf<String>())
|
||||||
class ListTest : OrderedIterableTests<List<String>>(listOf("foo", "bar"), listOf<String>())
|
class ListTest : OrderedIterableTests<List<String>>(listOf("foo", "bar"), listOf<String>())
|
||||||
class ArrayListTest : OrderedIterableTests<ArrayList<String>>(arrayListOf("foo", "bar"), arrayListOf<String>())
|
class ArrayListTest : OrderedIterableTests<ArrayList<String>>(arrayListOf("foo", "bar"), arrayListOf<String>())
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,38 @@ class MapTest {
|
|||||||
assertEquals(2, filteredByValue2["a"])
|
assertEquals(2, filteredByValue2["a"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test fun any() {
|
||||||
|
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||||
|
assertTrue(map.any())
|
||||||
|
assertFalse(emptyMap<String, Int>().any())
|
||||||
|
|
||||||
|
assertTrue(map.any { it.key == "b" })
|
||||||
|
assertFalse(emptyMap<String, Int>().any { it.key == "b" })
|
||||||
|
|
||||||
|
assertTrue(map.any { it.value == 2 })
|
||||||
|
assertFalse(map.any { it.value == 5 })
|
||||||
|
}
|
||||||
|
|
||||||
|
test fun all() {
|
||||||
|
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||||
|
assertTrue(map.all { it.key != "d" })
|
||||||
|
assertTrue(emptyMap<String, Int>().all { it.key == "d" })
|
||||||
|
|
||||||
|
assertTrue(map.all { it.value > 0 })
|
||||||
|
assertFalse(map.all { it.value == 2 })
|
||||||
|
}
|
||||||
|
|
||||||
|
test fun countBy() {
|
||||||
|
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||||
|
assertEquals(3, map.count())
|
||||||
|
|
||||||
|
val filteredByKey = map.count { it.key == "b" }
|
||||||
|
assertEquals(1, filteredByKey)
|
||||||
|
|
||||||
|
val filteredByValue = map.count { it.value == 2 }
|
||||||
|
assertEquals(2, filteredByValue)
|
||||||
|
}
|
||||||
|
|
||||||
test fun filterNot() {
|
test fun filterNot() {
|
||||||
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||||
val filteredByKey = map.filterNot { it.key == "b" }
|
val filteredByKey = map.filterNot { it.key == "b" }
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ public class StreamTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test fun withIndex() {
|
||||||
|
val data = streamOf("foo", "bar")
|
||||||
|
val indexed = data.withIndex().map { it.value.substring(0..it.index) }.toList()
|
||||||
|
assertEquals(2, indexed.size())
|
||||||
|
assertEquals(listOf("f", "ba"), indexed)
|
||||||
|
}
|
||||||
|
|
||||||
test fun filterAndTakeWhileExtractTheElementsWithinRange() {
|
test fun filterAndTakeWhileExtractTheElementsWithinRange() {
|
||||||
assertEquals(listOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList())
|
assertEquals(listOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList())
|
||||||
}
|
}
|
||||||
@@ -99,6 +106,7 @@ public class StreamTest {
|
|||||||
|
|
||||||
test fun dropWhile() {
|
test fun dropWhile() {
|
||||||
assertEquals("233, 377, 610", fibonacci().dropWhile { it < 200 }.take(3).joinToString(limit = 10))
|
assertEquals("233, 377, 610", fibonacci().dropWhile { it < 200 }.take(3).joinToString(limit = 10))
|
||||||
|
assertEquals("", streamOf(1).dropWhile { it < 200 }.joinToString(limit = 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
test fun merge() {
|
test fun merge() {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class PrimitiveSetJsTest : SetJsTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkedHashSetTest : SetJsTest() {
|
class LinkedHashSetJsTest : SetJsTest() {
|
||||||
override fun createEmptyMutableSet(): MutableSet<String> = LinkedHashSet()
|
override fun createEmptyMutableSet(): MutableSet<String> = LinkedHashSet()
|
||||||
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = LinkedHashSet()
|
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = LinkedHashSet()
|
||||||
Test override fun constructors() {
|
Test override fun constructors() {
|
||||||
|
|||||||
Reference in New Issue
Block a user