Skip to content

Commit 327c0e4

Browse files
committed
Fix checkstyle violations in test package
1 parent 09020a2 commit 327c0e4

File tree

63 files changed

+2145
-2094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2145
-2094
lines changed

src/test/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
This folder contains the test code for the corresponding algorithms and data structures in **main/** folder.
44

5-
Note to contributors:
5+
Note to contributors:
6+
67
- Naming convention for test methods: featureUnderTest_testScenario_expectedBehaviour()
7-
The above is just a guide, slight deviation is fine as long as its clear. eg. no need to specifically mention "ordinary array" if testing some sorting algor.
8-
- camelCase
9-
- eg. sortList_emptyList_shouldReturnNoChange(), test_mergeSort_shouldReturnSortedArray, test{algor}_emptyList_shouldReturnEmptyResult
8+
The above is just a guide, slight deviation is fine as long as its clear. eg. no need to specifically mention "
9+
ordinary array" if testing some sorting algor.
10+
- camelCase
11+
- eg. sortList_emptyList_shouldReturnNoChange(), test_mergeSort_shouldReturnSortedArray, test{algor}_
12+
emptyList_shouldReturnEmptyResult

src/test/java/algorithms/binarySearch/BinarySearchTest.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@
88
* Test cases for {@link BinarySearch}.
99
*/
1010
public class BinarySearchTest {
11-
@Test
12-
public void test_binarySearch() {
13-
// Test 1: even number of elements
14-
int[] firstArray = {1, 5, 10, 12};
15-
int firstResult = BinarySearch.search(firstArray, 1);
16-
17-
// Test 2: odd number of elements
18-
int[] secondArray = {1, 5, 10, 11, 12};
19-
int secondResult = BinarySearch.search(secondArray, 11);
20-
21-
// Test 3: target not in array
22-
int[] thirdArray = {1, 5, 10, 11, 12};
23-
int thirdResult = BinarySearch.search(thirdArray, 3);
24-
25-
assertEquals(0, firstResult);
26-
assertEquals(3, secondResult);
27-
assertEquals(-1, thirdResult);
28-
}
29-
30-
@Test
31-
public void test_binarySearchTemplated() {
32-
// Test 1: even number of elements
33-
int[] firstArray = {1, 5, 10, 12};
34-
int firstResult = BinarySearchTemplated.search(firstArray, 1);
35-
36-
// Test 2: odd number of elements
37-
int[] secondArray = {1, 5, 10, 11, 12};
38-
int secondResult = BinarySearchTemplated.search(secondArray, 11);
39-
40-
// Test 3: target not in array
41-
int[] thirdArray = {1, 5, 10, 11, 12};
42-
int thirdResult = BinarySearchTemplated.search(thirdArray, 3);
43-
44-
assertEquals(0, firstResult);
45-
assertEquals(3, secondResult);
46-
assertEquals(-1, thirdResult);
47-
}
11+
@Test
12+
public void test_binarySearch() {
13+
// Test 1: even number of elements
14+
int[] firstArray = {1, 5, 10, 12};
15+
int firstResult = BinarySearch.search(firstArray, 1);
16+
17+
// Test 2: odd number of elements
18+
int[] secondArray = {1, 5, 10, 11, 12};
19+
int secondResult = BinarySearch.search(secondArray, 11);
20+
21+
// Test 3: target not in array
22+
int[] thirdArray = {1, 5, 10, 11, 12};
23+
int thirdResult = BinarySearch.search(thirdArray, 3);
24+
25+
assertEquals(0, firstResult);
26+
assertEquals(3, secondResult);
27+
assertEquals(-1, thirdResult);
28+
}
29+
30+
@Test
31+
public void test_binarySearchTemplated() {
32+
// Test 1: even number of elements
33+
int[] firstArray = {1, 5, 10, 12};
34+
int firstResult = BinarySearchTemplated.search(firstArray, 1);
35+
36+
// Test 2: odd number of elements
37+
int[] secondArray = {1, 5, 10, 11, 12};
38+
int secondResult = BinarySearchTemplated.search(secondArray, 11);
39+
40+
// Test 3: target not in array
41+
int[] thirdArray = {1, 5, 10, 11, 12};
42+
int thirdResult = BinarySearchTemplated.search(thirdArray, 3);
43+
44+
assertEquals(0, firstResult);
45+
assertEquals(3, secondResult);
46+
assertEquals(-1, thirdResult);
47+
}
4848
}

