Lab 4 - Reverse Polish Notation
- Open your Homework 3 program in IntelliJ (or another IDE
where it can be modified).
- If the latest version of your work is not on Bitbucket (or
GitHub), create a commit called "Before lab" and push
it. Do this before starting the lab. If necessary, review the
materials from the first lab.
- The teacher will assign you a partner.
- In Moodle, open your last submission and show the submission
time and the teacher’s latest comment (it must contain "ok").
NB! All automated tests must pass and all sources must be
referenced.
- Explain the interpret method to your partner. Your
partner will do the same.
- Divide the roles: developer and tester. One
partner ("developer") is responsible for the file DoubleStack.java
and the other partner ("tester") is responsible for the file DoubleStackTest.java.
- Development: complete the interpret method so
that it accepts additional stack operations as input, which have
the following meanings (see
the Forth language manual). We assume that in the
following descriptions the top of the stack is the rightmost
element.
SWAP swaps the top two elements on the stack: a b -- b a
(check that at least two elements exist)
ROT rotates the top three elements, moving the third element
to the top: a b c -- b c a (check that at least three elements
exist)
DUP creates a copy of the top element: a -- a a (check that at
least one element exists)
DROP removes the top element: a -- (check that at least one
element exists)
Examples:
- "2 5 SWAP -" should result in 3.
- "2 5 9 ROT - +" should result in 12.
- "3 DUP *" should result in 9.
- "3 7 DROP" should result in 3.
- "9 11 17 ROT - SWAP -" should result in -3.
- "-3 -5 -7 ROT - SWAP DUP * +" should result in 21.
- "9 11 17 DUP ROT - SWAP DROP -" should result in 3.
Implement the changes to the interpret
method. Be sure to try all the previous examples and include
them in the tests.
- Testing: Write JUnit
4 tests for all examples in the previous section (complete
DoubleStackTest.java based on the examples above). Add
methods to check for stack underflow (DUP and DROP require one,
SWAP requires two, and ROT requires three elements). Write at
least five tests: one that includes all the previous examples
("positive test") and one for each operation to test the
underflow situation ("negative tests").
- Share your result with your partner and test the new solution
on both computers.
- Make a new commit called "Developer: name,
Tester: name" and upload it to
Bitbucket (or GitHub). Your partner will do the same with their
code.
- Show the commit, the tests, and working examples to
the teacher. You can also run tests from the command line if
there is a problem with the IDE.
- The teacher assigns the grade. Then complete the Homework 3
defense in Moodle.
Jaanus Pöial