Tdd rspec palindrome

826 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
826
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tdd rspec palindrome

  1. 1. • Presentation is available online at– http://www.slideshare.net/jasonjnoble/tdd_rspec_palindrome
  2. 2. Test Driven Designto learn Recursion and PalindromesJason Nobleinstructor@jasonnoble.org
  3. 3. Test Driven Design• TDD is a software development practice thatrelies on the repetition of a very shortdevelopment cycle– Write a failing test that defines a desiredimprovement or new function– Write the minimum code possible to make thetest pass– Refactor the code to acceptable standards
  4. 4. Red Green Refactor• Write a failing test (Red)• Make the test pass (Green)• Refactor tests or code (NOT both!)
  5. 5. Why use TDD?• Helps you break problems down into smallmanageable tasks• Writing tests takes the fear out ofprogramming• Writing tests helps you communicate whatyour code SHOULD do/accomplish
  6. 6. Lets Talk about Recursion• "In order to understand recursion, you mustfirst understand recursion." – Anonymous• Lets ask Google
  7. 7. What is recursion?
  8. 8. What is recursion?• Recursion is simply:– A simple base case (or base cases)– A set of rules that reduce all other cases towards aknown base case• Example:– Your parents are your ancestors (base case)– The ancestors of your ancestors are also yourancestors (recursion step)
  9. 9. Another example• Factorial– 1! equals 1 (Base case)– For any number n greater than 1, the factorial ofthat 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
  10. 10. Palindrome• A palindrome is defined as "Aword, phrase, number or other sequence ofsymbols or elements, whose meaning may beinterpreted the same way in either forward orreverse direction".• dad == dad.reverse• 10022001• radar
  11. 11. Lets code it!• git clonegit@github.com:jasonnoble/tdd_rspec_palindrome.git• Whats in this repo?
  12. 12. Palindrome recursive definition• A given string is a palindrome if the string readforward is the same as the string readbackwards• Is an empty string a palindrome?• Is a single character a palindrome?

×