7
7
8
8
package stdlib
9
9
10
+ import kotlin.test.*
11
+
10
12
fun <K , V > isEmpty (map : Map <K , V >) = map.isEmpty()
11
13
12
14
fun <K , V > getKeysAsSet (map : Map <K , V >) = map.keys
@@ -61,4 +63,67 @@ data class TripleVars<T>(var first: T, var second: T, var third: T) {
61
63
}
62
64
}
63
65
64
- fun gc () = kotlin.native.internal.GC .collect()
66
+ fun gc () = kotlin.native.internal.GC .collect()
67
+
68
+ // Note: this method checks only some of the operations (namely the ones modified recently,
69
+ // and thus required additional tests).
70
+ // More tests are absolutely needed.
71
+ @Throws(Throwable ::class )
72
+ @Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
73
+ fun testSet (set : Set <String >) {
74
+ set as kotlin.native.internal.KonanSet <String > // Smart cast to access getElement below.
75
+ val setAny: Set <Any ?> = set
76
+
77
+ assertTrue(set.contains(" a" ))
78
+ assertTrue(set.contains(" c" ))
79
+ assertFalse(set.contains(" h" ))
80
+ assertFalse(setAny.contains(1 ))
81
+
82
+
83
+ assertEquals(" a" , set.getElement(" a" ))
84
+ assertNull(set.getElement(" aa" ))
85
+ assertNull((setAny as kotlin.native.internal.KonanSet <Any ?>).getElement(1 ))
86
+ }
87
+
88
+ // Note: this method checks only some of the operations (namely the ones modified recently,
89
+ // and thus required additional tests).
90
+ // More tests are absolutely needed.
91
+ @Throws(Throwable ::class )
92
+ fun testMap (map : Map <String , Int >) {
93
+ val mapAny: Map <String , Any ?> = map
94
+ val mapKeysAny: Set <Any ?> = map.keys
95
+ val mapEntriesAny: Set <Map .Entry <Any ?, Any ?>> = map.entries
96
+
97
+ assertTrue(map.containsKey(" a" ))
98
+ assertTrue(map.keys.contains(" b" ))
99
+ assertTrue(map.containsKey(" g" ))
100
+ assertFalse(map.containsKey(" 0" ))
101
+ assertFalse(mapKeysAny.contains(1 ))
102
+
103
+ assertTrue(map.containsValue(1 ))
104
+ assertTrue(map.values.contains(2 ))
105
+ assertTrue(map.containsValue(7 ))
106
+ assertFalse(map.containsValue(8 ))
107
+ assertFalse(mapAny.containsValue(" 8" ))
108
+
109
+ assertEquals(2 , map.get(" b" ))
110
+ assertEquals(4 , map.get(" d" ))
111
+ assertNull(map.get(" h" ))
112
+
113
+ val referenceMap = (0 until 7 ).map { (' a' + it).toString() to (it + 1 ) }.toMap()
114
+ assertEquals(referenceMap.hashCode(), map.hashCode())
115
+ assertEquals(referenceMap, map)
116
+ assertEquals(map, referenceMap)
117
+
118
+ assertEquals(28 , map.entries.sumBy { it.value })
119
+
120
+ assertTrue(map.entries.contains(createMapEntry(" e" , 5 )))
121
+ assertTrue(map.entries.contains(createMapEntry(" g" , 7 )))
122
+ assertFalse(map.entries.contains(createMapEntry(" e" , 7 )))
123
+ assertFalse(map.entries.contains(createMapEntry(" e" , 10 )))
124
+ assertFalse(map.entries.contains(createMapEntry(" 10" , 5 )))
125
+ assertFalse(map.entries.contains(createMapEntry(" 10" , 10 )))
126
+ assertFalse(mapEntriesAny.contains(createMapEntry(5 , " e" )))
127
+ }
128
+
129
+ private fun <K , V > createMapEntry (key : K , value : V ) = mapOf (key to value).entries.single()
0 commit comments