Skip to content

Commit 27a6d7f

Browse files
committed
Fix checkstyle violations in tests directory
- This should resolve checkstyle violations of all test files. Running './gradlew clean checkstyleTest' should show 0 violations.
1 parent df509d5 commit 27a6d7f

File tree

49 files changed

+1830
-1636
lines changed

Some content is hidden

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

49 files changed

+1830
-1636
lines changed

scripts/scripts.iml

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/dataStructures/queue/Deque/Deque.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dataStructures.queue;
1+
package dataStructures.queue.Deque;
22

33
/**
44
* This class implements a doubly-ended queue, known as a deque.
Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
package algorithms.binarySearch;
22

3-
import org.junit.Test;
4-
5-
import java.util.Arrays;
6-
73
import static org.junit.Assert.assertEquals;
84

5+
import org.junit.Test;
6+
7+
/**
8+
* Test cases for {@link BinarySearch}.
9+
*/
910
public class BinarySearchTest {
10-
@Test
11-
public void test_binarySearch() {
12-
// Test 1: even number of elements
13-
int[] firstArray = {1, 5, 10, 12};
14-
int firstResult = BinarySearch.search(firstArray, 1);
15-
16-
// Test 2: odd number of elements
17-
int[] secondArray = {1, 5, 10, 11, 12};
18-
int secondResult = BinarySearch.search(secondArray, 11);
19-
20-
// Test 3: target not in array
21-
int[] thirdArray = {1, 5, 10, 11, 12};
22-
int thirdResult = BinarySearch.search(thirdArray, 3);
23-
24-
assertEquals(0, firstResult);
25-
assertEquals(3, secondResult);
26-
assertEquals(-1, thirdResult);
27-
}
28-
29-
@Test
30-
public void test_binarySearchTemplated() {
31-
// Test 1: even number of elements
32-
int[] firstArray = {1, 5, 10, 12};
33-
int firstResult = BinarySearchTemplated.search(firstArray, 1);
34-
35-
// Test 2: odd number of elements
36-
int[] secondArray = {1, 5, 10, 11, 12};
37-
int secondResult = BinarySearchTemplated.search(secondArray, 11);
38-
39-
// Test 3: target not in array
40-
int[] thirdArray = {1, 5, 10, 11, 12};
41-
int thirdResult = BinarySearchTemplated.search(thirdArray, 3);
42-
43-
assertEquals(0, firstResult);
44-
assertEquals(3, secondResult);
45-
assertEquals(-1, thirdResult);
46-
}
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+
}
4748
}
Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,89 @@
11
package algorithms.graphs;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
37
import org.junit.Test;
48

59
import algorithms.graphs.util.BinaryTreeNode;
610
import algorithms.graphs.util.GraphNode;
711

8-
import java.util.ArrayList;
9-
import java.util.Arrays;
10-
import java.util.List;
11-
12-
public class breadthFirstSearchTest {
12+
/**
13+
* Test cases for {@link breadthFirstSearch}.
14+
*/
15+
public class BreadthFirstSearchTest {
1316

14-
@Test
15-
public void bfs_levelOrderTraversal_shouldReturnAccurate() {
16-
// empty tree
17-
List<Integer> firstList = new ArrayList<>();
18-
BinaryTreeNode root1 = null;
19-
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);
2023

21-
//standard tree
22-
// 1
23-
// / \
24-
// 2 3
25-
// / \
26-
// 4 5
27-
List<Integer> secondList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
28-
BinaryTreeNode rootRight2 = new BinaryTreeNode(3, new BinaryTreeNode(4), new BinaryTreeNode(5));
29-
BinaryTreeNode root2 = new BinaryTreeNode(1, new BinaryTreeNode(2), rootRight2);
30-
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);
3134

32-
//standard tree 2
33-
// 1
34-
// / \
35-
// 2 7
36-
// / \
37-
// 3 5
38-
// / /
39-
// 4 6
40-
List<Integer> thirdList = new ArrayList<>(Arrays.asList(1, 2, 7, 3, 5, 4, 6));
41-
BinaryTreeNode rootLeft3 = new BinaryTreeNode(2, new BinaryTreeNode(3, new BinaryTreeNode(4), null), new BinaryTreeNode(5, new BinaryTreeNode(6), null));
42-
BinaryTreeNode root3 = new BinaryTreeNode(1, rootLeft3, new BinaryTreeNode(7));
43-
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+
BinaryTreeNode root3 = new BinaryTreeNode(1, rootLeft3, new BinaryTreeNode(7));
48+
List<Integer> thirdResult = breadthFirstSearch.levelOrder(root3);
4449

45-
assert firstResult.equals(firstList);
46-
// System.out.println(secondResult.toString());
47-
assert secondResult.equals(secondList);
48-
// System.out.println(thirdResult.toString());
49-
assert thirdResult.equals(thirdList);
50-
}
50+
assert firstResult.equals(firstList);
51+
assert secondResult.equals(secondList);
52+
assert thirdResult.equals(thirdList);
53+
}
5154

52-
@Test
53-
public void bfs_friendHops_shouldReturnAccurate() {
55+
@Test
56+
public void bfs_friendHops_shouldReturnAccurate() {
5457

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

81-
assert breadthFirstSearch.friendHops(anonymous, diana) == -1;
82-
assert breadthFirstSearch.friendHops(iris, gerald) == 7;
83-
assert breadthFirstSearch.friendHops(andre, gerald) == 4;
84-
assert breadthFirstSearch.friendHops(felix, harold) == 4;
85-
}
86-
}
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+
}
89+
}

0 commit comments

Comments
 (0)