Skip to content

Commit 7136df5

Browse files
committed
Renamed classes and added @before method to test class
1 parent ba09409 commit 7136df5

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

exercises/binary-search-tree/.meta/src/reference/java/BST.java renamed to exercises/binary-search-tree/.meta/src/reference/java/BinarySearchTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.List;
66
import java.util.Queue;
77

8-
public class BST<T extends Comparable<T>> {
8+
public class BinarySearchTree<T extends Comparable<T>> {
99

1010
public static class Node<T> {
1111

exercises/binary-search-tree/src/test/java/BSTTest.java renamed to exercises/binary-search-tree/src/test/java/BinarySearchTreeTest.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
import static org.junit.Assert.assertNotNull;
77
import org.junit.Ignore;
88
import org.junit.Test;
9+
import org.junit.Before;
910

10-
public class BSTTest {
11+
public class BinarySearchTreeTest {
12+
BinarySearchTree<Integer> bst;
13+
14+
@Before
15+
public void setUp() {
16+
bst = new BinarySearchTree<>();
17+
}
1118

1219
@Test
1320
public void dataIsRetained() {
14-
BST<Integer> bst = new BST<>();
1521
final int actual = 4;
1622
bst.insert(actual);
17-
final BST.Node<Integer> root = bst.getRoot();
23+
final BinarySearchTree.Node<Integer> root = bst.getRoot();
1824
assertNotNull(root);
1925
final int expected = root.getData();
2026
assertEquals(expected, actual);
@@ -23,16 +29,15 @@ public void dataIsRetained() {
2329
@Ignore("Remove to run test")
2430
@Test
2531
public void insertsLess() {
26-
BST<Integer> bst = new BST<>();
2732
final int expectedRoot = 4;
2833
final int expectedLeft = 2;
2934

3035
bst.insert(expectedRoot);
3136
bst.insert(expectedLeft);
3237

33-
final BST.Node<Integer> root = bst.getRoot();
38+
final BinarySearchTree.Node<Integer> root = bst.getRoot();
3439
assertNotNull(root);
35-
final BST.Node<Integer> left = root.getLeft();
40+
final BinarySearchTree.Node<Integer> left = root.getLeft();
3641
assertNotNull(left);
3742

3843
final int actualRoot = root.getData();
@@ -44,16 +49,15 @@ public void insertsLess() {
4449
@Ignore("Remove to run test")
4550
@Test
4651
public void insertsSame() {
47-
BST<Integer> bst = new BST<>();
4852
final int expectedRoot = 4;
4953
final int expectedLeft = 4;
5054

5155
bst.insert(expectedRoot);
5256
bst.insert(expectedLeft);
5357

54-
final BST.Node<Integer> root = bst.getRoot();
58+
final BinarySearchTree.Node<Integer> root = bst.getRoot();
5559
assertNotNull(root);
56-
final BST.Node<Integer> left = root.getLeft();
60+
final BinarySearchTree.Node<Integer> left = root.getLeft();
5761
assertNotNull(left);
5862

5963
final int actualRoot = root.getData();
@@ -65,16 +69,15 @@ public void insertsSame() {
6569
@Ignore("Remove to run test")
6670
@Test
6771
public void insertsRight() {
68-
BST<Integer> bst = new BST<>();
6972
final int expectedRoot = 4;
7073
final int expectedRight = 5;
7174

7275
bst.insert(expectedRoot);
7376
bst.insert(expectedRight);
7477

75-
final BST.Node<Integer> root = bst.getRoot();
78+
final BinarySearchTree.Node<Integer> root = bst.getRoot();
7679
assertNotNull(root);
77-
final BST.Node<Integer> right = root.getRight();
80+
final BinarySearchTree.Node<Integer> right = root.getRight();
7881
assertNotNull(right);
7982

8083
final int actualRoot = root.getData();
@@ -86,7 +89,6 @@ public void insertsRight() {
8689
@Ignore("Remove to run test")
8790
@Test
8891
public void createsComplexTree() {
89-
BST<Integer> bst = new BST<>();
9092
List<Integer> expected = Collections.unmodifiableList(
9193
Arrays.asList(4, 2, 6, 1, 3, 5, 7)
9294
);
@@ -103,7 +105,6 @@ public void createsComplexTree() {
103105
@Ignore("Remove to run test")
104106
@Test
105107
public void sortsSingleElement() {
106-
BST<Integer> bst = new BST<>();
107108
List<Integer> expected = Collections.unmodifiableList(
108109
Collections.singletonList(4)
109110
);
@@ -117,7 +118,6 @@ public void sortsSingleElement() {
117118
@Ignore("Remove to run test")
118119
@Test
119120
public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst() {
120-
BST<Integer> bst = new BST<>();
121121
List<Integer> expected = Collections.unmodifiableList(
122122
Arrays.asList(2, 4)
123123
);
@@ -132,7 +132,6 @@ public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst() {
132132
@Ignore("Remove to run test")
133133
@Test
134134
public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst() {
135-
BST<Integer> bst = new BST<>();
136135
List<Integer> expected = Collections.unmodifiableList(
137136
Arrays.asList(4, 5)
138137
);
@@ -147,7 +146,6 @@ public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst() {
147146
@Ignore("Remove to run test")
148147
@Test
149148
public void iteratesOverComplexTree() {
150-
BST<Integer> bst = new BST<>();
151149
List<Integer> expected = Collections.unmodifiableList(
152150
Arrays.asList(1, 2, 3, 4, 5, 6, 7)
153151
);

0 commit comments

Comments
 (0)