SlideShare une entreprise Scribd logo
1  sur  3
the bowling game kata
Using the OCP rules, write a calculator for scores in ten-pin bowling:
@Test
public void gutterGame() throws Exception {
BowlingGame game = new BowlingGameFactory().create();
for (int i=0; i<20; i++) {
game.roll(0);
}
assertEquals(0, game.score());
}
Requirements
The tests are:
Gutter game: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 0
All ones: 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1 → 20
No spares: 0,0, 0,0, 3,4, 6,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 15
A spare: 0,0, 0,0, 3,7, 6,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 24
Final spare: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 3,7,2 → 12
A strike: 0,0, 0,0, 10, 2,3, 4,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 24
Final strike: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,7,2 → 19
Bonus variants
And here are some bonus variants:
 In Martian bowling there are 12 frames, with 3 rolls per frame.
All other rules are unchanged.
 In the Callisto variant, the rules are as for normal (Earth) bowling,
except as long as the last roll is a 10 you may keep on rolling.
 The Callisto variant may be played with Martian rules
 In Venusian rules the number of pins starts at 1 for the first frame,
and increases by 1 for each subsequent frame.
All other rules as per Earth bowling.
 The Venusian rules may be applied to all other variants
… in any combination.

Contenu connexe

Plus de Kevin Rutherford (17)

The 5-day challenge
The 5-day challengeThe 5-day challenge
The 5-day challenge
 
Red, green, ... what now?!
Red, green, ... what now?!Red, green, ... what now?!
Red, green, ... what now?!
 
Pair programming
Pair programmingPair programming
Pair programming
 
Tdd is dead
Tdd is deadTdd is dead
Tdd is dead
 
Hex arch
Hex archHex arch
Hex arch
 
Shepherding antipatterns
Shepherding antipatternsShepherding antipatterns
Shepherding antipatterns
 
Kata rules
Kata rulesKata rules
Kata rules
 
Movie app kata
Movie app kataMovie app kata
Movie app kata
 
Object discovery
Object discoveryObject discovery
Object discovery
 
Connascence
ConnascenceConnascence
Connascence
 
OCP Checkout kata
OCP Checkout kataOCP Checkout kata
OCP Checkout kata
 
OCP String Calculator kata
OCP String Calculator kataOCP String Calculator kata
OCP String Calculator kata
 
OCP kata overview
OCP kata overviewOCP kata overview
OCP kata overview
 
Telling not-asking
Telling not-askingTelling not-asking
Telling not-asking
 
Uml
UmlUml
Uml
 
Agile principles
Agile principlesAgile principles
Agile principles
 
Flow
FlowFlow
Flow
 

Bowling Game Kata Calculator Tests

  • 1. the bowling game kata Using the OCP rules, write a calculator for scores in ten-pin bowling: @Test public void gutterGame() throws Exception { BowlingGame game = new BowlingGameFactory().create(); for (int i=0; i<20; i++) { game.roll(0); } assertEquals(0, game.score()); }
  • 2. Requirements The tests are: Gutter game: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 0 All ones: 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1 → 20 No spares: 0,0, 0,0, 3,4, 6,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 15 A spare: 0,0, 0,0, 3,7, 6,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 24 Final spare: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 3,7,2 → 12 A strike: 0,0, 0,0, 10, 2,3, 4,0, 0,0, 0,0, 0,0, 0,0, 0,0 → 24 Final strike: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,7,2 → 19
  • 3. Bonus variants And here are some bonus variants:  In Martian bowling there are 12 frames, with 3 rolls per frame. All other rules are unchanged.  In the Callisto variant, the rules are as for normal (Earth) bowling, except as long as the last roll is a 10 you may keep on rolling.  The Callisto variant may be played with Martian rules  In Venusian rules the number of pins starts at 1 for the first frame, and increases by 1 for each subsequent frame. All other rules as per Earth bowling.  The Venusian rules may be applied to all other variants … in any combination.