Question: Open class Search.java in the package ceLinearBinary. It includes the method linear. Add a new JUnit test class called SearchTest. It should be in a
- Open class Search.java in the package ceLinearBinary. It includes the method linear.
- Add a new JUnit test class called SearchTest. It should be in a separate source folder called tests
- Include 6 JUnit tests that test the method linear(int[] numbers, int key) Use the following int array for the tests: [60, 10, 12, 5, 12, 17, 29, 13, 40] Include JUnit tests that test the first element, last element, a duplicate element, a missing element, an empty array, and a null array Important: Use descriptive JUnit test method names of the form {methodName}_{description} E.g., linear_missingElement()
- In class Search, Overload the method linear with a generic method of the same name that can accept any array of reference types.
- Include 6 more JUnit tests that test the generic method linear(T[] array, int key) Again, include JUnit tests that test the first element, last element, a duplicate element, a missing element, an empty array, and a null array. However, this time use two arrays for your tests:
- Use an array that includes elements of type Double [ 60.5, 10.5, 12.5, 5.5, 12.5, 17.5, 29.5, 13.5, 40.5 ] to test the last element and duplicate elements
- Use an array that includes strings ["cat", "dog", "ant", "bat"] Important: to test the first element and a missing element
- Descriptive names: Since we overloaded the method, the form {methodName}_{description} no longer allows us to distinguish between the original method linear and the overloaded version. In this case, add a T at the end of the method name to indicate that we test the generic version E.g., linearT_missingElemen
- Do we need to test an empty array and null again for the generic version? The only change in the JUnit test method would be the name. This indicates, that it is not necessary. However, it can be helpful anyhow. If you decide at a later point that the original version is no longer needed and the tests starting with linear_ ... are deleted, the two tests would be lost. Including them for both linear_... and linearT_... would avoid that issue.
- Inside 2420_CLASS_EXERCISES add a new package called comparable.
- Add a class called Rectangle
- It has two private fields height and width of type double
- It has a parameterized constructor that initializes the fields
- It has getters but no setters
- It has a toString method that represents a rectangle in the following form: [{height}, {width}] Where {height} and {width} are replaced with the corresponding field values
- Implement the interface Comparable
This rectangle is considered smaller than another rectangle if the height is smaller. - Add a class called RectangleApp. It is a test client for class Rectangle and includes a main method with test code to demonstrate the working functionality of class Rectangle.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
