tdd rspec palindrome

12
• Presentation is available online at http://www.slideshare.net/jasonjnoble/tdd_rspec _palindrome

Upload: jason-noble

Post on 18-Dec-2014

308 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tdd rspec palindrome

• Presentation is available online at – http://www.slideshare.net/jasonjnoble/tdd_rspec_palindrome

Page 2: Tdd rspec palindrome

Test Driven Designto learn Recursion and Palindromes

Jason [email protected]

Page 3: Tdd rspec palindrome

Test Driven Design

• TDD is a software development practice that relies on the repetition of a very short development cycle– Write a failing test that defines a desired

improvement or new function– Write the minimum code possible to make the test

pass– Refactor the code to acceptable standards

Page 4: Tdd rspec palindrome

Red Green Refactor

• Write a failing test (Red)

• Make the test pass (Green)

• Refactor tests or code (NOT both!)

Page 5: Tdd rspec palindrome

Why use TDD?

• Helps you break problems down into small manageable tasks

• Writing tests takes the fear out of programming

• Writing tests helps you communicate what your code SHOULD do/accomplish

Page 6: Tdd rspec palindrome

Let's Talk about Recursion

• "In order to understand recursion, you must first understand recursion." – Anonymous

• Let's ask Google

Page 7: Tdd rspec palindrome

What is recursion?

Page 8: Tdd rspec palindrome

What is recursion?

• Recursion is simply:– A simple base case (or base cases)– A set of rules that reduce all other cases towards a

known base case• Example:– Your parents are your ancestors (base case)– The ancestors of your ancestors are also your

ancestors (recursion step)

Page 9: Tdd rspec palindrome

Another example

• Factorial– 1! equals 1 (Base case)– For any number n greater than 1, the factorial of

that number is simply n * n – 1– Factorial of 2 is 2 * 1! = 2 * 1 (base case) = 2– Factorial of 3 is 3 * 1! = 3 * 2 = 6– Factorial of 4 is 4 * 3! = 4 * 6 = 24– Factorial of 5 is 5 * 4! = 5 * 24 = 120

Page 10: Tdd rspec palindrome

Palindrome

• A palindrome is defined as "A word, phrase, number or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction".

• dad == dad.reverse• 10022001• radar

Page 11: Tdd rspec palindrome

Let's code it!

• git clone [email protected]:jasonnoble/tdd_rspec_palindrome.git

• What's in this repo?

Page 12: Tdd rspec palindrome

Palindrome recursive definition

• A given string is a palindrome if the string read forward is the same as the string read backwards

• Is an empty string a palindrome?

• Is a single character a palindrome?