-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrefixTreeTest.kt
56 lines (50 loc) · 1.81 KB
/
PrefixTreeTest.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
package ru.romanow
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import ru.romanow.PrefixTreeTest.OperationType.INSERT
import ru.romanow.PrefixTreeTest.OperationType.SEARCH
import ru.romanow.PrefixTreeTest.OperationType.START_WITH
import java.util.stream.Stream
class PrefixTreeTest {
@ParameterizedTest
@ArgumentsSource(ValueProvider::class)
fun test(operations: List<Operation>) {
val obj = PrefixTree()
for (op in operations) {
when (op.type) {
INSERT -> obj.insert(op.value)
SEARCH -> assertThat(obj.search(op.value)).isEqualTo(op.result)
START_WITH -> assertThat(obj.startsWith(op.value)).isEqualTo(op.result)
}
}
}
internal class ValueProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<Arguments> =
Stream.of(
Arguments.of(
listOf(
Operation(INSERT, "apple"),
Operation(SEARCH, "apple", true),
Operation(SEARCH, "app", false),
Operation(START_WITH, "app", true),
Operation(INSERT, "app"),
Operation(SEARCH, "app", true)
)
)
)
}
data class Operation(
val type: OperationType,
val value: String,
val result: Boolean? = null,
)
enum class OperationType {
INSERT,
SEARCH,
START_WITH
}
}