karumi dojo - string calculator kata

20
Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs Karumi Dojo Pedro Vicente Gómez Sánchez Senior Android Developer at Karumi [email protected] @pedro_g_s github.com/pedrovgs

Upload: pedro-vicente-gomez-sanchez

Post on 12-Apr-2017

2.073 views

Category:

Engineering


6 download

TRANSCRIPT

Page 1: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Karumi DojoPedro Vicente Gómez SánchezSenior Android Developer at Karumi

[email protected]@pedro_g_sgithub.com/pedrovgs

Page 2: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Page 3: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Irene HerranzManaging Director

Alberto GrageraTechnical Director

Jorge BarrosoAndroid Expert

Davide MendoliaFull Stack Engineer

Page 4: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Page 5: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Karumi Dojo● We are here to practice and learn.

● This is a bullshit free environment.

● This exercise meant to be collaborative, not competitive.

● Try to open your mind to new concepts.

Page 6: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Karumi Dojo● We are here to practice Test-Driven Development.

● TDD is a software development process, not a dogma.

● We are going to practice pair programming.

● Keep always in mind the TDD Cycle.

Page 7: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Rules:

● Write enough test code so that to get a single test failure.

● Write enough production code to get all your tests to pass.

● Refactor until the code is Simple/Clean.

Page 8: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Rules: The TDD Cycle

RED

GREENREFACTOR

3. Simplify and clean your code.

1. Write a failing test.

2. Make the code work.

Page 9: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Sum the number inside string passed as parameter: 1,2,3 = 6

String Calculator

public int add(String numbers) {//Put your code here

}

Page 10: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Business Rule 1

The method can take 0, 1 or 2 numbers, and will return their sum (for an empty

string it will return 0) for example “” or “1” or “1,2”.

Page 11: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Business Rule 2

Allow the Add method to handle an unknown amount of numbers.

Page 12: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Business Rule 3

Allow the Add method to handle new lines between numbers (instead of commas).

Page 13: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Business Rule 4Calling Add with a negative number will

throw an exception “negatives not allowed” - and the negative that was

passed. If there are multiple negatives, show all of them in the exception

message

Page 14: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Rule 5

If the delimiter used is not “,” or “\n” throw an exception.

Page 15: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Tips● Baby steps.

● Don’t lose the green.

● Choose the language you prefer.

● Refactor your code.

● Build errors are not failing tests.

● Follow the TDD Cycle.

Page 16: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

http://goo.gl/erofJ5

Page 17: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Extra points

Page 18: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Extra Rule 1

Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2

Page 19: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Extra Rule 2To change a delimiter, the beginning of the string

will contain a separate line that looks like this: “//[delimiter]\n[numbers…]” for example “//;\n1;2”

should return three where the default delimiter is ‘;’ .

The first line is optional. all existing scenarios should still be supported

Page 20: Karumi Dojo - String Calculator Kata

Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

Extra Rule 3

Allow multiple delimiters like this:

“//[delim1][delim2]\n” for example “//[*][%]\n1*2%3” should return 6.