-
Notifications
You must be signed in to change notification settings - Fork 0
/
LRUCacheTest.kt
66 lines (60 loc) · 2.05 KB
/
LRUCacheTest.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
59
60
61
62
63
64
65
66
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.LRUCacheTest.OperationType.GET
import ru.romanow.LRUCacheTest.OperationType.PUT
import java.util.stream.Stream
class LRUCacheTest {
@ParameterizedTest
@ArgumentsSource(ValueProvider::class)
fun test(operations: List<Operation>) {
val cache = LRUCache(2)
for (op in operations) {
when (op.type) {
GET -> assertThat(cache.get(op.key)).isEqualTo(op.value)
PUT -> cache.put(op.key, op.value)
}
}
}
internal class ValueProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<Arguments> =
Stream.of(
Arguments.of(
listOf(
Operation(PUT, 1, 1),
Operation(PUT, 2, 2),
Operation(GET, 1, 1),
Operation(PUT, 3, 3),
Operation(GET, 2, -1),
Operation(PUT, 4, 4),
Operation(GET, 1, -1),
Operation(GET, 3, 3),
Operation(GET, 4, 4)
)
),
Arguments.of(
listOf(
Operation(PUT, 2, 1),
Operation(PUT, 2, 2),
Operation(GET, 2, 2),
Operation(PUT, 1, 1),
Operation(PUT, 4, 1),
Operation(GET, 2, -1)
)
)
)
}
data class Operation(
val type: OperationType,
val key: Int,
val value: Int,
)
enum class OperationType {
PUT,
GET
}
}