Workout for your TDD
What to expect?
Why software testing?
http://lmgtfy.com/?q=why+software+testing%3F
How to convince your boss of TDD?
http://lmgtfy.com/?q=How+to+convince+my+boss+of+TDD%3F
What to expect?
Exercise only!
(almost)
Overall agenda
Quest showoff
Coding session
Presentation of results / Discussion
Project setup
TDD / Pair programming
Test
Driven
Development
Red
Green
Refactor
Write a test which will fail with the current implementation!
Implement code to fulfill the tests requirements!
Refactor as you wish!
Tests may not change to red!
Ping-pong paired programming
Red
Green
Refactor
Red
Green
Refactor
Red
Any questions so far?
Just asking ;)
Prerequisite: Setup your project!
Any language!
Test framework!
Backup (PHP):
git clone git@github.com:mjainta/php-simple-template.git
$ make setup
$ make test
Our Exercise today!
Epic weapon generator
The Quest!
You are a blacksmith and calculate the strength of your weapons by its name!
Names can be anything you may image, example names might be..
Mighty Axe of a thousand Bloodbaths
The heroic hammer of 7 heavens
Little rubber duck for the bathtub
The Quest!
Key notes
Write a function which takes one parameter, the weapon name as a string, and returns its strength!
Each word in the weapons name counts strength +3
Some words have a special meaning:
-
tiny => strength +5
- "Cute tiny hammer"
= 3 + 5 + 3 = 11
- "Cute tiny hammer"
-
awesome => Multiplies strength of all prior words by 2
- "Shining mace of awesome power"
= (3 + 3 + 3) * 2 + 3 = 21
- "Shining mace of awesome power"
Start Coding!
Start Coding!
What have you crafted?
Presentation of results
The Quest!
Extension
We add conditions to weapons, expressed by a word in braces at the end. There are three conditions.
-
Perfect: Multiplies strength by 1.5
- "Cute tiny hammer (Perfect)"
= (3 + 5 + 3) * 1.5 = 16.5
- "Cute tiny hammer (Perfect)"
- Normal: Changes nothing
-
Flawed: Multiplies strength by 0.5
- "Cute tiny hammer (Flawed)"
= (3 + 5 + 3) * 0.5 = 5.5
- "Cute tiny hammer (Flawed)"
Weapons without a specific condition are considered as normal!
What have you crafted?
Presentation of results
You have done it!
Thank you
Workout for your TDD
By Martin Jainta
Workout for your TDD
- 48