Name: [171] Florian Mayer
Member: 87 months
Authored: 7 videos
Description: I'm a student from Vienna, the federal capital of Austria. Please visit `My Blog <http://segfaulthunter.blogspot.com/>`_ ...

Test Driven Development by Example [ID:851] (2/2)

in series: Unittesting with Python

video tutorial by Florian Mayer, added 08/08

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

This video is an introduction into test-driven development. It teaches you how to develop software using test-driven development at the example of a roman numeral converter.

# roman_numerals.py
class OutOfRangeError(Exception):
    pass


roman_numeral_map = (
    ('M', 1000), ('CM', 900),
    ('D',  500),  ('CD', 400),
    ('C',  100),  ('XC', 90),
    ('L',  50),    ('XL', 40),
    ('X',  10),   ('IX', 9),
    ('V',  5),     ('IV', 4), 
    ('I',  1))


def to_roman(x):
    output = ''
    if x < 1:
        raise OutOfRangeError
    for roman, normal in roman_numeral_map:
        while x - normal >= 0:
            output += roman
            x -= normal
    return output

# tests.py
import unittest
import roman_numerals

class ToRomanKnown(unittest.TestCase):
    def test_known(self):
        self.assertEqual(roman_numerals.to_roman(5), "V")
        self.assertEqual(roman_numerals.to_roman(10), "X")
        self.assertEqual(roman_numerals.to_roman(15), "XV")
        self.assertEqual(roman_numerals.to_roman(42), "XLII")
    
class ToRomanBadInput(unittest.TestCase):
    def test_zero(self):
        self.assertRaises(roman_numerals.OutOfRangeError, roman_numerals.to_roman, 0)
    
    def test_negative(self):
        self.assertRaises(roman_numerals.OutOfRangeError, roman_numerals.to_roman, -1)
            

if __name__ == '__main__':
    unittest.main()

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 2642 (since July 30th)
  • Plays in last week: 0
  • Published: 68 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>








All comments excluding tick-boxed quick-comments

Nice intro


21. R. Mark Sharp Wed, 01 Sep 2010 15:05

Very nice. I appreciate it.


I am glad I watched the video. I found this very helpful


Thanks. was good


18. Gordon McQuarrie Thu, 18 Feb 2010 23:04

Quick, clear and to the point - well done.


17. J.F. Sebastian Tue, 16 Feb 2010 11:17

Thanks. For a beginner like me it was helpful to see how to actually run the tests (written tutorials seem to assume it to be obvious -_-;)


Great video, look forward to see more.


15. Peg Duffy Fri, 05 Feb 2010 15:06

Watched both part 1 and 2 or test driven development with python. I know test driven development but not python. Your videos were very good. Taught me how to get started using unittest. Thank you.


Great job! Really helpful introduction to TDD with easy to follow code.


13. anonymous Fri, 25 Dec 2009 12:40

great job! simple and clear.


12. anonymous Thu, 17 Dec 2009 06:42

very nice -- but perhaps a bit too fast, esp once you run the test. there's barely time to watch the results before you jump back. Remember that most likely the people watching this are learning about this, so they want to look at the output (fast coding is ok :-)

This is a minor problem however since we can just watch parts of the clip again I suppose. Thanks again for taking time to do this.


11. anonymous Wed, 09 Dec 2009 17:02

Good stuff ... thanks for clear examples


10. anonymous Mon, 30 Nov 2009 15:07

Good, succint video.


9. anonymous Mon, 16 Nov 2009 05:32

Really enjoyed your video. I'm actually a Java programmer. (I quite like Python though).

However, I was interested in the 'thought-processes' that a developer goes through when doing Test Driven Development.


8. anonymous Sat, 14 Nov 2009 06:44

Great job!!

I have been assigned unit testing using python..I have just started learning python, and ur videos are great to start with!!


7. anonymous Fri, 30 Oct 2009 23:43

Thank you again!

I am looking forward to the second installment.


6. anonymous Tue, 13 Oct 2009 20:23

Very helpful! Thank you.


5. anonymous Fri, 24 Jul 2009 07:35

thanks, was helpful.


4. anonymous Thu, 28 May 2009 21:52

Salamat!


3. anonymous Tue, 14 Apr 2009 20:28

nice work, man. i appreciate it


2. anonymous Tue, 14 Apr 2009 20:27

nice work, man. i appreciate it


The ShowMeDo Robot says - this video is now published, thanks for adding to ShowMeDo.


Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Florian

Content

Feedback

Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.

feedback@showmedo.com