Skip to content

Commit 4d9965c

Browse files
authored
Create DepthFirstSearchTest.java
this test is created for the DepthFirstSearch.java file- that I added- containing the DepthFirstSearch algorithm
1 parent 6938c40 commit 4d9965c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package src.test.java.com.search;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import src.main.java.com.search.DepthFirstSearch;
6+
import src.main.java.com.search.BinaryTree;
7+
8+
public class DepthFirstSearchTest {
9+
@Test
10+
public void testDepthFirstSearch() {
11+
12+
BinaryTree<Integer> tree1 = new BinaryTree<Integer>();
13+
tree1.add(1,1);
14+
tree1.add(2,2);
15+
tree1.add(3,3);
16+
tree1.add(4,4);
17+
Assert.assertEquals("Incorrect index", 3, DepthFirstSearch.find(3, tree1));
18+
Assert.assertEquals("Incorrect index", 1, DepthFirstSearch.find(1, tree1));
19+
Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(0, tree1));
20+
Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(8, tree1));
21+
Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(-2, tree1));
22+
23+
BinaryTree<String> tree2 = new BinaryTree<String>();
24+
tree2.add("1","A");
25+
tree2.add("2","B");
26+
tree2.add("3","C");
27+
tree2.add("4","D");
28+
29+
Assert.assertEquals("Incorrect index", "C", LinearSearch.findIndex(tree2,"3"));
30+
Assert.assertEquals("Incorrect index", "B", LinearSearch.findIndex(tree2,"2"));
31+
Assert.assertEquals("Incorrect index", null, LinearSearch.findIndex(tree2,"F"));
32+
33+
BinaryTree<String> tree3 = new BinaryTree<String>();
34+
Assert.assertEquals("Incorrect index", null, LinearSearch.findIndex(tree3, ""));
35+
}
36+
}

0 commit comments

Comments
 (0)