A common exercise in acceptance test driven development is write acceptance for the problem of scoring a bowling game. You may have seen other examples of acceptance tests. Here’s a different version based on some of the guidelines listed in my book. These examples are shown as Word-style tables. They can be converted into tables compatible with the syntax of your acceptance test framework.
Before coming up with acceptance tests, its usually a good idea to understand the terms in the problem domain. One key term is the name associated with the number of pins that are knocked down when a participant throws the ball down the lane. In common terms, this is called a roll. The rules of scoring refer to it as a delivery. The customer’s terms are the ones that should be used in acceptance tests. Our customer says delivery, so we show the valid values for this term as:
|0||Yes||Minimum is 0|
|10||Yes||Maximum is 10|
There can be one or two Deliveries in a Frame. If the first Delivery makes all the pins fall, then there is no second Delivery. There is a Mark for each Frame that depends on the number of Deliveries and the total pins. We can show this as:
|Delivery One||Delivery Two||Valid?||Mark||Notes|
|0||10||Yes||Spare||Maximum is 10 for a frame|
|5||4||Yes||Open||Open mark if less than 10|
|10||Yes||Strike||Only one Delivery if first Delivery is strike|
|0||0||Yes||Open||Minimum is 0 ((two gutter balls)|
Now each Frame has a score. The score is dependent upon the Mark in that Frame. Here’s the business rule for a Frame score:
|Mark||Base score||Additional score|
|Open||Two deliveries in frame|
|Mark||Two deliveries in frame||Next delivery|
|Strike||Two deliveries in frame||Next two deliveries|
Now we can create examples of how the scores are computed for a Frame:
|Delivery One||Next Delivery||Delivery After That||Score?||Notes|
|1||9||10||20||Spare + Strike|
|9||1||0||10||Spare + Gutter|
|10||10||10||30||Three strikes (turkey)|
|10||0||0||10||Strike + two gutter|
|10||1||9||20||Strike + spare|
|10||9||1||20||Strike + spare|
|10||10||1||21||Two strikes (double)|
DNC stands for Do Not Care
A Game consists of ten Frames. Each Frame has one or two Deliveries, except for the tenth frame. It has either two or three deliveries, depending on the Mark. Here are scores for each Frame within a Game. The customer came up with these variations.
|Deliveries||Frame Scores (for frame)?||Notes|
|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0||0,0,0,0,0,0,0,0,0,0,||All Gutter balls|
Depending on your point of view, not all of the variations may be needed. One could come up with fewer Games that incorporated the variations, such as:
|Deliveries||Frame Scores (for frame)?|
The score that is shown for each Frame is the cumulative score for that Frame and all the previous Frames. Since this is just a summing, then not all the variations shown in this table are needed. It follows the customer supplied examples.
|Cumulative Frame Scores for Game|
|Frame Scores (for frame)||Cumulative Frame Score?||Game Score?||Notes|
|0,0,0,0,0,0,0,0,0,0,||0,0,0,0,0,0,0,0,0,0,||0||All Gutter balls|
One could just show the summations for a single game, e.g.
|Frame Scores (for frame)?||Cumulative Frame Score?||Game Score?|
Now if you are creating glue code to connect these tests to the production code, you will need only five different pieces of glue.