Upload
michael-willis
View
121
Download
0
Embed Size (px)
Citation preview
Powershell TDDMichael Willis
About
Following concept from https://laracasts.com/series/code-katas-in-php/episodes/2
This following is an except from a class presentation.
Test-Driven Development
1. Write a test case for some code that has yet to be implemented
2. Run the test case to verify it, which fails
3. Write only as much code as necessary to make the test pass
4. Run the test case
Roman Numeral Calculator
1 => I; Write the test; Watch it fail.
Simplest implementation to make it pass
Returning “I” brings us to “Green”
2 => II; Write Test; Watch it Fail
Strategies
Two simple ways to make this pass. We chose to use the second method.
5 => V; Write Test; Watch it Fail.
Make V=>5 Pass.
Add VI => 6 to Tests; Watch it fail
Refactoring to use a $solution variable.
Testing after Refactor; 6 still fails.
Remove the Else statement. Still Failing tests for 5 & 6.
Add minimal code to make test pass.
X => 10; Write Test; Watch it Fail.
Code duplication pattern becoming apparent
Write Test for 11=>XI
Test is already passing; Move on to next edge case.
20 => XX; Write Test; Watch it Fail.
Changing “if” to “while” lets this logic run twice for 20 making the test pass.
50 => L; Write Test; Watch it Fail.
Duplicate code shows us that we may have room for refactoring.
4 => IV; Write Test; Watch it Fail.
Make 4 Pass
Test for 9 is added.After 9 Fails we duplicate the code from 10 and change it to make 9 pass.
Refactor to pattern
Other if statements will also pass using a while statement.
Refactor (cont.)
The Statement
can be refactored to use a while loop as well.
Refactor
Duplicate code removed by using a lookup hashtable. Test by removing the: while “$Number -ge 50 loop.”
Tests still Green!
Remove >= 10 Loop; Fail since Lookup missing X.
Add 10 = “X” to lookup; Back to Green.
Remove all other while loops; Add Values to lookup.
Why is L Failing?
Hashtables are not sorted.
Missing Edge Cases
Back to Green!
Community Help
Team integration apps can help with on the fly code review / testing.
Almost forgot the sunflower