Docsity

CSC 227 Project 3: Unit Testing Two Array Methods, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
C Sc 227 Project 3, Spring 06: Two Array Problems
Due Date: Tuesday, 31-Jan, 2006 @ 9:00 pm via web based turnin
This project must be turned in using our web based turnin facility. This means you can
turn in your project from any computer that has an Internet connection. I recommend that
you use our lab when section leaders are there to help, especially for the first few. This
schedule has the lab hours
http://www.cs.arizona.edu/classes/cs391/spring06/gs_228_hours.htm
For both problems you are asked to:
1. Create a test class that extends junit.framework.TestCase
2. Write a test method with enough assertions to test the method. The heading must
begin as public void testX() where X is the name of the method you are testing
3. Write a public method in the same class as the test method.
Note: Since unit tests do not have a main method, run them in Eclipse as JUnit Tests:
Run > Run As > JUnit Test
1. Evens Left
Write a unit test named EvensLeftTest that has a test method testEvensLeft to test a
method named evensLeft that rearranges any array of ints such that all the even
integers are in the lower portion of the array. For example, if the int array stores the
following sequence of integers when the method is called:
{ 1 3 2 9 6 7 12 4 28 17 }
the array should be rearranged to this when the method is done executing:
{ 2 6 12 4 28 7 1 9 3 17 }
Your array may look different as long as all the even integers are on the left and all the
odd integers are on the right. Here are some other examples:
{ 1 } { 1 } // no change
{ 2 } { 2 } // no change
{ 1 2 } { 2 1 }
{ 1 3 } { 1 3 } // no change
{ 1 3 5 } { 1 3 5 } // no change
{ 3 5 2 } { 2 5 3 }
{ 1 2 3 4 5 6 7 8 } { 2 4 6 8 5 3 7 1 }
{ 1 3 5 7 4 6 8 10 } { 4 6 8 10 1 3 5 7 }
{ 2 4 6 8 10 } { 2 4 6 8 10 }
{ 1 3 5 7 } { 1 3 5 7 }
pf2

Partial preview of the text

Download CSC 227 Project 3: Unit Testing Two Array Methods and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

C Sc 227 Project 3, Spring 06: Two Array Problems

Due Date: Tuesday, 31-Jan, 2006 @ 9:00 pm via web based turnin

This project must be turned in using our web based turnin facility. This means you can turn in your project from any computer that has an Internet connection. I recommend that you use our lab when section leaders are there to help, especially for the first few. This schedule has the lab hours http://www.cs.arizona.edu/classes/cs391/spring06/gs_228_hours.htm For both problems you are asked to:

  1. Create a test class that extends junit.framework.TestCase
  2. Write a test method with enough assertions to test the method. The heading must begin as public void testX() where X is the name of the method you are testing
  3. Write a public method in the same class as the test method. Note: Since unit tests do not have a main method, run them in Eclipse as JUnit Tests: Run > Run As > JUnit Test

1. Evens Left

Write a unit test named EvensLeftTest that has a test method testEvensLeft to test a method named evensLeft that rearranges any array of ints such that all the even integers are in the lower portion of the array. For example, if the int array stores the following sequence of integers when the method is called: { 1 3 2 9 6 7 12 4 28 17 } the array should be rearranged to this when the method is done executing: { 2 6 12 4 28 7 1 9 3 17 } Your array may look different as long as all the even integers are on the left and all the odd integers are on the right. Here are some other examples: { 1 } { 1 } // no change { 2 } { 2 } // no change { 1 2 } { 2 1 } { 1 3 } { 1 3 } // no change { 1 3 5 } { 1 3 5 } // no change { 3 5 2 } { 2 5 3 } { 1 2 3 4 5 6 7 8 } { 2 4 6 8 5 3 7 1 } { 1 3 5 7 4 6 8 10 } { 4 6 8 10 1 3 5 7 } { 2 4 6 8 10 } { 2 4 6 8 10 } { 1 3 5 7 } { 1 3 5 7 }

2. Frequency

Write a unit test named FrequencyTest that has a test method testFrequency to test a method named frequency that returns an array that stores the frequency of each integer in the Scanner argument. For example, if the Scanner object contains the numbers shown next, your method must return an array of ints where the value at index 100 represents the number of 100's, the value stored at index 99 represents the number of 99s found in the input stream. String numbers = "75 85 90 100 60 90 100 85 75 35 60 90 100"; numbers += " 90 90 90 60 50 70 85 75 90 90 70"; Scanner inputStream = new Scanner(numbers); Your frequency method may assume that the Scanner argument will contain any integers in the range of 0 through 100 inclusive. One assertion could look like this. int[] tests = new int[100]; tests = frequency(inputStream); assertEquals(3, tests[100]);

Grading Criteria (Subject to change)

___/ 16 You turned in an Eclipse Project as an archive file (zipped) that is properly named and it has the following class and method name and they compile.

  • The EvensLeftTest class with the evensLeft method
  • The FrequencyTest class with the frequency method ___/ 16 You have a test method for evensLeft that has enough assertions to convince us the test works. Hint: Consider the 10 examples shown in the specification. ___/ 16 You have a test method for frequency that has enough assertions to convince us the test works. Hint: Consider a Scanner with no numbers, another with many numbers where each non-zero is asserted and several 0s, one where every possible test score is checked, … ___/ 32 All of our assertions pass. We will add our own unit test and make sure our assertions pass. -2 for any assertion that fails. ___/ 20 You followed these style and design guidelines:
  • Used intention-revealing names (meaningful identifiers)
  • Used public for all method and classes
  • Used consistent spacing/indentation (in Eclipse, use Source > Format ).
  • Have one blank line between methods
  • Each class has your name and a description of the class at the top of the file

Turn in your project through Web-Based Turnin

Go to the turnin page for instructions