Week 5

Back to the Bank

The greeting program, split so a function returns the amount.

You type

You write the tests. The function takes a greeting.

The tool
Each kind of greeting needs a test A greeting in An amount out A test for each kind
What comes out

Tests for each kind of greeting.

The question, more slowly

The question is: the greeting fee becomes a function that returns the amount, and you write tests for each kind of greeting. Returning 0, the middle amount, or the large amount is what the test sees. Printing is not enough.

You want at least one greeting that starts with hello, one that starts with h but is not hello, and one that starts with something else. Case and surrounding words belong in the tests if the original problem cared about them.

People write three tests that all start with hello. Those pass together and miss the bug. One test per branch.

Before you code

List the kinds of greeting before you write tests. One test per kind is the shape.