Skip to content

Instantly share code, notes, and snippets.

@janernsting
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janernsting/913b40698f0e21a808a0 to your computer and use it in GitHub Desktop.
Save janernsting/913b40698f0e21a808a0 to your computer and use it in GitHub Desktop.
Tell, Don't Ask in Python
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