Lab 5 - Quaternions
- Open your homework 4 in IntelliJ (or other IDE, so that it can
be changed), be sure that unit testing works.
- If you do not have the latest version of your work on
bitbucket (or github), create a commit and push it. If
necessary, refer to the materials of the first lab. The test
file QuaternionTest.java must also be included in the
version control.
- The teacher will assign you a partner for this lab.
- Show that all the tests pass on your computer (if necessary,
check the materials of the first lab), that the work has been
submitted by the deadline and the teachers comments (must
contain "ok"). The partner does the same
- Divide the roles: developer and tester. One partner
("developer") is responsible for the file Quaternion.java,
the other partner ("tester") is responsible for the file QuaternionTest.java.
- Development: Add a new method pow for raising
a quaternion to a given integer power (by multiplication):
q.pow(0) is 1: new
Quaternion(1, 0, 0, 0)
q.pow(1) is equal
to (but not identical to) q
q.pow(-1) is
q.inverse()
q.pow(n) is
defined for n > 1 by the rule: q.times(q.pow(n-1))
q.pow(-n) is q.pow(n).inverse()
- Testing: Write about 5-7 test cases for pow
that cover all the rules in the previous item and add them to
existing tests (use the junit4
framework, see the test file QuaternionTest.java for
an example). Zero quaternion on negative power must raise an
exception, zero on power zero is 1. Check that pow(1) creates a
new quaternion.
- Share your result with the partner and test the new solution
in both computers.
- Make a new commit "Developer: name,
Tester: name" and upload it to
bitbucket (or github), the partner will do the same with their
code. Do this 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.
- Challenge: Extend the valueOf method so that it accepts
input with minus signs and abbreviated strings of the form:
"-1-2i-3j-4k" (does not include plus signs for negative
components)
"-1-2i" means -1-2i+0j+0k (missing some part means that the
corresponding component is 0), for example: "-1-2i-3j" means
-1-2i-3j+0k and "-1" means -1+0i+0j+0k
"i" means 0+1i+0j+0k (missing the imaginary part coeficient
means that this coeficient is 1), for example "i-j-k" means
0+1i-1j-1k
- The teacher will discuss, ask questions and grade your work.
Jaanus Pöial