src/test/java/algorithms/graphs/breadthFirstSearchTest.java

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,77 @@
1414
*/
1515
public class BreadthFirstSearchTest {
1616

17-
@Test
18-
public void bfs_levelOrderTraversal_shouldReturnAccurate() {
19-
// empty tree
20-
List<Integer> firstList = new ArrayList<>();
21-
BinaryTreeNode root1 = null;
22-
List<Integer> firstResult = breadthFirstSearch.levelOrder(root1);
17+
@Test
18+
public void bfs_levelOrderTraversal_shouldReturnAccurate() {
19+
// empty tree
20+
List<Integer> firstList = new ArrayList<>();
21+
BinaryTreeNode root1 = null;
22+
List<Integer> firstResult = breadthFirstSearch.levelOrder(root1);
2323

24-
//standard tree
25-
// 1
26-
// / \
27-
// 2 3
28-
// / \
29-
// 4 5
30-
List<Integer> secondList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
31-
BinaryTreeNode rootRight2 = new BinaryTreeNode(3, new BinaryTreeNode(4), new BinaryTreeNode(5));
32-
BinaryTreeNode root2 = new BinaryTreeNode(1, new BinaryTreeNode(2), rootRight2);
33-
List<Integer> secondResult = breadthFirstSearch.levelOrder(root2);
24+
//standard tree
25+
// 1
26+
// / \
27+
// 2 3
28+
// / \
29+
// 4 5
30+
List<Integer> secondList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
31+
BinaryTreeNode rootRight2 = new BinaryTreeNode(3, new BinaryTreeNode(4), new BinaryTreeNode(5));
32+
BinaryTreeNode root2 = new BinaryTreeNode(1, new BinaryTreeNode(2), rootRight2);
33+
List<Integer> secondResult = breadthFirstSearch.levelOrder(root2);
3434

35-
//standard tree 2
36-
// 1
37-
// / \
38-
// 2 7
39-
// / \
40-
// 3 5
41-
// / /
42-
// 4 6
43-
List<Integer> thirdList = new ArrayList<>(Arrays.asList(1, 2, 7, 3, 5, 4, 6));
44-
BinaryTreeNode rootLeft3 =
45-
new BinaryTreeNode(2, new BinaryTreeNode(3, new BinaryTreeNode(4), null),
46-
new BinaryTreeNode(5, new BinaryTreeNode(6), null));
47-
BinaryTreeNode root3 = new BinaryTreeNode(1, rootLeft3, new BinaryTreeNode(7));
48-
List<Integer> thirdResult = breadthFirstSearch.levelOrder(root3);
35+
//standard tree 2
36+
// 1
37+
// / \
38+
// 2 7
39+
// / \
40+
// 3 5
41+
// / /
42+
// 4 6
43+
List<Integer> thirdList = new ArrayList<>(Arrays.asList(1, 2, 7, 3, 5, 4, 6));
44+
BinaryTreeNode rootLeft3 =
45+
new BinaryTreeNode(2, new BinaryTreeNode(3, new BinaryTreeNode(4), null),
46+
new BinaryTreeNode(5, new BinaryTreeNode(6), null)
47+
);
48+
BinaryTreeNode root3 = new BinaryTreeNode(1, rootLeft3, new BinaryTreeNode(7));
49+
List<Integer> thirdResult = breadthFirstSearch.levelOrder(root3);
4950

50-
assert firstResult.equals(firstList);
51-
assert secondResult.equals(secondList);
52-
assert thirdResult.equals(thirdList);
53-
}
51+
assert firstResult.equals(firstList);
52+
assert secondResult.equals(secondList);
53+
assert thirdResult.equals(thirdList);
54+
}
5455

55-
@Test
56-
public void bfs_friendHops_shouldReturnAccurate() {
56+
@Test
57+
public void bfs_friendHops_shouldReturnAccurate() {
5758

58-
// Tests based on the following friend graph:
59-
// Andre ------ Ben ------- Diana ------- Evelyn ------- Gerald
60-
// | | |
61-
// Cathy Felix--------------------------
62-
// |
63-
// Harold ------ Iris Anonymous
64-
GraphNode<String> andre = new GraphNode<>("andre");
65-
GraphNode<String> ben = new GraphNode<>("ben");
66-
GraphNode<String> cathy = new GraphNode<>("cathy");
67-
GraphNode<String> diana = new GraphNode<>("diana");
68-
GraphNode<String> evelyn = new GraphNode<>("evelyn");
69-
GraphNode<String> felix = new GraphNode<>("felix");
70-
GraphNode<String> gerald = new GraphNode<>("gerald");
71-
GraphNode<String> harold = new GraphNode<>("harold");
72-
GraphNode<String> iris = new GraphNode<>("iris");
73-
GraphNode<String> anonymous = new GraphNode<>("anonymous");
74-
GraphNode.connect(andre, ben);
75-
GraphNode.connect(andre, cathy);
76-
GraphNode.connect(cathy, harold);
77-
GraphNode.connect(harold, iris);
78-
GraphNode.connect(ben, felix);
79-
GraphNode.connect(ben, diana);
80-
GraphNode.connect(diana, evelyn);
81-
GraphNode.connect(evelyn, felix);
82-
GraphNode.connect(evelyn, gerald);
59+
// Tests based on the following friend graph:
60+
// Andre ------ Ben ------- Diana ------- Evelyn ------- Gerald
61+
// | | |
62+
// Cathy Felix--------------------------
63+
// |
64+
// Harold ------ Iris Anonymous
65+
GraphNode<String> andre = new GraphNode<>("andre");
66+
GraphNode<String> ben = new GraphNode<>("ben");
67+
GraphNode<String> cathy = new GraphNode<>("cathy");
68+
GraphNode<String> diana = new GraphNode<>("diana");
69+
GraphNode<String> evelyn = new GraphNode<>("evelyn");
70+
GraphNode<String> felix = new GraphNode<>("felix");
71+
GraphNode<String> gerald = new GraphNode<>("gerald");
72+
GraphNode<String> harold = new GraphNode<>("harold");
73+
GraphNode<String> iris = new GraphNode<>("iris");
74+
GraphNode<String> anonymous = new GraphNode<>("anonymous");
75+
GraphNode.connect(andre, ben);
76+
GraphNode.connect(andre, cathy);
77+
GraphNode.connect(cathy, harold);
78+
GraphNode.connect(harold, iris);
79+
GraphNode.connect(ben, felix);
80+
GraphNode.connect(ben, diana);
81+
GraphNode.connect(diana, evelyn);
82+
GraphNode.connect(evelyn, felix);
83+
GraphNode.connect(evelyn, gerald);
8384

84-
assert breadthFirstSearch.friendHops(anonymous, diana) == -1;
85-
assert breadthFirstSearch.friendHops(iris, gerald) == 7;
86-
assert breadthFirstSearch.friendHops(andre, gerald) == 4;
87-
assert breadthFirstSearch.friendHops(felix, harold) == 4;
88-
}
85+
assert breadthFirstSearch.friendHops(anonymous, diana) == -1;
86+
assert breadthFirstSearch.friendHops(iris, gerald) == 7;
87+
assert breadthFirstSearch.friendHops(andre, gerald) == 4;
88+
assert breadthFirstSearch.friendHops(felix, harold) == 4;
89+
}
8990
}

0 commit comments

Comments
 (0)