SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
OCP String Calculator Kata
Using the OCP rules, write a very simple
string calculator using the following test template:
public class CalculatorTester {
@Test
public void sampleTest() {
Calculator calculator = new CalculatorFactory().create();
assertEquals(4, calculator.evaluate("2 + 2"));
}
}
OCP String Calculator Kata
The tests are:
" " -> 0
"234" -> 234
"6 + 3" -> 9
"12 + 34" -> 46
"6 - 3" -> 3
"18 - 4" -> 14
"6 * 3" -> 18
"5 * 22" -> 110
"6 / 3" -> 2
"36 / 12" -> 3
You can assume that:

A single space char separates the operator from the numbers.

Only integer arithmetic is to be supported.
OCP String Calculator Kata
Additional challenges:
"18 - 4 + 3" -> 17
"18 - 4 * 3" -> 6
"18 - (4 + 3)" -> 11
Only integer arithmetic is to be supported.

Contenu connexe

Plus de Kevin Rutherford (18)

Connascence hunting
Connascence huntingConnascence hunting
Connascence hunting
 
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 bowling kata
OCP bowling kataOCP bowling kata
OCP bowling 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
 

OCP String Calculator kata

  • 1. OCP String Calculator Kata Using the OCP rules, write a very simple string calculator using the following test template: public class CalculatorTester { @Test public void sampleTest() { Calculator calculator = new CalculatorFactory().create(); assertEquals(4, calculator.evaluate("2 + 2")); } }
  • 2. OCP String Calculator Kata The tests are: " " -> 0 "234" -> 234 "6 + 3" -> 9 "12 + 34" -> 46 "6 - 3" -> 3 "18 - 4" -> 14 "6 * 3" -> 18 "5 * 22" -> 110 "6 / 3" -> 2 "36 / 12" -> 3 You can assume that:  A single space char separates the operator from the numbers.  Only integer arithmetic is to be supported.
  • 3. OCP String Calculator Kata Additional challenges: "18 - 4 + 3" -> 17 "18 - 4 * 3" -> 6 "18 - (4 + 3)" -> 11 Only integer arithmetic is to be supported.