-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionsSpec.kt
55 lines (47 loc) · 1.9 KB
/
CollectionsSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.emaginalabs.wecodeproperties
import io.kotlintest.properties.forAll
import io.kotlintest.specs.ShouldSpec
class CollectionsSpec : ShouldSpec() {
init {
"Collections" {
should("contain one more element after insertion") {
forAll { list: List<Int>, a: Int ->
(list + a).contains(a)
}
}
should("contain the inserted element") {
forAll { list: List<Int>, a: Int ->
(list + a).size == list.size + 1
}
}
should("have an element less after deletion") {
forAll { list: List<Int>, a: Int ->
val numberOfAs = list.count { it == a }
val listIncludingA = list + a
val listWithNoAs = listIncludingA.filter { it != a }
listWithNoAs.size == list.size - numberOfAs
}
}
should("not contain the removed element") {
forAll { list: List<Int>, a: Int ->
val listIncludingA = list + a
val listWithNoAs = listIncludingA.filter { it != a }
!listWithNoAs.contains(a)
}
}
should("contain the items of the two collections after a concatenation") {
forAll { list1: List<String>, list2: List<String> ->
val joinedList = list1 + list2
joinedList.containsAll(list1) && joinedList.containsAll(list2)
}
}
should("no duplicated elements when convert to a set") {
forAll { list: List<Int> ->
val asSet = list.toSet()
val distinct = list.distinct()
asSet.containsAll(distinct) && distinct.containsAll(asSet)
}
}
}
}
}