File tree 1 file changed +50
-1
lines changed
src/test/kotlin/com/igorwojda/binarytree/validate
1 file changed +50
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com.igorwojda.binarytree.validate
2
2
3
3
import org.amshove.kluent.shouldBeEqualTo
4
+ import org.amshove.kluent.shouldEqual
4
5
import org.junit.jupiter.api.Test
5
6
6
7
private fun isValidSearchBinaryTree (node : Node <Int >): Boolean {
@@ -29,7 +30,7 @@ private class Test {
29
30
}
30
31
31
32
@Test
32
- fun `Validate invalid BST` () {
33
+ fun `Validate invalid BST 1 ` () {
33
34
// -- -------Tree------------
34
35
//
35
36
// 10
@@ -50,6 +51,54 @@ private class Test {
50
51
51
52
isValidSearchBinaryTree(node) shouldBeEqualTo false
52
53
}
54
+
55
+ @Test
56
+ fun `Validate invalid BST 2` () {
57
+ // -- -------Tree------------
58
+ //
59
+ // 10
60
+ // / \
61
+ // 5 15
62
+ // / \
63
+ // 0 20
64
+ // / \
65
+ // -1 999
66
+ // --------------------------
67
+
68
+ val node = Node (10 )
69
+ node.insert(5 )
70
+ node.insert(15 )
71
+ node.insert(0 )
72
+ node.insert(- 1 )
73
+ node.insert(20 )
74
+ node.left?.left?.right = Node (999 )
75
+
76
+ isValidSearchBinaryTree(node) shouldEqual false
77
+ }
78
+
79
+ @Test
80
+ fun `Validate invalid BST 3` () {
81
+ // -- -------Tree------------
82
+ //
83
+ // 10
84
+ // / \
85
+ // 5 15
86
+ // / \
87
+ // 0 20
88
+ // / \
89
+ // 999 21
90
+ // --------------------------
91
+
92
+ val node = Node (10 )
93
+ node.insert(5 )
94
+ node.insert(15 )
95
+ node.insert(0 )
96
+ node.insert(20 )
97
+ node.insert(21 )
98
+ node.right?.right?.left = Node (999 )
99
+
100
+ isValidSearchBinaryTree(node) shouldEqual false
101
+ }
53
102
}
54
103
55
104
private data class Node <E : Comparable <E >>(
You can’t perform that action at this time.
0 commit comments