Lab 6 - Trees
- Open your
homework in IntelliJ (or other IDE, so you can edit and
test it). The tests must be functional also.
- If you do
not have the latest state of your work in bitbucket (or
github), create a "Before Lab" commit at the beginning of
the lab and upload it. If necessary, see the materials of
the first lab.
- The teacher
will assign you a partner for this lab.
- Explain to your
partner how your program works. Show that all the tests
pass your computer (if necessary, check the materials of
the first lab), that the work has been submitted by the
deadline and that all the items in the "checklist" have
been met. The partner does the same and then compare the
solutions to decide which solution to use as the basis for
the extra work.
- Divide the roles:
developer and tester. One partner (the "developer") is
responsible for the Tnode.java file, the other
partner (the "tester") for the TnodeTest.java
file.
- Development:
Update the buildFromRPN method to accept DUP,
SWAP, and ROT operations in input with the following
meanings:
- DUP creates a
copy of the last subtree (check that the tree exists)
- SWAP swaps the
last two subtrees (check that two subtrees exist)
- ROT rotates the
last three subtrees, raising the third to become the
first (check that three subtrees exist)
See the Lab 4 for
the meaning of these operations - when calculating a tree,
the result must be the same as from the interpret
method for the same input.
Examples:
- "2 5 SWAP -"
must swap subtrees 2 and 5 and give a tree -(5, 2)
- "3 DUP *"
must copy tree 3 and give a tree *(3, 3)
- "2 5 9
ROT - +" must raise tree 2 to be the first and give a
tree +(5, -(9, 2))
- "2 5 9 ROT +
SWAP -" must give a tree -(+(9, 2), 5)
- "2 5 DUP ROT -
+ DUP *" must give a tree *(+(5, -(5, 2)), +(5, -(5,
2)))
- "-3 -5 -7 ROT -
SWAP DUP * +" must return a tree +(-(-7, -3), *(- 5,
-5))
Make changes to the
buildFromRPN method. Be sure to try the previous
examples.
- Testing:
Write junit4
tests for the examples in the previous section (complete
the TnodeTest.java file based on the examples
there). Also include tests to verify underflow situations
(DUP requires one, SWAP requires two, and ROT requires
three subtrees).
- Make a new
commit "Develper: name,
Tester: name" and upload it to
bitbucket (or github), the partner will do the same with
her code. Do this only AFTER THE TESTING PART IS FINISHED.
- Show the commit,
the tests and running examples to the teacher. You can
also run tests from the command line if there is a problem
with the IDE.
- The teacher
asks questions and inputs grades to SIS.
Jaanus
Pöial