• No results found

Instructions for Int Int Return Int Testing Template

N/A
N/A
Protected

Academic year: 2022

Share "Instructions for Int Int Return Int Testing Template"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

Instructions for Int Int Return Int Testing Template

Overview

These instructions will help you implement a code magnet microlab where the method is passed two integer parameters and returns an integer value. There are two steps in this process:

1. Implement the desired method and testing program outside of WAGS (Web Automated Grading System) and

2. Implement the code magnet lab in WAGS.

This is illustrated with the nCr method that returns the number of ways r items can be selected from n objects (i.e., combinations). You will change the nCr method to a method of your choice that has the same footprint:

input two integer parameters and returns an integer value.

The zip file IntIntReturnInt.zip contains four Java files:

1. IntIntReturnIntTest.java – this is heart of the test program and should not require any modification by the developer (or in this case the workshop participant). This will be uploaded as the test file when using the magnet creation page in WAGS.

2. ParamDataAndInvocations.java – the parameter values are

specified as two integer arrays in this file. Two methods are used to invoke a correct version of the method and the student version of the method. This file will be modified as described in the steps outlined below and uploaded as a helper file when using the magnet creation page in WAGS.

3. CorrectMethod.java – this file contains a correct version of the method being implemented as a code magnet method; it will be used to generate a correct return value for comparison with the method created in the code magnet lab by the student. This file will be modified as described in the steps outlined below and uploaded as a helper file when using the

magnet creation page in WAGS.

4. Student.java – this file contains the method to be developed as a code magnet microlab; it is only used to test the testing environment

independently of the WAGS system. DO NOT upload this file when you are using code magnet creation in WAGS.

(2)

Step 1

To complete step one you need to do the following:

 Design your java method that has two integer parameters and returns an integer; put a copy inside of CorrectMethod.java and Student.java

 Change the integer parameter values in

ParamDataAndInvocations.java to match the desired test values for your method. You can include as many values as you wish; be sure to include limiting cases for the method you are developing. For example in the choose method, there could be selecting zero items from a set of size zero.

 Change invokeCorrectMethod and invokeStudentMethod to call the appropriate method in the CorrectMethod and Student classes, respectively.

 Use your favorite IDE to test this testing framework.

 Upload the four files (IntIntReturnIntTest.java,

ParamDataAndInvocations.java, CorrectMethod.java, Student.java) into the IDE

 Set the first main method parameter value to any integer value of your choice; this is a nonce value that will be printed after testing is completed

 Run the test program IntIntReturnIntTest.java and insure you get the expected results

(3)

Step 2

To create a code magnet lab you need to put the desired method the students will construct into “standard form” and then add alternative

(4)

magnets as appropriate. This is illustrated using the nCr method included in the download files.

“Standard form” means changing the desired method in the following ways:

 All control statements, such as if, else, while, for are required to have a body enclosed in braces, even if the body is a single statement.

 Put every declaration/initialization/statement on a separate line.

Incorrect Correct

if (n > 0) n--; if (n > 0){

n--;

}

a = 1; b = 2; a = 1;

b = 2;

 Put the header of every control statement on a separate line ending in an opening brace; put every statement in the body on a separate line; put the closing brace on a separate line. NOTE: our parser does not currently handle switch statements, so please use if statements.

 Most of these are the standard for Eclipse auto-formatting

NOT in standard form CORRECT standard form

int nCr(int n, int r) { if(n < r) return -1;

if (r == 0 || r == n) return 1;

return nCr(n-1, r-1) + nCr(n-1, r);

}

int nCr(int n, int r) { if(n < r) {

return -1;

}

if (r == 0 || r == n) { return 1;

}

return nCr(n-1, r-1) + nCr(n-1, r);

Then add a heading block that contains the title of the lab and a description for students who will use the lab. The format of this block is:

 The first line in the file opening starting a comment line with /*

 The title of the lab on a new line; this must be unique from other labs

(5)

 A blank line

 A description for students who will be using the lab to help their understand of the goal to be completed; this is usually multiple lines

 A closing comment line ending with */

Comment block in processString.txt

/***********************************

Count Digit Characters

Return the number of digit characters, '0' through '9', in the given string parameter.

***********************************/

STEP 2A

Create a code magnet lab where all magnets are used to construct a correct solution.

 Put the desired method into standard form, including the header block, do not put inside an enclosing class; name the file appropriately; we used nCr.java for the example provided.

 Log onto the WAGS system using your account; in the top toolbar select Magnet Creation from the Admin pull down menu.

 Go to the bottom right side of the screen and select Choose File under the

parse file option; navigate to the java file in standard form and select it.

 Press the parse button once the file is selected; the text boxes on the right side of the screen should be filled in.

 Go to choose file for the Testing class and upload the file IntIntReturnIntTest.java

 Go to choose file for the Helper class and upload the file CorrectMethod.java

Add another helper class and upload ParamDataAndInvocations.java

 Press create and test your code magnet lab to ensure it works correctly.

(6)

STEP 2B

It is often desirable to add alternative magnets so that students must choose between two similar magnets, such as one containing a >

comparison and the other containing a >= comparison. The file with the magnet lab in standard form can be modified inthe following way: duplicate the line that will become the alternative magnet then modify one of the two lines with the desired change. Here is the iterative nCr method where the alternative magnets are shown in red.

int nCr(int n, int r) { if(n < r) {

return 1;

return -1;

}

if (r = 0 || r = n) { if (r == 0 || r == n) { return 1;

}

return nCr(n, r-1) + nCr(n, r+1);

return nCr(n-1, r-1) + nCr(n-1, r);

return nCr(n-1, r) + nCr(n-1, r+1);

}

Add some alternative magnets to your method in standard form and then parse the new file in the magnet creation page. You should not need to change the test program or the helper files. Test your new lab and make changes as appropriate.

References

Related documents

Our data suggest that ICT1 is a versatile ribosome rescue factor, which is also involved in the translation termination at non- standard stop codons AGG and AGA in mammalian

[r]

vANdAL ReSISTANT PUSH PLATeS Narrow PN1 PN2 PN5 Tee-Style PT1 PT2 PT5 Single Gang PS1 PS2 PS5 Switch description SPDT momentary DPDT momentary Pneumatic time delay. 2-60 seconds

Methods Mice with dextran sulfate sodium (DSS)- induced acute and chronic colitis were treated with indirubin in their diet.. Clinical and histologic changes

attracted the minds of many devotee poets and scholars of Hindu, Buddhist, Jaina and various other religious sects* Within a few centuries a large number of

Click the [Offline] button to open up a form to let you select the type of the Tixi Alarm Modem, in case the Tixi Alarm Modem Editor is not connected to the device

The proposed Intrusion Detection System (IDS) provides a network administrator with a comprehensive visualization of the network traffic.. Thus, the network manager can supervise

During the management of the Covid-19 in Turkey, officials of the Ministry of Health, members of the Covid-19 scientific board (summoned from the leading physicians) and