Important: Remember that you are now required to work on the lab with your partner. Although you and your partner can choose to both follow the Setup instructions below, the recommended way to work on the lab is for one student to download and set up the lab's Eclipse project and then share it with the partner through the team's Subversion repository (the way you learned in the previous lab). This way you can work on the lab together on one computer and then share the resulting work through the repository.
Objective
In this lab you will practice implementing and testing a kernel component, Sequence3 implemented on Stack .
Setup
Follow these steps to set up a project for this lab. For this lab, instead of creating a new project, you will import a project already set-up for this lab. First you need to download the project, SequenceOnStack.zip, to your computer. Click on this download link and save the file somewhere on your hard drive where you can easily find it. Make sure that you do not expand this archive. If your browser automatically expands downloaded zip archives, that's OK too. Just pay attention to the special instructions in the following few steps. You may want to make a note of where you saved it.
Import your new project by following these steps:
- From the File menu select Import....
- In the new window, expand General and select Existing Projects into Workspace. Click Next.
- Click on the radio button next to Select archive file and then click the Browse... button. (If the archive was expanded when you downloaded the file to your own computer, click on Select root directory... instead.)
- In the file selection window, find the SequenceOnStack.zip file and select it. (If your browser expanded the archive, find the SequenceOnStack directory instead.) Click OK.
- Click Finish.
Method
- Take a look at the src and test folders
in your new project. Open the Sequence3.java file in the
src folder and explore it. In particular, take a look at
the private members (the representation) at the top of the
class and the correspondence in the Javadoc comment for the
class. The correspondence clause is a mathematical statement that
describes how a client should interpret the variables in the data
representation (denoted by
$this
followed by a dot and the name of the instance variable) as an abstract value of aSequence
variable (writtenthis
). (Note that the notation$this
never appears in Java code, but only in Javadoc comments like this that describe aspects of the data representation!) - Paste the code you wrote for the homework into the body of the private method setLengthOfLeftStack, and complete the body of the kernel methods (add, remove, and length) in Sequence3 in the src folder.
- Paste the test cases you designed for the homework at the end of the SequenceTest class in the test folder.
- Run Sequence3Test in the test folder to test your implementation of Sequence3. Fix any bugs that you discover and/or add extra test cases, if you realize that you are missing some important cases.
Additional Activities
- Copy and paste the following piece of code at the end of Sequence3
(after the iterator method and before the class closing
'}').
/* * Other methods (overridden for performance reasons) --------------------- */ @Override public final void flip() { // TODO - fill in body }
Provide a non-layered implementation of the secondary method flip defined in Sequence. Note that there is a simple, clever solution to this that does not involve iteration or recursion.
- Add appropriate test cases for the flip method to SequenceTest and test your implementation.
- Copy and paste the following piece of code at the end of Sequence3
(after the iterator method and before the class closing
'}').
/* * Other methods (overridden for performance reasons) --------------------- */ @Override public final T entry(int pos) { assert 0 <= pos : "Violation of: 0 <= pos"; assert pos < this.length() : "Violation of: pos < |this|"; // TODO - fill in body }
Provide a non-layered implementation of the secondary method entry defined in Sequence.
- Add appropriate test cases for the entry method to SequenceTest and test your implementation.
- Take a look at the Standard methods (newInstance, clear, and transferFrom) in Sequence3. We will discuss the details of these implementations later in the semester, but for now, design test cases to test these methods and add the test cases to your test fixture, SequenceTest.