Code Magnet Method And Test Program

Designing a Method and Test Program
In this session you will:
• See how using testing templates can speed up
code magnet lab development
• Write the function you want students to
construct and adapt one of the provided
templates to suit your needs
• Implement and test your method outside of
WAGS
Available Test Templates
Parameter Type(s)
Return Type
Sample Method
integer
integer
iterative Fibonacci
integer
boolean
prime checker
integer, integer
integer
combinations C(n,r)
integer array
integer
longest consecutive increasing streak
Integer array
boolean
more positives than negatives
Integer, integer array
Integer array
Remove int value from int array
string
integer
# of digit characters in string
string
boolean
is string a palindrome
string
string
remove all non-alphabetic characters
character, string
integer
# of characters greater than the
character parameter
double array
double
variance
double array, double array
double
Pearson correlation coefficient
Select your desired signature now for your microlab method.
Step One: Download and Unzip Files
• The appropriate files can be downloaded from
http://cs.appstate.edu/microlabs/ under
workshop resources
• There are four Java files involved
1. <<signature>>Test.java – this is heart of the test
program; does not need modification
2. ParamDataAndInvocations.java –This file will be
modified as described in the steps outlined below
3. CorrectMethod.java – this file contains a correct
version of the method being implemented
4. Student.java – another copy of the correct method; if
not in the download then make it yourself
Step Two: Get Demo Program Working
•
•
•
•
Use your favorite IDE (Eclipse, NetBeans, etc.)
Create a Java Project
Do not use a package (use a default)
Load the files <<signature>>Test.java,
ParamDataAndInvocations.java,
CorrectMethod.java, and Student.java
• Compile and run the main program:
<<signature>>Test.java; NOTE: you will get an
error message about a missing argument
• Verify that everything worked as expected
Step Three: Implement Your Method
• Modify the sample method in
CorrectMethod.java to the method you want
students to implement
• Put a copy of this method in Student.java
Step Four: Set Parameters & Invocations
Modify test data and method invocation
public class ParamDataAndInvocations {
int[] numData = {5, 3, 8, 1, 0};
This example had a single integer
parameter; your template may
be different
public int invokeCorrectMethod(CorrectMethod myCorrectMethod,int n){
return myCorrectMethod.iterativeFibonacci(n);
}
Put the name of the method in the
CorrectMethod.java file here.
public int invokeStudentMethod(Student student,int n){
return student.iterativeFibonacci(n);
}
Put the name of the method in
}
the Student.java file here.
Step Five: Run Your Program
1. Make sure your method is compiled and runs correctly
2. Make sure your parameter data includes limiting cases
for the method you have designed, such as an empty
string if you had a string parameter
3. Modify the method in the Student class to create an
error; make sure you test cases detect the error
If you are done and the workshop hasn’t proceeded to the
next session; repeat the above process for a second method.