Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing a Method and Test Program

Similar presentations


Presentation on theme: "Designing a Method and Test Program"— Presentation transcript:

1 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

2 Available Test Templates
Parameter Type(s) Return Type Sample Method integer iterative Fibonacci boolean prime checker integer, integer combinations C(n,r) integer array longest consecutive increasing streak Integer array more positives than negatives Integer, integer array Remove int value from int array string # of digit characters in string is string a palindrome remove all non-alphabetic characters character, string # of characters greater than the character parameter double array double variance double array, double array Pearson correlation coefficient Select your desired signature now for your microlab method.

3 Step One: Download and Unzip Files
The appropriate files can be downloaded from under workshop resources There are four Java files involved <<signature>>Test.java – this is heart of the test program; does not need modification ParamDataAndInvocations.java –This file will be modified as described in the steps outlined below CorrectMethod.java – this file contains a correct version of the method being implemented Student.java – another copy of the correct method; if not in the download then make it yourself

4 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

5 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

6 Step Four: Set Parameters & Invocations
Modify test data and method invocation public class ParamDataAndInvocations { int[] numData = {5, 3, 8, 1, 0}; public int invokeCorrectMethod(CorrectMethod myCorrectMethod,int n){ return myCorrectMethod.iterativeFibonacci(n); } public int invokeStudentMethod(Student student,int n){ return student.iterativeFibonacci(n); This example had a single integer parameter; your template may be different Put the name of the method in the CorrectMethod.java file here. Put the name of the method in the Student.java file here.

7 Step Five: Run Your Program
Make sure your method is compiled and runs correctly 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 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.


Download ppt "Designing a Method and Test Program"

Similar presentations


Ads by Google