Created
March 14, 2017 03:11
-
-
Save AndyLPK247/2ba5fc21c2243dcf4939a8e65cec3cd2 to your computer and use it in GitHub Desktop.
Python Testing 101 pytest 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
from com.automationpanda.example.calc_func import * | |
class Calculator(object): | |
def __init__(self): | |
self._last_answer = 0.0 | |
@property | |
def last_answer(self): | |
return self._last_answer | |
def _do_math(self, a, b, func): | |
self._last_answer = func(a, b) | |
return self.last_answer | |
def add(self, a, b): | |
return self._do_math(a, b, add) | |
def subtract(self, a, b): | |
return self._do_math(a, b, subtract) | |
def multiply(self, a, b): | |
return self._do_math(a, b, multiply) | |
def divide(self, a, b): | |
return self._do_math(a, b, divide) | |
def maximum(self, a, b): | |
return self._do_math(a, b, maximum) | |
def minimum(self, a, b): | |
return self._do_math(a, b, minimum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment