|
| 1 | +{ |
| 2 | + "#": [ |
| 3 | + "Bowling is game where players roll a heavy ball to knock down pins", |
| 4 | + "arranged in a triangle. Write code to keep track of the score of a", |
| 5 | + "game of bowling." |
| 6 | + ], |
| 7 | + "methods": { |
| 8 | + "description": [ |
| 9 | + "Check the public API is correct." |
| 10 | + ], |
| 11 | + "cases": [{ |
| 12 | + "description": "must be able to roll with a number of pins", |
| 13 | + "method": "roll", |
| 14 | + "arity": 1 |
| 15 | + }, { |
| 16 | + "description": "must have a score", |
| 17 | + "method": "score", |
| 18 | + "arity": 0 |
| 19 | + }] |
| 20 | + }, |
| 21 | + "score": { |
| 22 | + "description": [ |
| 23 | + "Check game can be scored correctly." |
| 24 | + ], |
| 25 | + "cases": [{ |
| 26 | + "description": "should be able to score open frame", |
| 27 | + "rolls": [3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 28 | + "expected": 7 |
| 29 | + }, { |
| 30 | + "description": "should be able to score multiple frames", |
| 31 | + "rolls": [3, 4, 2, 3, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 32 | + "expected": 19 |
| 33 | + }, { |
| 34 | + "description": "should be able to score a game with all gutterballs", |
| 35 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 36 | + "expected": 0 |
| 37 | + }, { |
| 38 | + "description": "should be able to score a game with all single pin rolls", |
| 39 | + "rolls": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], |
| 40 | + "expected": 20 |
| 41 | + }, { |
| 42 | + "description": "should be able to score a game with all open frames", |
| 43 | + "rolls": [3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6], |
| 44 | + "expected": 90 |
| 45 | + }, { |
| 46 | + "description": "should be able to score a strike not in the last frame", |
| 47 | + "rolls": [10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 48 | + "expected": 26 |
| 49 | + }, { |
| 50 | + "description": "should be able to score a spare not in the last frame", |
| 51 | + "rolls": [5, 5, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 52 | + "expected": 20 |
| 53 | + }, { |
| 54 | + "description": "should be able to score multiple strikes in a row", |
| 55 | + "rolls": [10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 56 | + "expected": 81 |
| 57 | + }, { |
| 58 | + "description": "should be able to score multiple spares in a row", |
| 59 | + "rolls": [5, 5, 3, 7, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 60 | + "expected": 32 |
| 61 | + }, { |
| 62 | + "description": "should allow fill balls when the last frame is a strike", |
| 63 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1], |
| 64 | + "expected": 18 |
| 65 | + }, { |
| 66 | + "description": "should allow fill ball when the last frame is a spare", |
| 67 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 7], |
| 68 | + "expected": 17 |
| 69 | + }, { |
| 70 | + "description": "should allow fill balls to be a strike", |
| 71 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10], |
| 72 | + "expected": 30 |
| 73 | + }, { |
| 74 | + "description": "should be able to score a perfect game", |
| 75 | + "rolls": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10], |
| 76 | + "expected": 300 |
| 77 | + }] |
| 78 | + }, |
| 79 | + "validations": { |
| 80 | + "description": [ |
| 81 | + "Check game rules." |
| 82 | + ], |
| 83 | + "cases": [{ |
| 84 | + "description": "should not allow rolls with negative pins", |
| 85 | + "rolls": [-1], |
| 86 | + "expected": "Pins must have a value from 0 to 10" |
| 87 | + }, { |
| 88 | + "description": "should not allow rolls better than strike", |
| 89 | + "rolls": [11], |
| 90 | + "expected": "Pins must have a value from 0 to 10" |
| 91 | + }, { |
| 92 | + "description": "should not allow two normal rolls better than strike", |
| 93 | + "rolls": [5, 6], |
| 94 | + "expected": "Pin count exceeds pins on the lane" |
| 95 | + }, { |
| 96 | + "description": "should not allow two normal rolls better than strike in last frame", |
| 97 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6], |
| 98 | + "expected": "Pin count exceeds pins on the lane" |
| 99 | + }, { |
| 100 | + "description": "should not allow to take score at the beginning of the game", |
| 101 | + "rolls": [], |
| 102 | + "expected": "Score cannot be taken until the end of the game" |
| 103 | + }, { |
| 104 | + "description": "should not allow to take score before the game has ended", |
| 105 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 106 | + "expected": "Score cannot be taken until the end of the game" |
| 107 | + }, { |
| 108 | + "description": "should not allow rolls after the tenth frame", |
| 109 | + "rolls": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 110 | + "expected": "Should not be able to roll after game is over" |
| 111 | + }, { |
| 112 | + "description": "should not calculate score before fill balls have been played", |
| 113 | + "rolls": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], |
| 114 | + "expected": "Score cannot be taken until the end of the game" |
| 115 | + }] |
| 116 | + } |
| 117 | +} |
0 commit comments