-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteNodeInABalancedSearchTreeTest.kt
32 lines (28 loc) · 1.35 KB
/
DeleteNodeInABalancedSearchTreeTest.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
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 DeleteNodeInABalancedSearchTreeTest {
@ArgumentsSource(ValueProvider::class)
@ParameterizedTest(name = "#{index} – Tree {0} after removing key {1} is {2}")
fun deleteNode(values: List<Int?>, key: Int, expectedResult: List<Int?>) {
val obj = DeleteNodeInABalancedSearchTree()
val root = buildTreeFromList(values, 0)
val result = buildListFromTree(obj.deleteNode(root, key))
assertThat(result).isEqualTo(expectedResult)
}
internal class ValueProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<Arguments> =
Stream.of(
Arguments.of(listOf(5, 3, 6, 2, 4, null, 7), 3, listOf(5, 4, 6, 2, null, null, 7)),
Arguments.of(listOf(5, 3, 6, 2, 4, null, 7), 0, listOf(5, 3, 6, 2, 4, null, 7)),
Arguments.of(listOf<Int?>(), 0, listOf<Int?>())
)
}
}