From 4d9965cb945d59c5582e1f9cdfc7f59627638beb Mon Sep 17 00:00:00 2001 From: Abir Bhushan Date: Mon, 15 Apr 2019 11:38:59 +0100 Subject: [PATCH] Create DepthFirstSearchTest.java this test is created for the DepthFirstSearch.java file- that I added- containing the DepthFirstSearch algorithm --- .../java/com/search/DepthFirstSearchTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test/java/com/search/DepthFirstSearchTest.java diff --git a/src/test/java/com/search/DepthFirstSearchTest.java b/src/test/java/com/search/DepthFirstSearchTest.java new file mode 100644 index 00000000..859abfb1 --- /dev/null +++ b/src/test/java/com/search/DepthFirstSearchTest.java @@ -0,0 +1,36 @@ +package src.test.java.com.search; + +import org.junit.Assert; +import org.junit.Test; +import src.main.java.com.search.DepthFirstSearch; +import src.main.java.com.search.BinaryTree; + +public class DepthFirstSearchTest { + @Test + public void testDepthFirstSearch() { + + BinaryTree tree1 = new BinaryTree(); + tree1.add(1,1); + tree1.add(2,2); + tree1.add(3,3); + tree1.add(4,4); + Assert.assertEquals("Incorrect index", 3, DepthFirstSearch.find(3, tree1)); + Assert.assertEquals("Incorrect index", 1, DepthFirstSearch.find(1, tree1)); + Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(0, tree1)); + Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(8, tree1)); + Assert.assertEquals("Incorrect index", null, DepthFirstSearch.find(-2, tree1)); + + BinaryTree tree2 = new BinaryTree(); + tree2.add("1","A"); + tree2.add("2","B"); + tree2.add("3","C"); + tree2.add("4","D"); + + Assert.assertEquals("Incorrect index", "C", LinearSearch.findIndex(tree2,"3")); + Assert.assertEquals("Incorrect index", "B", LinearSearch.findIndex(tree2,"2")); + Assert.assertEquals("Incorrect index", null, LinearSearch.findIndex(tree2,"F")); + + BinaryTree tree3 = new BinaryTree(); + Assert.assertEquals("Incorrect index", null, LinearSearch.findIndex(tree3, "")); + } +}