Skip to content

Instantly share code, notes, and snippets.

@rpietro
Last active January 1, 2016 21:18
Show Gist options
  • Save rpietro/8202201 to your computer and use it in GitHub Desktop.
Save rpietro/8202201 to your computer and use it in GitHub Desktop.
Crafting Quality Code

Crafting Quality Code

A few notes from Jennifer Campbell & Paul Gries' outstanding Coursera MOOC Crafting Quality Code

Recipe for designing functions

  1. examples
  2. type contract
  3. header
  4. description
  5. body
  6. test

Choosing test cases

When choosing test cases, consider the following factors:

Size

  • For collections (strings, lists, tuples, dictionaries) test with:
  • empty collection
  • a collection with 1 item
  • smallest interesting case
  • collection with several items

Dichotomies

Consider your situation:

For example:

  • vowels/non-vowels
  • even/odd
  • positive/negative
  • empty/full

Boundaries

If a function behaves differently for a value near a particular threshold (i.e. an if statement checking when a value is 3; 3 is a threshold), test at the that threshold.

Order

If a function behaves differently when the values are in a different order, identify and test each of those orders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment