pythonadventurer/run_manager — pull request #2 by ollie (2014-02-15 13:21:43+00:00)
Title: Moved the app code into a class so it will be easier to test

Hello,

Even though it looks like I rewrote the whole thing, that's not the case. Try doing a `git diff -w` to ignore whitespace.

I moved the functions into a class and made the startup code run only when the script is run directly from the command line (that's the `if __name__ == '__main'__:` thing, it's very common in python).

Then I created a test file which uses the unittest module to test your methods. The goal is to cover most of the methods so when you make future changes to the manager code, it will still function properly.

There is a problem though, your code is kind of messy: it combines the input/output stuff with data stuff as well as printing stuff. Writing tests forces you to write your methods in such a way that they are testable. Testing input/output is always messy so what I do is I try to separate the jobs: make a class(es) for managing the data and then another class(es) to do the controlling work and maybe another class(es) to do the printing. Voila, we now have a MVC pattern. :smile:

Don't worry about it, but try one thing: try to write some tests for your app. Start with those simple functions you already have (converts, calcs etc.). Think about how you could test the big ones, but it might be impossible, you would have to split the code to smaller functions which would be easier to test.

I hope I didn't break your code. :bowtie: