Consider the PasswordTester program. This program asks a user to enter an employee ID and a password and then asks to have the password entered again. It then checks the ID and password for validity. An ID is valid if it is a 7 digit number (and the first digit can't be 0). A password is valid if it meats the following two criteria:
Without looking at the code, decide what inputs should be used to adequately test this method. Make sure you come up with positive (valid) test cases, boundary test cases, and negative (invalid) test cases.
The code above does not quite work correctly. When it is run using an ID of 1234567 and a password of UW-Madison, it produces the output below. To discover why, we need to look at the code for the PasswordTester.
Enter your employee ID#: 1234567 Enter your password: Enter your password again: UW-Madison You did not enter the same password twice
Dog agility is a sport in which dogs traverse a set course containing obstacles such as jumps, tunnels, teeter-totters, and weave poles. The height of the jumps is determined by the height of the dog (at the withers): smaller dogs jump smaller heights, larger dogs jump larger heights. Another factor which determines the jump height for a dog is the age of the dog: older dogs jump smaller heights, younger dogs jump larger heights. Below is a table indicating the jump height for dogs based on the age and height of the dog (at the withers):
11" & under | 14" & under | 18" & under | 20" & under | more than 20" | |
---|---|---|---|---|---|
Standard division | 8" | 12" | 16" | 20" | 24" |
Senior division (7 years & up) |
4" | 8" | 12" | 16" |
Here is a Java method that determines a dog's jump height based on the dog's height and age:
public static int jumpHeight(int height, int age) { int jump; if (height <= 11) jump = 8; else if (height <= 14) jump = 12; else if (height <= 18) jump = 16; else if (height <= 20) jump = 20; else jump = 24; if (age >= 7) if (height <= 18) jump -= 4; else jump = 16; return jump; }
Test coverage refers to how much of a program has been tested. Give a set of inputs to this method that gives complete test coverage, that is, will result in every line in the method being executed at least once.