Slide 1

Slide 1 text

@gregmalcolm @gregmalcolm Python Koans Primer

Slide 2

Slide 2 text

RED GREEN REFACTOR Test Driven Development (TDD) Write a failing test Make it pass Clean up!

Slide 3

Slide 3 text

REDWrite a failing test What do I want to do? Sir Lancelot should have a favorite color

Slide 4

Slide 4 text

REDWrite a failing test def test_that_lancelots_favorite_color_is_blue(self): lancelot = Lancelot() self.assertEquals("blue", lancelot.favorite_color()); ... Traceback (most recent call last): File "test_lancelot.py", line 11, in test_that_lancelots_favorite_color_is_blue self.assertEquals("blue", lancelot.favorite_color()); AttributeError: 'Lancelot' object has no attribute 'favorite_color' ...

Slide 5

Slide 5 text

REDWrite a failing test

Slide 6

Slide 6 text

GREENMake it pass What is the simplest thing I can do to make it pass?

Slide 7

Slide 7 text

Make it pass class Lancelot(object): pass class Lancelot(object): def favorite_color(self): return 'Blue' ... Traceback (most recent call last): File "test_lancelot.py", line 11, in test_that_lancelots_favorite_color_is_blue self.assertEquals("blue", lancelot.favorite_color()); AttributeError: 'Lancelot' object has no attribute 'favorite_color' ... ---------------------------------------------------------------------- Ran 1 test in 0.000s OK GREEN

Slide 8

Slide 8 text

REFACTOR Clean up class Lancelot(object): def favorite_color(self): return 'Blue' class Robin(object): def favorite_color(self): return 'Blue. No yel-- Auuuuuuuugh!'

Slide 9

Slide 9 text

Clean up def test_that_lancelots_favorite_color_is_blue(self): lancelot = Lancelot() self.assertEquals("blue", lancelot.favorite_color()); class Lancelot(object): def favorite_color(self): return 'Blue' def test_that_lancelots_favorite_color_is_blue(self): lancelot = Knight('Lancelot', 'blue') self.assertEquals("blue", lancelot.favorite_color()); class Lancelot(object): def favorite_color(self): return 'Blue' REFACTOR

Slide 10

Slide 10 text

Clean up def test_that_lancelots_favorite_color_is_blue(self): lancelot = Knight('Lancelot', 'blue') self.assertEquals("blue", lancelot.favorite_color()); class Knight(object): def __init__(self, name, favorite_color): self._name = name self._favorite_color = favorite_color def favorite_color(self): return self._favorite_color REFACTOR

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

REFACTORClean up Applying TDD principals to Python Koans GREENMake it pass REDWrite a failing test See a failing test Make it pass Reflect

Slide 13

Slide 13 text

class Sources(object): http://commons.wikimedia.org/wiki/File:Ouroboros-simple.svg http://farm4.static.flickr.com/3213/2979328686_f56f213576_o.png http://ihasahotdog.files.wordpress.com/2009/08/funny-dog-pictures-red-balloons.jpg http://static.howstuffworks.com/gif/snake-anatomy.gif def images(self): def information(self): http://github.com/edgecase/ruby_koans/blob/master/README.rdoc http://www.slideshare.net/Siddhi/test-driven-development-with-python http://jamesshore.com/Blog/Red-Green-Refactor.html def python_koans(self): http://bitbucket.org/gregmalcolm/python_koans http://wiki.github.com/gregmalcolm/python_koans/ def other_koans(self): http://github.com/edgecase/ruby_koans http://rubyquiz.com/quiz67.html http://github.com/chicagoruby/MongoDB_Koans http://github.com/CoryFoy/DotNetKoans http://github.com/relevance/functional-koans

Slide 14

Slide 14 text

http://github.com/gregmalcolm/python_koans