Newer
Older
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
import but3.collections.EmptyBSTException
import but3.collections.IterativeBinarySearchTree
import but3.collections.KeyNotFoundException
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
class TestIte6Remove {
lateinit var bst: IterativeBinarySearchTree<Int>
@BeforeEach
fun initialise() {
bst = IterativeBinarySearchTree.buildFrom(10, 3, 5, 7, 100, 30, 20, 45, 50, 48, 60, 10000)
}
@Test
fun empty() {
bst = IterativeBinarySearchTree()
assertThrows<EmptyBSTException> { bst.removeB(42) }
}
@ParameterizedTest(name = "removed value {0} : impossible")
@CsvSource(
"42,4",
"2,2",
"0,2",
"1000,3",
"-3,2",
"666,3"
)
fun removeImpossible(contained: Int, expectedCalls: Int) {
assertThrows<KeyNotFoundException> { bst.removeB(contained) }
}
@ParameterizedTest(name = "element removed : {0}")
@CsvSource(
"5,3,6",
"7,4,7",
"10,5,9",
"20,4,7",
"30,5,9",
"45,4,9",
"48,6,11",
"50,7,13",
"60,6,11",
"100,4,10",
"10000,3,5"
)
fun remove(removed: Int, expectedCalls: Int, expectedCalls2: Int) {
bst.removeB(removed)
assertFalse(bst.containsB(removed))
}
@Test
fun removeAll() {
val elements = listOf(10, 3, 5, 7, 100, 30, 20, 45, 50, 48, 60, 10000)
elements.forEach {
bst.removeB(it)
}
assertTrue(bst.isEmpty())
}
}