-
-
Save justinvoss/1190189 to your computer and use it in GitHub Desktop.
Overloading constructor example
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
class Greeter: | |
def __init__(self, greeting=None): | |
self.myGreeting = greeting or 'Hello World!' | |
def greeting(self): | |
return self.myGreeting |
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 spike import Greeter | |
class GreeterTest(unittest.TestCase): | |
def test_greetingReturnsDefault(self): | |
mw = Greeter() | |
self.assertEqual(mw.greeting(),'Hello World!','greeting is not as expected') | |
def test_greetingReturnsConstructorProvidedContent(self): | |
mw = Greeter('booyah!') | |
self.assertEqual(mw.greeting(),'booyah!') | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment