karumi dojo - string calculator kata
TRANSCRIPT
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
Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs
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
Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs
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.
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.
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.
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.
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
}
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”.
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.
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).
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
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.
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.
Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs
http://goo.gl/erofJ5
Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs
Extra points
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
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
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.