Refactor Map-InternalMap to provide specialized linked string map and set
This commit is contained in:
@@ -55,7 +55,7 @@ class PrimitiveMapJsTest : MapJsTest() {
|
||||
}
|
||||
}
|
||||
|
||||
class LinkedHashMapTest : MapJsTest() {
|
||||
class LinkedHashMapJsTest : MapJsTest() {
|
||||
@test override fun constructors() {
|
||||
LinkedHashMap<String, Int>()
|
||||
LinkedHashMap<String, Int>(3)
|
||||
@@ -72,6 +72,19 @@ class LinkedHashMapTest : MapJsTest() {
|
||||
override fun emptyMutableMapWithNullableKeyValue(): MutableMap<String?, Int?> = LinkedHashMap()
|
||||
}
|
||||
|
||||
class LinkedPrimitiveMapJsTest : MapJsTest() {
|
||||
@test override fun constructors() {
|
||||
val map = createTestMap()
|
||||
|
||||
assertEquals(KEYS.toNormalizedList(), map.keys.toNormalizedList())
|
||||
assertEquals(VALUES.toNormalizedList(), map.values.toNormalizedList())
|
||||
}
|
||||
|
||||
override fun <T : kotlin.Comparable<T>> Collection<T>.toNormalizedList(): List<T> = this.toList()
|
||||
override fun emptyMutableMap(): MutableMap<String, Int> = linkedStringMapOf()
|
||||
override fun emptyMutableMapWithNullableKeyValue(): MutableMap<String?, Int?> = LinkedHashMap()
|
||||
}
|
||||
|
||||
abstract class MapJsTest {
|
||||
val KEYS = listOf("zero", "one", "two", "three")
|
||||
val VALUES = arrayOf(0, 1, 2, 3).toList()
|
||||
|
||||
@@ -72,6 +72,18 @@ class LinkedHashSetJsTest : SetJsTest() {
|
||||
}
|
||||
}
|
||||
|
||||
class LinkedPrimitiveSetJsTest : SetJsTest() {
|
||||
override fun createEmptyMutableSet(): MutableSet<String> = linkedStringSetOf()
|
||||
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = LinkedHashSet()
|
||||
@Test
|
||||
override fun constructors() {
|
||||
val orderedData = data.toList()
|
||||
val set = linkedStringSetOf(*orderedData.toTypedArray())
|
||||
|
||||
assertEquals(orderedData, set.toList())
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SetJsTest {
|
||||
val data: Set<String> = createTestMutableSet()
|
||||
val empty: Set<String> = createEmptyMutableSet()
|
||||
|
||||
@@ -19,4 +19,6 @@ package test.collections.js
|
||||
import java.util.*
|
||||
|
||||
public fun <V> stringMapOf(vararg pairs: Pair<String, V>): HashMap<String, V> = hashMapOf<String, V>(*pairs)
|
||||
public fun <V> linkedStringMapOf(vararg pairs: Pair<String, V>): LinkedHashMap<String, V> = linkedMapOf(*pairs)
|
||||
public fun stringSetOf(vararg elements: String): HashSet<String> = hashSetOf(*elements)
|
||||
public fun linkedStringSetOf(vararg elements: String): LinkedHashSet<String> = linkedSetOf(*elements)
|
||||
|
||||
Reference in New Issue
Block a user