1. Study materials

And, Oh, before we forget: Polymorphism, Interfaces, Comparator and friends, That Too (rehearsal from PRC1).

Week 1 rehearses some topics from PRC1 and introduces (unit) testing, the Java collection framework, and the Comparator as a way to make the collection very flexible.

Throughout the exercises of PRC1, your have become acquainted with the value of tests: You have a way of checking if your code is any good without having to test each and every part manually. You clicked on the nice TMC button in NetBeans and then you could see which parts of your code worked, and which didn’t. There is a catch, though: Out there in the real world, there won’t be any NetBeans button doing that magic for you, nor will a teacher of school provide the tests for you, so you are on your own. But fret not! Writing tests is typically much simpler than writing the actual code. At least, it is when you follow a basic set of steps:

  1. Prepare: set up the thing you want to test (as in, set up the experiment)

  2. Interact: execute the experiment

  3. Verify: Assert or ensure that the observable result(s) is/are as expected

On the theory of inheritance and interfaces

1.1. Tutorials

Oracle tutorial on Interfaces and Inheritance and Collections.

Study tutorials before you come to class or the practical session.

1.3. Additional pointers

Start reading the fine manual (RTFM), in this case the api doc:

1.4. Demos

Lecture demo PRC2 about comparable will be in the lessondemo part of the repository.

1.5. YouTube Lesson 1

These are the recordings of the PRC2 lesson on 2019-02-07.

Starting Test Driven Part 1
Starting Test Driven Part 2

Part 2 ends abruptly because of end of lesson time. The code is incomplete, but of the kind we often see while correcting exams. If I see such code, I comment it in the correction with useless invocation. Can you notice the problem? Hint: the test will always be green in this state, where it should be red, assuming the earlier assertNotNull(…​) still passes. Why is the question. Answer next week.

2. Exercises week 1.

2.1. Polymorphism

Assume the following class Hierarchy:

class extending and implementing.
class B extends A implements I,J {

After the statement B b = new B();, will the expression b instanceof J yield true?

For the tasks below, the project will be injected into your repo.

2.2. Two Stacks

The task will show that even tests can be reused, by applying inheritance and interfaces. The specification of the stack is given through its interface, which can be implemented in multiple ways, of which you will tests and implement two.

Task link: Two Stacks.

Netbeans starter project will be inserted into your repository.

2.3. Fraction TDD

Test driven development of a fraction class.

The task has been a Java1 (the precursor of PRC1) exam task.

There is a task description and a rather empty NetBeans project with one working test and a broken Fraction.java file. This is your starting point.

NetBeans starter project will be in your respository.

3. Test Results

Note that the test results are currently produced by running your own tests on your own code, which is the normal developer way. Later we might run your tests on our know to be broken code AND run our test on your (hopefully) passing implementations.