Skip to content

Instantly share code, notes, and snippets.

@AndyLPK247
Created March 11, 2017 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyLPK247/5fe28e7d6c524e342c5f4db8ea620d5a to your computer and use it in GitHub Desktop.
Save AndyLPK247/5fe28e7d6c524e342c5f4db8ea620d5a to your computer and use it in GitHub Desktop.
Python Testing 101 doctest Example: Calculator Class
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
def maximum(self, a, b):
self._last_answer = a if a >= b else b
return self.last_answer
def minimum(self, a, b):
self._last_answer = a if a <= b else b
return self.last_answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment