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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
package moe.nea.firmament.test.features.macros
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import net.minecraft.client.util.InputUtil
import moe.nea.firmament.features.macros.Branch
import moe.nea.firmament.features.macros.ComboKeyAction
import moe.nea.firmament.features.macros.CommandAction
import moe.nea.firmament.features.macros.KeyComboTrie
import moe.nea.firmament.features.macros.Leaf
import moe.nea.firmament.keybindings.SavedKeyBinding
class KeyComboTrieCreation {
val basicAction = CommandAction("ac Hello")
val aPress = SavedKeyBinding(InputUtil.GLFW_KEY_A)
val bPress = SavedKeyBinding(InputUtil.GLFW_KEY_B)
val cPress = SavedKeyBinding(InputUtil.GLFW_KEY_C)
@Test
fun testValidShortTrie() {
val actions = listOf(
ComboKeyAction(basicAction, listOf(aPress)),
ComboKeyAction(basicAction, listOf(bPress)),
ComboKeyAction(basicAction, listOf(cPress)),
)
Assertions.assertEquals(
Branch(
mapOf(
aPress to Leaf(basicAction),
bPress to Leaf(basicAction),
cPress to Leaf(basicAction),
),
), KeyComboTrie.fromComboList(actions)
)
}
@Test
fun testOverlappingLeafs() {
Assertions.assertThrows(IllegalStateException::class.java) {
KeyComboTrie.fromComboList(
listOf(
ComboKeyAction(basicAction, listOf(aPress, aPress)),
ComboKeyAction(basicAction, listOf(aPress, aPress)),
)
)
}
Assertions.assertThrows(IllegalStateException::class.java) {
KeyComboTrie.fromComboList(
listOf(
ComboKeyAction(basicAction, listOf(aPress)),
ComboKeyAction(basicAction, listOf(aPress)),
)
)
}
}
@Test
fun testBranchOverlappingLeaf() {
Assertions.assertThrows(IllegalStateException::class.java) {
KeyComboTrie.fromComboList(
listOf(
ComboKeyAction(basicAction, listOf(aPress)),
ComboKeyAction(basicAction, listOf(aPress, aPress)),
)
)
}
}
@Test
fun testLeafOverlappingBranch() {
Assertions.assertThrows(IllegalStateException::class.java) {
KeyComboTrie.fromComboList(
listOf(
ComboKeyAction(basicAction, listOf(aPress, aPress)),
ComboKeyAction(basicAction, listOf(aPress)),
)
)
}
}
@Test
fun testValidNestedTrie() {
val actions = listOf(
ComboKeyAction(basicAction, listOf(aPress, aPress)),
ComboKeyAction(basicAction, listOf(aPress, bPress)),
ComboKeyAction(basicAction, listOf(cPress)),
)
Assertions.assertEquals(
Branch(
mapOf(
aPress to Branch(
mapOf(
aPress to Leaf(basicAction),
bPress to Leaf(basicAction),
)
),
cPress to Leaf(basicAction),
),
), KeyComboTrie.fromComboList(actions)
)
}
}
|