Created
November 29, 2017 20:26
-
-
Save johnhonan/0c0676205d89f85e9eeaa717f30f5ff6 to your computer and use it in GitHub Desktop.
Calculator test functions
This file contains hidden or 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
import unittest | |
from calculator import Calculator | |
# test the calculator functionality | |
class TestCalculator(unittest.TestCase): | |
def setUp(self): | |
self.calc = Calculator() | |
# this tests the add functionality | |
# 2 + 2 = 4 | |
# 2 + 4 = 6 | |
# 2 + (-2) = 0 | |
def test_calculator_add_method_returns_correct_result(self): | |
result = self.calc.add(2, 2) | |
self.assertEqual(4, result) | |
result = self.calc.add(2, 4) | |
self.assertEqual(6, result) | |
result = self.calc.add(2, -2) | |
self.assertEqual(0, result) | |
# this tests the subtract functionality | |
# 2 - 2 = 0 | |
# 2 - 4 = -2 | |
# 2 - (-4) = 6 | |
def test_calculator_subtract_method_returns_correct_result(self): | |
result = self.calc.subtract(2, 2) | |
self.assertEqual(0, result) | |
result = self.calc.subtract(2, 4) | |
self.assertEqual(-2, result) | |
result = self.calc.subtract(2, -4) | |
self.assertEqual(6, result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment