Dark theme

Writing to tests


Here's the start of a class matches these tests latlong.py. Note the considerable amount of code in set_long. If we hadn't been so rigorous with designing our tests to probe every eventuality, we'd probably have just written:
def set_long (self, longitude)
    self.long = longitude

and considered ourselves pretty pleased. But because we've been forced to think through the eventualities now, we've been much tighter with constraining our code. It may take longer to build both tests and the class (indeed, it can take a considerable percentage of the development time to build the tests), overall development time should be shorter, as there should be no need for extensive post-coding runtime bug testing, and the code should be very issue resistant if new code is added.


Can you write the two functions to match your two tests? Remember, you'll need to also write an exception class to join the two already in the file. Note that the code clauses starting:
if __name__ == '__main__':
run when the module is run as a script, but not otherwise. This just allows us to quickly test things if we need to in a fashion that isn't just about the end results; for example if we want to use a debugger or print some variable values.