dward2 / BME547

Medical Software Design
74 stars 165 forks source link

Unit Testing and CI Assignment Feedback #517

Closed dward2 closed 1 year ago

dward2 commented 1 year ago

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?

  1. Check that there is only one period before executing the split by running code like this:
    if string.count(".") == 1:
  2. 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

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.