Instructions: Work with your neighbors in groups.
Let's consider the venerable Triangle
program.
(This problem has been used as a "interview quiz" many times.)
/**
* @param s1, s2, s3: sides of a putative triangle
* decide what type of triangle, if any
*/
Try Koskela's TDD approach
by applying the same methods as he demonstrated in Chapter 2.
Preliminaries:
-
Why is the problem "hard" enough for an interview question?
-
What should the API look like?
Design a happy-path test.
-
What are the options for signaling an invalid triangle?
-
What kind of tests are better? Basic JUnit or data-driven?
Now, let's turn to adding functionality with TDD.
-
Write a test for the
triangle
method.
-
Implement enough code to make the test pass.
-
Refactor as needed.
-
Lather. Rinse. Repeat.