Last active
August 29, 2015 14:01
-
-
Save janernsting/913b40698f0e21a808a0 to your computer and use it in GitHub Desktop.
Tell, Don't Ask in Python
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 hamcrest import * | |
import unittest | |
class GameOfLifeTest(unittest.TestCase): | |
def setUp(self): | |
self.was_invoked = False | |
def invoke(self): | |
self.was_invoked = True | |
def testDeadCellIsDead(self): | |
DeadCell().executeIfDead(self.invoke) | |
assert_that(self.was_invoked) | |
def testDeadCellIsNotAlive(self): | |
DeadCell().executeIfAlive(self.invoke) | |
assert_that(is_not(self.was_invoked)) | |
def testLiveCellIsNotDead(self): | |
LiveCell().executeIfDead(self.invoke) | |
assert_that(is_not(self.was_invoked)) | |
def testLiveCellIsAlive(self): | |
LiveCell().executeIfAlive(self.invoke) | |
assert_that(is_(self.was_invoked)) | |
class DeadCell: | |
def executeIfDead(self, invokable): | |
invokable() | |
def executeIfAlive(self, invokable): | |
pass | |
class LiveCell: | |
def executeIfDead(self, invokable): | |
pass | |
def executeIfAlive(self, invokable): | |
invokable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment