Clone the logging_numpy_matplotlib_classwork repo. See Canvas Announcement
Issue on Splitting
Be careful with lines such as this:
domain, toplevel = string.split(".")
If the string does not contain a period, or if the string has more than one period, the above line will raise a ValueError because it is written to expect two items in return to go into the domain and toplevel variables. But, if it only receives one or more than two, it doesn't have the right number of values to put into two variables and it will cause an Error. Only use this format if you are absolutely certain there will be two responses.
How to write it better?
Check that there is only one period before executing the split by running code like this:
if string.count(".") == 1:
Have the result of the split be put into a single variable which will give you a list of results. You can then act on this variable based on how many results there are. Example:
answer = string.split(".")
if len(answer) == 2:
domain, toplevel = answer
else:
# Code to respond to other numbers of periods
Make sure test cases only have a single reason to fail.
Example: Assume we are testing a function that is checking the prefix.
Test Case: _blue..devil
def check_prefix(prefix):
if prefix starts with `_` then return False
return True
Unit Testing for ALL Functions
Be sure to write modular code so that any user input/output is done in a function that does nothing else.
All other functions, as much as possible, should have an input in the form of an argument(s) and an output using return.
Every function, other than I/O functions, should have a unit test.
Unrelated Clarification on Live/Dead Cell Assay Analysis Assignment
You can assume that every patient will have image data and that it will be at least 1 x 1.
Clone the logging_numpy_matplotlib_classwork repo. See Canvas Announcement
Issue on Splitting
Be careful with lines such as this:
If the string does not contain a period, or if the string has more than one period, the above line will raise a
ValueError
because it is written to expect two items in return to go into thedomain
andtoplevel
variables. But, if it only receives one or more than two, it doesn't have the right number of values to put into two variables and it will cause an Error. Only use this format if you are absolutely certain there will be two responses.How to write it better?
Make sure test cases only have a single reason to fail.
Example: Assume we are testing a function that is checking the prefix. Test Case:
_blue..devil
Unit Testing for ALL Functions
return
.Unrelated Clarification on Live/Dead Cell Assay Analysis Assignment
You can assume that every patient will have image data and that it will be at least 1 x 1.