-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlattenBinaryTreeToLinkedListTest.kt
37 lines (32 loc) · 1.35 KB
/
FlattenBinaryTreeToLinkedListTest.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
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.models.buildListFromTree
import ru.romanow.models.buildTreeFromList
import java.util.stream.Stream
class FlattenBinaryTreeToLinkedListTest {
@ArgumentsSource(ValueProvider::class)
@ParameterizedTest(name = "#{index} – Binary tree {0} flatten into {1}")
fun flatten(items: List<Int?>, result: List<Int>) {
val root = buildTreeFromList(items, 0)
val obj = FlattenBinaryTreeToLinkedList()
obj.flatten(root)
val list = buildListFromTree(root)
assertThat(list).isEqualTo(result)
}
internal class ValueProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<Arguments> =
Stream.of(
Arguments.of(
listOf(1, 2, 5, 3, 4, null, 6),
listOf(1, null, 2, null, 3, null, 4, null, 5, null, 6)
),
Arguments.of(listOf<Int?>(), listOf<Int?>()),
Arguments.of(listOf<Int?>(0), listOf<Int?>(0))
)
}
}