Lab: Sequence Smooth
Objective
In this lab you will practice writing the smooth static method for
Sequence<Integer> in a couple different ways and testing your
implementations with your JUnit test fixture.
Setup
Follow these steps to set up a project for this lab.
- Create a new Eclipse project by copying
ProjectTemplate. Name the new projectSequenceSmooth. - Open the
srcfolder of this project and then open(default package). As a starting point you can use any of the Java files. Rename itSequenceSmoothand delete the other files from the project. - Follow the link to
SequenceSmooth.java, select all the code on that page (click and hold the left mouse button at the start of the program and drag the mouse to the end of the program) and copy it to the clipboard (right-click the mouse on the selection and choose Copy from the contextual pop-up menu), then come back to this page and continue with these instructions. - In Eclipse, open the
SequenceSmooth.javafile; select all the code in the editor, right-click on it and select Paste from the contextual pop-up menu to replace the existing code with the code you copied in the previous step. Save your file. - Finally, create a new JUnit test fixture by following these steps:
- Right-click on the
testfolder in your project and select New > Class; name the classSequenceSmoothTestand click Finish. - Open the
SequenceSmoothTest.javafile and paste in it the JUnit test fixture you created for the homework due today. If you do not have a complete test fixture, you can start by copying and pasting the code from the homework'sSequenceSmoothTest.java
- Right-click on the
Method
-
Take a look at the provided code skeleton and make sure you understand it.
-
Complete the body of the
smoothstatic method. While you may use methodentry, do not use any other method that is introduced in the enhanced interfaceSequence. Among the methods still permitted for your use are all those inherited by or introduced inSequenceKernel, includingadd,remove, andlength. -
Run your JUnit test fixture and test your implementation of
smooth. This is also a test of your test fixture itself, and you may have to fix some test cases or add new ones you had not considered before. -
Provide an alternative implementation that is recursive if your first implementation was not recursive, or make your second implementation not recursive if the first one was recursive. You can just comment out the code of your first implementation (select the code to comment out and press CTRL-/, i.e., the Control key and the '/' key at the same time).
-
Run the JUnit test fixture and test your second implementation of
smooth. -
Once you are convinced that both your implementations work and you are satisfied with your test fixture, proceed with these steps:
-
What is the value of the expression
-5 / 2? If your test fixture does not include test cases involving negative numbers (both in the arguments and in the expected values), add appropriate test cases to deal with them. Run the new test fixture and fix any issues. -
Add the following test case to your test fixture:
Argument values:
s1 = < 1073741825, 1073741825 >,s2 = < >Expected values:
s1 = < 1073741825, 1073741825 >,s2 = < 1073741825 >Run the JUnit test fixture and fix any new problem this test case exposes.
-
Next add the following test case:
Argument values:
s1 = < 1073741825, -1073741825 >,s2 = < >Expected values:
s1 = < 1073741825, -1073741825 >,s2 = < 0 >Run the JUnit test fixture and fix any new problem this test case exposes.
-
Next add the following test case:
Argument values:
s1 = < -1073741823, 1073741824 >,s2 = < >Expected values:
s1 = < -1073741823, 1073741824 >,s2 = < 0 >Run the JUnit test fixture and fix any new problem this test case exposes.
-