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:
Delivery | ||
Value | Valid? | Notes |
0 | Yes | Minimum is 0 |
-1 | No | |
10 | Yes | Maximum is 10 |
11 | No |
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:
Frame | ||||
Delivery One | Delivery Two | Valid? | Mark | Notes |
0 | 10 | Yes | Spare | Maximum is 10 for a frame |
1 | 10 | No | Above maximum | |
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:
Frame Scoring | ||
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:
Frame Scores | ||||
Delivery One | Next Delivery | Delivery After That | Score? | Notes |
0 | 0 | 0 | 0 | Gutter balls |
0 | 9 | DNC | 9 | Open |
0 | 10 | 1 | 11 | Spare |
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.
Game Score | ||
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 |
9,0,9,0,9,0,9,0,9,0,9,0,9,0,9,0,9,0,9,0 | 9,9,9,9,9,9,9,9,9,9, | Nothing special |
9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9 | 19,19,19,19,19,19,19,19,19,19 | All Spares |
10,10,10,10,10,10,10,10,10,10,10,10 | 30,30,30,30,30,30,30,30,30,30 | Perfect Game |
10,10,10,10,10,10,10,10,10,10,9,1 | 30,30,30,30,30,30,30,30,29,20 | Almost Perfect |
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:
Game Score | |
Deliveries | Frame Scores (for frame)? |
0,0,0,0,9,0,9,0,9,1,9,1,10,10,10,10,9,1 | 0,0,9,9,19,20,30,30,29,20 |
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 |
9,9,9,9,9,9,9,9,9,9, | 9,18,27,36,45,54,63,72,81,90 | 90 | Nothing special |
19,19,19,19,19,19,19,19,19,19 | 19,38,57,76,95,114,133,152,171,190 | 190 | All Spares |
30,30,30,30,30,30,30,30,30,30 | 30,60,90,120,150,180,210,240,270,300 | 300 | Perfect Game |
30,30,30,30,30,30,30,30,30,20v | 30,60,90,120,150,180,210,240,269,289 | 289 | Almost Perfect |
One could just show the summations for a single game, e.g.
Game Score | ||
Frame Scores (for frame)? | Cumulative Frame Score? | Game Score? |
0,0,9,9,19,20,30,30,29,20 | 0,0,9,18,37,57,87,117,146,186 | 186 |
Now if you are creating glue code to connect these tests to the production code, you will need only five different pieces of glue.