generated from Jadarma/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionsUtilTest.kt
58 lines (52 loc) · 1.73 KB
/
CollectionsUtilTest.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
56
57
58
package aockt.util
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
@DisplayName("Utils: Collections")
class CollectionsUtilTest : FunSpec({
context("Permutations") {
test("generate simple permutations correctly") {
val list = listOf(1, 2, 3)
val permutations = listOf(
listOf(1, 2, 3),
listOf(1, 3, 2),
listOf(2, 1, 3),
listOf(2, 3, 1),
listOf(3, 1, 2),
listOf(3, 2, 1),
)
list.generatePermutations().toList() shouldContainExactlyInAnyOrder permutations
}
test("only work for small collections") {
val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
shouldThrow<Exception> { list.generatePermutations() }
}
}
context("Power Sets") {
test("generate simple power sets") {
val items = listOf(1, 2, 3)
val powerSet = listOf(
emptyList(),
listOf(1),
listOf(2),
listOf(3),
listOf(1, 2),
listOf(1, 3),
listOf(2, 3),
listOf(1, 2, 3),
)
items.powerSet() shouldContainExactlyInAnyOrder powerSet
}
test("work with duplicate items") {
val items = listOf(1, 1)
val powerSet = listOf(
emptyList(),
listOf(1),
listOf(1),
listOf(1, 1),
)
items.powerSet() shouldContainExactlyInAnyOrder powerSet
}
}
})