Created
April 8, 2012 16:53
-
-
Save mattjmorrison/2338429 to your computer and use it in GitHub Desktop.
Inherit Tests Cases
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 FirstGradeMath(object): | |
def __init__(self, first_number, second_number): | |
self.first_number = first_number | |
self.second_number = second_number | |
def add(self): | |
return self.first_number + self.second_number | |
def subtract(self): | |
return self.first_number - self.second_number |
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
import first_grade | |
class SecondGradeMath(first_grade.FirstGradeMath): | |
def multiply(self): | |
return self.first_number * self.second_number | |
def divide(self): | |
return self.first_number / self.second_number |
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
import unittest | |
import first_grade | |
class FirstGradeMathTests(unittest.TestCase): | |
def setUp(self): | |
self.sut = first_grade.FirstGradeMath(2, 2) | |
def test_addition(self): | |
self.assertEqual(4, self.sut.add()) | |
def test_subtraction(self): | |
self.assertEqual(0, self.sut.subtract()) |
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
import second_grade | |
import test_first_grade | |
class SecondGradeMathTests(test_first_grade.FirstGradeMathTests): | |
def setUp(self): | |
self.sut = second_grade.SecondGradeMath(2, 2) | |
def test_multiplication(self): | |
self.assertEqual(4, self.sut.multiply()) | |
def test_division(self): | |
self.assertEqual(1, self.sut.divide()) |
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
import first_grade | |
import second_grade | |
import unittest | |
class FirstGradeMathTests(unittest.TestCase): | |
sut_class = first_grade.FirstGradeMath | |
def test_addition(self): | |
sut = self.sut_class(2, 2) | |
self.assertEqual(4, sut.add()) | |
def test_subtraction(self): | |
sut = self.sut_class(2, 2) | |
self.assertEqual(0, sut.subtract()) | |
class SecondGradeMathTests(FirstGradeMathTests): | |
sut_class = second_grade.SecondGradeMath | |
def test_multiplication(self): | |
sut = self.sut_class(2, 2) | |
self.assertEqual(4, sut.multiply()) | |
def test_division(self): | |
sut = self.sut_class(2, 2) | |
self.assertEqual(1, sut.divide()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment