Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.48 KB

2-simple_function.md

File metadata and controls

39 lines (26 loc) · 1.48 KB

Write tests for a simple function

This assumes you have setup your environment as described in 1-run_tests.md and that you are in your virtualenv.

calico

If you get stuck, take a peek at the solution.

  1. We will be writing tests for catmath.py. This module contains only one function cat_years_to_hooman_years.

  2. Look at the existing tests. You can see there are test stubs:

    • test__cat_years_to_hooman_years__middle_age__succeeds
    • test__cat_years_to_hooman_years__less_than_one_year__succeeds
    • test__cat_years_to_hooman_years__0__returns_0
  3. Fill in the body of these tests. Based on their names, what test case do you think each of these is trying to cover?

    Each test should be calling cat_years_to_hooman_years with different input and asserting based on the output.

  4. When you have filled in the body of these tests, run them:

(catpy)user@host:~/catinabox$ python setup.py test

Bonus

Try to write some tests for is_cat_leap_year. (When these tests run successfully, you should see an increase in coverage!) Are you sufficiently convinced that this function works now? Why or why not?

We'd love to have a discussion about this with you if you get this far. Every developer will have different opinions about this :)