Last active
March 10, 2017 02:30
-
-
Save AndyLPK247/ba78ddbc6b963bc5d7fc338162107b78 to your computer and use it in GitHub Desktop.
Python Testing 101 unittest Example: Calculator Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculator(object): | |
def __init__(self): | |
self._last_answer = 0.0 | |
@property | |
def last_answer(self): | |
return self._last_answer | |
def add(self, a, b): | |
self._last_answer = a + b | |
return self.last_answer | |
def subtract(self, a, b): | |
self._last_answer = a - b | |
return self.last_answer | |
def multiply(self, a, b): | |
self._last_answer = a * b | |
return self.last_answer | |
def divide(self, a, b): | |
# automatically raises ZeroDivisionError | |
self._last_answer = a * 1.0 / b | |
return self.last_answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment