Full Course Title: Program Design and Development - Homework | C SC 227, Assignments of Computer Science

Material Type: Assignment; Class: Full Course Title: Program Design and Development; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-wg1
koofers-user-wg1 ๐Ÿ‡บ๐Ÿ‡ธ

5

(1)

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
For this homework, you are asked to
Implement one class with two unrelated methods and a unit test for those two methods
Set up Eclipse to submit your Eclipse Projects to WebCat.
Submit your Eclipse project to WebCat using the Submit option
o Note: Although the Submit option is available in our CS labs in GS, you will need to add a
plugin if using your home machine. Instructions are found though a link at the bottom
Implement a Unit test with two methods and a Unit test for both
This project asks you to solve two problems related to a primitive type and Strings. You are asked to write two
methods in class TwoMethods and a test method for each in class TwoMethodsTest. Develop (code and test)
one method at a time.
public String middleTwo(String arg)
Given a String argument, return a new String made from the middle two chars of that argument. For
example, with the argument "Computer" returns "pu". If the length is odd, favor the left. Assume all arguments
have a length >= 2. Our reference tests will not have any assertions for Strings with less than two characters.
middleTwo("abcd") โ†’ "bc"
middleTwo("abcde") โ†’ "bc"
Here are the beginnings of the two required classes.
// This class has tests for two methods to provide practice for testing
// methods that process Strings and some of the primitive types.
// Programmer: Rick Mercer
import static org.junit.Assert.*;
import org.junit.Test;
public class TwoMethodsTest {
@Test
public void testMiddleTwo() {
// Need a TwoMethods object to send messages to
TwoMethods myFuns = new TwoMethods();
// Four test cases to test the middleTwo method
assertEquals("bc", myFuns.middleTwo("abcd"));
assertEquals("bc", myFuns.middleTwo("abcde"));
assertEquals("23", myFuns.middleTwo("12345"));
assertEquals("pu", myFuns.middleTwo("Computers"));
assertEquals("to", myFuns.middleTwo("to"));
assertEquals("is", myFuns.middleTwo("antidisestablishmentarianism"));
// Our tests will not violate the precondition with cases like this
// that would throw an indexOutOfBoundsException
// assertEquals("to", myFuns.middleTwo("a"));
// assertEquals("to", myFuns.middleTwo(""));
}
// One more test method will be completed below
}
pf3
pf4
pf5

Partial preview of the text

Download Full Course Title: Program Design and Development - Homework | C SC 227 and more Assignments Computer Science in PDF only on Docsity!

For this homework, you are asked to

Implement one class with two unrelated methods and a unit test for those two methods

Set up Eclipse to submit your Eclipse Projects to WebCat.

Submit your Eclipse project to WebCat using the Submit option

o Note: Although the Submit option is available in our CS labs in GS, you will need to add a

plugin if using your home machine. Instructions are found though a link at the bottom

Implement a Unit test with two methods and a Unit test for both

This project asks you to solve two problems related to a primitive type and Strings. You are asked to write two

methods in class TwoMethods and a test method for each in class TwoMethodsTest. Develop (code and test)

one method at a time.

public String middleTwo(String arg)

Given a String argument, return a new String made from the middle two chars of that argument. For

example, with the argument "Computer" returns "pu". If the length is odd, favor the left. Assume all arguments

have a length >= 2. Our reference tests will not have any assertions for Strings with less than two characters.

middleTwo("abcd") โ†’ "bc" middleTwo("abcde") โ†’ "bc"

Here are the beginnings of the two required classes.

// This class has tests for two methods to provide practice for testing // methods that process Strings and some of the primitive types. // Programmer: Rick Mercer import static org.junit.Assert.*; import org.junit.Test;

public class TwoMethodsTest {

@Test public void testMiddleTwo() { // Need a TwoMethods object to send messages to TwoMethods myFuns = new TwoMethods();

// Four test cases to test the middleTwo method assertEquals ("bc", myFuns.middleTwo("abcd")); assertEquals ("bc", myFuns.middleTwo("abcde")); assertEquals ("23", myFuns.middleTwo("12345")); assertEquals ("pu", myFuns.middleTwo("Computers")); assertEquals ("to", myFuns.middleTwo("to")); assertEquals ("is", myFuns.middleTwo("antidisestablishmentarianism"));

// Our tests will not violate the precondition with cases like this // that would throw an indexOutOfBoundsException // assertEquals("to", myFuns.middleTwo("a")); // assertEquals("to", myFuns.middleTwo(""));

} // One more test method will be completed below }

And here is the beginning of the class containing the methods being tested.

  • This class has six unrelated methods to provide practice for implementing
  • methods that process Strings and some of the primitive types.
  • Programmer: Your Name */ public class TwoMethods {

// Determine and return the middle two chars of the String argument. public String middleTwo(String arg) { return "TBA"; // Change this method body }

// More methods to be completed below }

You are probably seeing errors because JUnit 4 is not in the build path

๏‚ง Click on a light bulb and choose 'Add JUnit 4 to the build path'

Run this as a JUnit test. The assertions should not pass (Red bar)

Fix TwoMethods.middleTwo(String) so all assertions pass.

public boolean isEven( int number)

Complete method isEven to return true if the argument is an even integer or false if it the argument is odd.

isEven (24) โ†’ true isEven (25) โ†’ false

The test method should go in TwoMethodsTest.java and the isEven method should go TwoMethods.java.

Remember you need a new TwoMethods object in your test method.

@Test public void testIsEven() { TwoMethods myFuns = new TwoMethods(); assertTrue (myFuns.isEven(24)); // ... add other assertions to fully test isEven }

After you have completely tested both methods, submit to the automated testing tool known as WebCat

Submit your project to WebCat

You will be graded on a scale of 0.0 through 10.0 automatically by WebCat. Here are the instructions

fot getting the Submit plugin for Eclipse and Submitting your first Webcat project.

Read your email to get for your Web-Cat account ID (almost always what comes before

@email.arizona.edu) and the randomly generated password

Login to WebCat at this url: https://web-cat.cs.vt.edu/Web-CAT/WebObjects/Web-CAT.woa

Change your password to a good password no one else can guess.

If you haven't already, download WebCat's submit plugin to make it easy to submit projects:

webcat-eclipse-submitter-1.2.1.zip

Unzip this archive file.

Copy three highlighted folders (beginning with net.sf.webcat) into the Eclipse plugin. For

Window, the Eclipse plugin folder should be C:\Program Files\eclipse\ or c:\Program

Files\eclipse-SDK-3.4-win32\eclipse.

Click OK

Right click on your project name

Select the Submit button (near the bottom of the list of options). WebCat will return the list of

published projects under C Sc 227

Click on TwoMethodsTest

Make sure UserName has you WebCat user name (not your CS login name)

Enter your WebCat password

Click Next and Finish

Click view your graded results and wait until the report is posted back to you

Wait until WebCat posts results back to the Eclipse browser--could take 15-45 seconds

If you get 100%, Congratulations! But please read the next page anyway -- almost done ๏Š

Interpreting Results

Problem Coverage (50%)

Even though the student's unit test passed all of its tests, this project has 4 occurrences of

assertions failing middleTwo when run against Rick's reference tests. The hints say the test

that failed, but not why. You also see that there was a String index out of bounds exception

that should give the clue that the method is trying to return the substring that may be off by

one index. This student should fix the code and resubmit.

But if you have 100% and see 10.0 points, you are done.