6
6
import static org .junit .Assert .assertNotNull ;
7
7
import org .junit .Ignore ;
8
8
import org .junit .Test ;
9
+ import org .junit .Before ;
9
10
10
- public class BSTTest {
11
+ public class BinarySearchTreeTest {
12
+ BinarySearchTree <Integer > bst ;
13
+
14
+ @ Before
15
+ public void setUp () {
16
+ bst = new BinarySearchTree <>();
17
+ }
11
18
12
19
@ Test
13
20
public void dataIsRetained () {
14
- BST <Integer > bst = new BST <>();
15
21
final int actual = 4 ;
16
22
bst .insert (actual );
17
- final BST .Node <Integer > root = bst .getRoot ();
23
+ final BinarySearchTree .Node <Integer > root = bst .getRoot ();
18
24
assertNotNull (root );
19
25
final int expected = root .getData ();
20
26
assertEquals (expected , actual );
@@ -23,16 +29,15 @@ public void dataIsRetained() {
23
29
@ Ignore ("Remove to run test" )
24
30
@ Test
25
31
public void insertsLess () {
26
- BST <Integer > bst = new BST <>();
27
32
final int expectedRoot = 4 ;
28
33
final int expectedLeft = 2 ;
29
34
30
35
bst .insert (expectedRoot );
31
36
bst .insert (expectedLeft );
32
37
33
- final BST .Node <Integer > root = bst .getRoot ();
38
+ final BinarySearchTree .Node <Integer > root = bst .getRoot ();
34
39
assertNotNull (root );
35
- final BST .Node <Integer > left = root .getLeft ();
40
+ final BinarySearchTree .Node <Integer > left = root .getLeft ();
36
41
assertNotNull (left );
37
42
38
43
final int actualRoot = root .getData ();
@@ -44,16 +49,15 @@ public void insertsLess() {
44
49
@ Ignore ("Remove to run test" )
45
50
@ Test
46
51
public void insertsSame () {
47
- BST <Integer > bst = new BST <>();
48
52
final int expectedRoot = 4 ;
49
53
final int expectedLeft = 4 ;
50
54
51
55
bst .insert (expectedRoot );
52
56
bst .insert (expectedLeft );
53
57
54
- final BST .Node <Integer > root = bst .getRoot ();
58
+ final BinarySearchTree .Node <Integer > root = bst .getRoot ();
55
59
assertNotNull (root );
56
- final BST .Node <Integer > left = root .getLeft ();
60
+ final BinarySearchTree .Node <Integer > left = root .getLeft ();
57
61
assertNotNull (left );
58
62
59
63
final int actualRoot = root .getData ();
@@ -65,16 +69,15 @@ public void insertsSame() {
65
69
@ Ignore ("Remove to run test" )
66
70
@ Test
67
71
public void insertsRight () {
68
- BST <Integer > bst = new BST <>();
69
72
final int expectedRoot = 4 ;
70
73
final int expectedRight = 5 ;
71
74
72
75
bst .insert (expectedRoot );
73
76
bst .insert (expectedRight );
74
77
75
- final BST .Node <Integer > root = bst .getRoot ();
78
+ final BinarySearchTree .Node <Integer > root = bst .getRoot ();
76
79
assertNotNull (root );
77
- final BST .Node <Integer > right = root .getRight ();
80
+ final BinarySearchTree .Node <Integer > right = root .getRight ();
78
81
assertNotNull (right );
79
82
80
83
final int actualRoot = root .getData ();
@@ -86,7 +89,6 @@ public void insertsRight() {
86
89
@ Ignore ("Remove to run test" )
87
90
@ Test
88
91
public void createsComplexTree () {
89
- BST <Integer > bst = new BST <>();
90
92
List <Integer > expected = Collections .unmodifiableList (
91
93
Arrays .asList (4 , 2 , 6 , 1 , 3 , 5 , 7 )
92
94
);
@@ -103,7 +105,6 @@ public void createsComplexTree() {
103
105
@ Ignore ("Remove to run test" )
104
106
@ Test
105
107
public void sortsSingleElement () {
106
- BST <Integer > bst = new BST <>();
107
108
List <Integer > expected = Collections .unmodifiableList (
108
109
Collections .singletonList (4 )
109
110
);
@@ -117,7 +118,6 @@ public void sortsSingleElement() {
117
118
@ Ignore ("Remove to run test" )
118
119
@ Test
119
120
public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst () {
120
- BST <Integer > bst = new BST <>();
121
121
List <Integer > expected = Collections .unmodifiableList (
122
122
Arrays .asList (2 , 4 )
123
123
);
@@ -132,7 +132,6 @@ public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst() {
132
132
@ Ignore ("Remove to run test" )
133
133
@ Test
134
134
public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst () {
135
- BST <Integer > bst = new BST <>();
136
135
List <Integer > expected = Collections .unmodifiableList (
137
136
Arrays .asList (4 , 5 )
138
137
);
@@ -147,7 +146,6 @@ public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst() {
147
146
@ Ignore ("Remove to run test" )
148
147
@ Test
149
148
public void iteratesOverComplexTree () {
150
- BST <Integer > bst = new BST <>();
151
149
List <Integer > expected = Collections .unmodifiableList (
152
150
Arrays .asList (1 , 2 , 3 , 4 , 5 , 6 , 7 )
153
151
);
0 commit comments