Recitation R12
- Testing
Summer 2016
CS160: Foundations in Programming
The purpose of this lab is to:
- Call methods from another class by instantiating an object.
- To increase your understanding of method testing.
Part One
Write a test program to test all of the methods in a class.
- Create a new project in Eclipse called R12.
- Download the Java archive TestClass.jar.
- Import the TestClass.jar file using Build Path->Add External Archive
- Copy the interface file TestInterface.java to the R12/src directory.
- Create a new class called R12 with a main method.
- Instantiate TestClass in the main method using the TestInterface, as follows:
// Instantiate test class
TestInterface inter = new TestClass();
- Write code to test each of the six methods in the TestClass.
- Each method in TestClass has two distinct defects, so find them!
- To find the defects, you have to call each method with input that you've created and print the result. If the result doesn't do what the descriptions specifies, then you've found the defect! Leave the defect in your main method and the testing program will pick it up!
Interface
The following is the interface that you are testing. Pay careful attention to
parameters and return values, and the description of the functionality. The
testing program will ignore all of your output from System.out, so you can
print whatever you would like.
// R12 Interface File
// Author: Chris Wilcox
// Date: 07/26/2016
// Class: CS160
// Email: wilcox@cs.colostate.edu
public interface TestInterface {
// Returns a reversed version of the specified string,
// which can contain any ASCII character.
// For example, returns "edcba" for "abcde"
public String reverseString(String s);
// Returns the specified string duplicated.
// For example, returns "Hello There!Hello There!" for "Hello There!"
public String duplicateString(String s);
// Creates an array of strings with
// [0] = original, [1] = toUppercase(), [2] = toLowercase().
// For example, returns {"Whatever", "WHATEVER", "whatever"} for "Whatever"
public String[] createStrings(String s);
// Cubes all elements in array of doubles.
// For example, changes {2.0, 3.0, 4.0} to {8.0, 27.0, 64.0}
public void cubeArray(double[] array);
// Adds the elements in array of integers,
// returning the sum as an integer.
// For example, returns 21 for {1, 2, 3, 4, 5, 6}
public int sumArray(int[] array);
// Sorts an array of integers from low to high.
// For example, changes {2, 6, 4, 9, 1} to {1, 2, 4, 6, 9}
public void sortArray(int[] array);
}
Testing
Just a few tips on testing methods:
- Test with different sizes of strings and arrays.
- Test with different contents, for example a variety of characters in strings.
- Always test negative and positive and zero numerical values.
- Test with different array orderings.
- Don't be afraid of writing a loop to repeat the tests with many different values.
- Look for anomalies, i.e. incorrect results from each method that represent a defect.
- Overall you just want to adopt the mentality of trying to break things!
Please follow the usual rules for submitting Java programs.
- Work on your own.
- The name of the source code file must be exactly R12.java
- Comments at the top with your name, e-Name, date and course.
- We expect programming assignments to be implemented in Eclipse
using Java 1.5 or 1.6 or 1.7 or 1.8.
- We will be testing the code on the machines in the CS computer lab,
so make sure your code runs on those machines.
- We will be checking programs for plagiarism, so please don't copy
from anyone else.
Grading Criteria
- 100 points for perfect submission.
- 0 points for no submission, will not compile, submitted class file, etc.
- Testing
- defect1: verifies that you have found the defect number 1. (8 points)
- defect2: verifies that you have found the defect number 2. (8 points)
- defect3: verifies that you have found the defect number 3. (8 points)
- defect4: verifies that you have found the defect number 4. (8 points)
- defect5: verifies that you have found the defect number 5. (8 points)
- defect6: verifies that you have found the defect number 6. (8 points)
- defect7: verifies that you have found the defect number 7. (8 points)
- defect8: verifies that you have found the defect number 8. (8 points)
- defect9: verifies that you have found the defect number 9. (8 points)
- defect10: verifies that you have found the defect number 10. (8 points)
- defect11: verifies that you have found the defect number 11. (10 points)
- defect12: verifies that you have found the defect number 12. (10 points)
Submission
Submit your source file named R12.java to the the Checkin tab on the course web site.
© 2016 CS160 Colorado State University. All Rights Reserved.