Question

In: Computer Science

considering a binary class write five-unit test modules to test the class which must include 5...

considering a binary class write five-unit test modules to test the class which must include 5 different solutions

Solutions

Expert Solution

Here is the completed JUnit test code for this program. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// SearchTest.java

import static org.junit.Assert.*;

import org.junit.Before;

import org.junit.Test;

public class SearchTest {

      // Search class object

      private Search search;

      // this method gets called before executing each test module

      @Before

      public void setUp() {

            // initializing search object

            search = new Search();

      }

      // first test module to test if an element exists in array of positive

      // numbers, using an item that is present

      @Test

      public void testBinSearchUsingPositiveArray1() {

            int arr[] = { 1, 3, 5, 7, 8, 9, 10 };

            int item = 8;

            assertEquals(search.BinSearch(arr, item), 4);

      }

      // second test module to test if an element exists in array of positive

      // numbers, using an item that is NOT present

      @Test

      public void testBinSearchUsingPositiveArray2() {

            int arr[] = { 1, 3, 5, 7, 8, 9, 10 };

            int item = 15;

            assertEquals(search.BinSearch(arr, item), -1);

      }

      // third test module to test if an element exists in array of negative

      // numbers, using an item that is present

      @Test

      public void testBinSearchUsingNegativeArray1() {

            int arr[] = { -111, -33, -15, -7, -5, -2, -1 };

            int item = -1;

            assertEquals(search.BinSearch(arr, item), 6);

      }

      // fourth test module to test if an element exists in array of negative

      // numbers, using an item that is NOT present

      @Test

      public void testBinSearchUsingNegativeArray2() {

            int arr[] = { -111, -33, -15, -7, -5, -2, -1 };

            int item = -48;

            assertEquals(search.BinSearch(arr, item), -1);

      }

      // fifth test module to test if an element exists in array containing both

      // positive and negative values; using an item that is present and another

      // item that is not present

      @Test

      public void testBinSearchUsingNormalArray() {

            int arr[] = { -35, -1, -2, 1, 5, 6, 9, 24 };

            int item = -35;

            assertEquals(search.BinSearch(arr, item), 0);

            item = 119;

            assertEquals(search.BinSearch(arr, item), -1);

      }

}

OUTPUT:


Related Solutions

Write a Java class. The class name must be ShapeMetrics, which means the file name must...
Write a Java class. The class name must be ShapeMetrics, which means the file name must be ShapeMetrics.java. Provide the following functions: 1. getAreaOfRectangle(), with two float arguments, width and height, in that order, returning a float value which is the area of the rectangle with that width and height. 2. getSpaceDiagonalOfRectangularCuboid (), with three float arguments, width, height, and depth, in that order, returning a float value which is the length of the diagonal line which bisects the cuboid....
Write a program that will find the class average of fifteen (15) test scores for five...
Write a program that will find the class average of fifteen (15) test scores for five (5) different tests. The class average must be stored into an integer array. You are to have three separate arrays: Note: _jd represents the initials of the programmer. Your array and function names should be named by replace the initials jd with your first and last initials Arrays Student Names Scores Averages Name of array students_jd scores_jd averages_jd Size of array [15][10] [15][5] .[5]...
QUESTION 5     [10 A department has five employees and five jobs have been received which must...
QUESTION 5     [10 A department has five employees and five jobs have been received which must be assigned to the employees for completion. The time (in hours) each person will take to complete each job is given in the table below. Assign the jobs so as to minimize the total number of man-hours required to complete the jobs. Identify the optimal assignments and compute the total minimum time required to complete all jobs.                                                                                  ...
In C++: Write a binary search tree and include the functions to find the number of...
In C++: Write a binary search tree and include the functions to find the number of nodes and the height of the tree. Test your code in main. Print the post-order, in-order and pre-order traversal.
Write a binary search tree and include the functions to find the number of nodes and...
Write a binary search tree and include the functions to find the number of nodes and the height of the tree. Test your code in main. Print the post-order, in-order and pre-order traversal. in c++ please.
Lab 5: Binary Search Tree Implement operations for a Binary Search Tree class starting from the...
Lab 5: Binary Search Tree Implement operations for a Binary Search Tree class starting from the template provided under the PolyLearn assignment, using the class TreeNode that is also provided. You may (should) implement helper methods that make your code easier to write, read, and understand. You will also need to write test cases of your own as you develop the methods. You may use iterative and/or recursive functions in your implementation. The following starter files are available . •...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public TreeNode searchBST(TreeNode root, int val) {    }...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: TreeNode* sortedArrayToBST(vector<int>& nums) {    } }; Given an array where elements are sorted in...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: vector<int> inorderTraversal(TreeNode* root) {    } }; Given the root of a binary tree, return...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: vector<int> preorderTraversal(TreeNode* root) {    } }; Given the root of a binary tree, return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT