Lab 12: This is Just a Test

Due by midnight tonight

The goal of this lab is to get experience with making tests for the JUnit 5 unit-testing framework.

Specification

Create a project called Lab12. Download the following two files and add them to the project.

Bad methods

The BadMethods class contains three methods: round(), isPalindrome(), and largest(). These methods are all bad in that they don't do quite what they're supposed to.

The round() method is supposed to take a double value and return the nearest int value. However, this method only works for some values and not others.

Assumptions: If the input double has too large of a magnitude to be represented as an int, the required behavior is undefined. You should not test for this case.

The isPalindrome() method is supposed to tell if an input String is a palindrome, that is, a String whose characters are the same forwards and backwards. For the purpose of this lab, the characters in a palindrome must match exactly forwards and backwards, including case and punctuation. Thus, "tacocat" will be defined as a palindrome, but "Taco cat" will not. As with the previous method, this method sometimes works correctly: There are some String values that it will correctly identify as palindromes, but this method is also susceptible to some false positives, String values that are not palindromes but will be reported as if they are.

Assumptions: If the input String is null, this method will crash. You should not test for this case.

Finally, the largest() method finds the largest int value in an array. As with the other two methods, it often works, but there are cases where it will not correctly return the largest value in the array.

Assumptions: If the input array is null, this method will crash. If the input array has length 0, the required behavior of this method is undefined. You should not test for these cases.

Tests

Complete the six tests in BadMethodTests. For each method, you must write a test that calls the method and gets a correct result. These tests should be easy to write, since the methods return correct answers for many expected cases. For each method, you must also write a test that calls the method and gets the wrong result. These tests will take more thought since you will probably need to understand what's wrong with each method in order to design a test that reveals its flaws.

You should use appropriate assertions for each method, asserting the correct return values. Thus, three of your tests should pass, and three of them should fail. These tests should be short, requiring only a line or two of Java to call the method and check the result.

That's all there is to this lab. Don't fix BadMethods so that the methods are fully correct. However, you might want to check with me to make sure that your tests make sense.

Turn In

Turn in your code by uploading BadMethodTests.java from the Lab12\src folder inside your workspace folder to Blackboard. Do not upload the entire project. The BadMethods.java file is unnecessary. I only want the BadMethodTests.java file.

All work must be done individually. Never look at someone else's code. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.