Skip to content

Commit 0915fcf

Browse files
committed
more tests
1 parent ac3d57f commit 0915fcf

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

src/test/kotlin/io/vavr/kotlin/CollectionsKtTest.kt

+51-9
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,115 @@ import org.junit.Test
55
class CollectionsKtTest {
66
@Test
77
fun list() {
8-
val list = list(1, 2, 3)
8+
val list: io.vavr.collection.List<Int> = list(1, 2, 3)
99
assert(list.size() == 3)
1010
}
1111

1212
@Test
1313
fun toMutableList() {
14-
val mutableList = list(1, 2, 3).toMutableList()
14+
val mutableList: List<Int> = list(1, 2, 3).toMutableList()
1515
assert(mutableList.size == 3)
1616
}
1717

1818
@Test
19-
fun toVavrList() {
20-
val vavrList = listOf(1, 2, 3).toVavrList()
19+
fun toVavrList1() {
20+
val vavrList: io.vavr.collection.List<Int> = listOf(1, 2, 3).toVavrList()
21+
assert(vavrList.size() == 3)
22+
}
23+
24+
@Test
25+
fun toVavrList2() {
26+
val vavrList: io.vavr.collection.List<Int> = arrayOf(1, 2, 3).toVavrList()
2127
assert(vavrList.size() == 3)
2228
}
2329

2430
@Test
2531
fun stream() {
26-
val stream = stream(1, 2, 3)
32+
val stream: io.vavr.collection.Stream<Int> = stream(1, 2, 3)
2733
assert(stream.size() == 3)
2834
}
2935

3036
@Test
31-
fun toJsStream() {
37+
fun toVavrStream1() {
38+
val vavrStream: io.vavr.collection.Stream<Int> = listOf(1, 2, 3).toVavrStream()
39+
assert(vavrStream.size() == 3)
40+
}
41+
42+
@Test
43+
fun toVavrStream2() {
44+
val vavrStream: io.vavr.collection.Stream<Int> = arrayOf(1, 2, 3).toVavrStream()
45+
assert(vavrStream.size() == 3)
3246
}
3347

3448
@Test
35-
fun toJsStream1() {
49+
fun toVavrStream3() {
50+
val vavrStream: io.vavr.collection.Stream<Int> = generateSequence(1, { i -> i + 1 }).take(3).toVavrStream()
51+
assert(vavrStream.size() == 3)
3652
}
3753

3854
@Test
39-
fun toJsMap() {
55+
fun toVavrMap() {
56+
val vavrMap: io.vavr.collection.Map<Int, Int> = hashMapOf(Pair(1, 2)).toVavrMap()
57+
assert(vavrMap.get(1).get() == 2)
4058
}
4159

4260
@Test
4361
fun toMutableMap() {
62+
val mutableMap: Map<Int, Int> = io.vavr.collection.HashMap.of(1, 2).toMutableMap()
63+
assert(mutableMap[1] == 2)
4464
}
4565

4666
@Test
4767
fun hashMap() {
68+
val vavrMap: io.vavr.collection.HashMap<Int, Int> = hashMap(Pair(1, 2))
69+
assert(vavrMap.get(1).get() == 2)
4870
}
4971

5072
@Test
5173
fun linkedHashMap() {
74+
val vavrMap: io.vavr.collection.LinkedHashMap<Int, Int> = linkedHashMap(Pair(1, 2))
75+
assert(vavrMap.get(1).get() == 2)
5276
}
5377

5478
@Test
5579
fun treeMap() {
80+
val vavrMap: io.vavr.collection.Map<Int, Int> = treeMap(Pair(1, 2))
81+
assert(vavrMap.get(1).get() == 2)
5682
}
5783

5884
@Test
59-
fun toJsSet() {
85+
fun toVavrSet() {
86+
val vavrSet: io.vavr.collection.Set<Int> = hashSetOf(1, 2, 3).toVavrSet()
87+
assert(vavrSet.size() == 3)
6088
}
6189

6290
@Test
6391
fun toMutableSet() {
92+
val mutableSet: Set<Int> = io.vavr.collection.HashSet.of(1, 2, 3).toMutableSet()
93+
assert(mutableSet.size == 3)
6494
}
6595

6696
@Test
6797
fun hashSet() {
98+
val vavrSet: io.vavr.collection.HashSet<Int> = hashSet(1, 2, 3)
99+
assert(vavrSet.size() == 3)
68100
}
69101

70102
@Test
71103
fun linkedHashSet() {
104+
val vavrSet: io.vavr.collection.LinkedHashSet<Int> = linkedHashSet(1, 2, 3)
105+
assert(vavrSet.size() == 3)
72106
}
73107

74108
@Test
75109
fun treeSet() {
110+
val vavrSet: io.vavr.collection.TreeSet<Int> = treeSet(1, 2, 3)
111+
assert(vavrSet.size() == 3)
112+
}
113+
114+
@Test
115+
fun getOrNull() {
116+
assert(hashMap(Pair(1, 2)).getOrNull(1) == 2)
117+
assert(hashMap(Pair(1, 2)).getOrNull(2) == null)
76118
}
77119
}

src/test/kotlin/io/vavr/kotlin/ControlKtTest.kt

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ class ControlKtTest {
1111

1212
// -- Option
1313

14+
@Test
15+
fun createFromNull() {
16+
val opt = null.option()
17+
assert(opt.isEmpty)
18+
}
19+
20+
@Test
21+
fun createFromNonNull() {
22+
val opt = 1.option()
23+
assert(opt.get() == 1)
24+
}
25+
1426
@Test
1527
fun createSomeNull() {
1628
val some = some(null)

0 commit comments

Comments
 (0)