Question: Create a ClosedLab11 project folder. FOR ALL EXERCISES: Make sure you place a comment block at the top of the code with your name and

Create a ClosedLab11 project folder. FOR ALL EXERCISES: Make sure you place a comment block at the top of the code with your name and your partner's name. In your ClosedLab11 project folder, import the following file:

ClosedLab11.java

/** * ClosedLab11.java * * * @author Jeremy Morris * @version 20121028 * * A set of static methods used to explore the JUnit * testing framework. */ public class ClosedLab11 { /* * isPositive * * @param arr - array of integers * @returns true if all elements of arr are positive, false otherwise * should return false if the array contains no elements */ public static boolean isPositive(int [] arr) { return false; } /* * computeShipping * * @param amount - dollar amount to compute shipping for * @returns - the amount of shipping to be paid based on the following schedule: * * amount < $100 - shipping is 25% of order * $100 <= amount < $300 - shipping is 10% of order * $300 <= amount < $500 - shipping is 5% of order * $500 < amount - shipping is free * */ public static double computeShipping(double amount) { return 0; } /* * isReverse * * @param arr1 - array of characters * @param arr2 - array of characters * @returns true if arr1 is the reverse of arr2, false otherwise */ public static boolean isReverse(char [] arr1, char[] arr2) { return false; } /* * computeGraduatedTax * * @param amount - dollar amount to compute taxes on * @returns - the amount of tax to be paid based on the following * graduated scheudle: * * The first $8,000 of income - 10% tax * Income between $8,000 and $35,000 - 15% tax * Income between $35,000 and $85,000 - 25% tax * Income between $85,000 and $178,000 - 28% tax * Income between $178,000 and $388,000 - 33% tax * All income above $388,000 - 35% tax * * So someone making $50,000 a year would pay: * 0.1 * 8000 + 0.15 * 27000 + 0.25*15000 = 8600 in taxes * And someone making $500,000 a year would pay: * 0.1 * 8000 + 0.15 * 27000 + 0.25*50000 + 0.28*93000 + 0.33*210000 + 0.35*112000 = 151,890 in taxes * */ public static double computeGraduatedTax(double amount) { return 0; } }

There is no actual code in this file - only a set of stubs. For Exercise 1 you should just look at the isPositive method. In a separate text file named IsPositiveTests.txt, come up with a set of test cases for this method. Your test cases should test all possible cases for inputs to the isPositive method for arrays up to size 5. Make sure your test cases also indicate what the expected output should be for each test case. You will be turning in this text file as part of this lab, so take this part seriously even though there is no "coding" in this part. Once you feel that you have sufficient coverage of test cases (and you should have a good number of them - make sure you're testing arrays of all lengths up to 5 and all of the possible ways that each array could result in a true or false result), you should create a JUnit test class for the isPositive method. Highlight the ClosedLab11 class in your Package Explorer, right click and select New -> JUnit Test Case. Change the name of this Test Case to "IsPositiveTest" and click Next, then select just the isPositive method and click Finish. You should now have a JUnit class open in front of you. Fill in the JUnit class with the code for your first test case as described in class. Then run your JUnit test case. Does it pass? If it does, add your next test case to the mix and try again. Keep going until you find a test case that fails. Once you have a failed test case, look at the test case. Then open up the code for the isPositive method and make whatever changes you need to make to get that failed test case to work. Then go back and run your JUnit testing again - did it pass this time? If not, work out the bugs until you can get it to pass. If it did pass, are any of the previous test cases now broken? If so, go back and fix your isPositive method until all of the test cases you have so far work. Once you have all of your current test cases working, add another test case and repeat the cycle. Keep going until all of your test cases work in JUnit. Are you comfortable saying that your code works for all cases? If not, think about why you're not comfortable and think about some test cases you can add to either break your code or convince yourself that your fears are unfounded.

Exercise 2

Repeat the above process for the computeShipping method, including creating a text file containing your test cases and a separate JUnit method testing the computeShipping method (name this ComputeShippingTest).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!