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 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]...
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 . •...
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.                                                                                  ...
how to write a unit test for a write function in python? is there a better...
how to write a unit test for a write function in python? is there a better way than running main once and checking whether the new file path exists?
Part 1 – Create a Stock Class Write a class named Stock. Stock Class Specifications Include...
Part 1 – Create a Stock Class Write a class named Stock. Stock Class Specifications Include member variables for name (string), price (double), shares (double). Write a default constructor. Write a constructor that takes values for all member variables as parameters. Write a copy constructor. Implement Get/Set methods for all member variables. Implement the CalculateValue function. This function should multiply the prices by the shares and return that value. Use the following function header: double CalculateValue(). Add a member overload...
Given the main method of a driver class, write a Fraction class. Include the following instance...
Given the main method of a driver class, write a Fraction class. Include the following instance methods: add, multiply, print, printAsDouble, and a separate accessor method for each instance variable. Write a Fraction class that implements these methods: add ─ This method receives a Fraction parameter and adds the parameter fraction to the calling object fraction. multiply ─ This method receives a Fraction parameter and multiplies the parameter fraction by the calling object fraction. print ─ This method prints the...
Write an implementation of the set class, with associated iterators using a binary search tree. Add...
Write an implementation of the set class, with associated iterators using a binary search tree. Add to each node a link to the parent node. (C++)
Problem 4: Reading Binary You must write a program that willcontinuously prompt the user for...
Problem 4: Reading Binary You must write a program that will continuously prompt the user for a string representing a binary number. Then you should validate whether that string is valid binary number, and in case it is you must print the corresponding number in decimal base. Otherwise, you should state that the input string is not a valid binary number. Use the string “QUIT” to end the program. You should be aware that the input string may contain noise...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT