Sunday, February 2, 2014

Week 4: Practices on subclasses, errors, unittests

    Even though recursion was the main topic in lectures, I have to say that I learned something more from lab and exercise this week. During the lab, my task is to create some classes and subclasses, then finish up with some unittests for each class. The part of creating classes and subclasses was not very hard. The hard part for me is to create unittests, because my partner and I did not get any practice on it. Only thing we know is that we need to use assert to find out if actual is the same as expect. We had no clue what module should be imported, what superclass we should use, and what code we should put under if __name__ == '__main__'. After some researches, we figured out the necessary codes:
              import unittest
              import OurModuleName

              class TestOurModule(unittest.TestCase):
Then we created several proper test cases by using assert. At the end of file, we put:
              if __name__ == "__main__":
                     unittest.main(exit=False)

       On the other hand, I got more experienced about raising errors in this week's exercise. The exercise is quite simple, but I spent a lot time on it, since I had very limited knowledge about errors. After reviewing professor's notes, and reading information on websites. I successfully used try, and except to catch and process errors, while I used raise to produce a error.

       Since I mainly focused on unittests, subclasses, and errors this week, my goal for next week would be doing more practice on recursion, and master recursion.

No comments:

Post a Comment