How to test your functions
Today's programming tasks
Now that we're writing functions, we can start to write tests for our code. As you work through assignments in this class you will be expected to write tests to demonstrate that your code does what it's supposed to do.
Before you write a function, you need to understand what it's supposed to do. Therefore, you can generally write the tests before you write the python. For now, writing tests just means deciding what input (argument values) you will give the function and what output (side effects and/or fruit) will result from running the function with that input. You should write your input/output test pairs in a comment connected to your function so the grader can check try to run your suggested tests to see if they work.
While there is still testing in the lab notebook for tasks where you are not writing functions, tasks where you are writing functions will require you to test yourself. Try to write 2 sample input/output pairs for each function before you write the python. Once you've written the function, run it with your inputs. If the outputs don't match your predictions, you should try to figure out why (and fix the code or tests as needed). Note: if a function has no parameters there's only one test to write.
This week's extra practice is here.