removed proxy, bridge, template, and strategy patterns as they were too abstract to offer much use.
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
from unittest import TestCase
|
||||
from pypatterns.behavioral.strategy import Strategy
|
||||
|
||||
|
||||
class StategyTestCase(TestCase):
|
||||
"""
|
||||
Unit testing class for the Strategy pattern.
|
||||
"""
|
||||
def setUp(self):
|
||||
"""
|
||||
Initialize testing data.
|
||||
"""
|
||||
class AddStrategy(Strategy):
|
||||
|
||||
def __call__(self, a, b):
|
||||
return a + b
|
||||
|
||||
class SubtractStrategy(Strategy):
|
||||
|
||||
def __call__(self, a, b):
|
||||
return a - b
|
||||
|
||||
class Solver(object):
|
||||
|
||||
def __init__(self, strategy):
|
||||
self.strategy = strategy
|
||||
|
||||
def solve(self, a, b):
|
||||
return self.strategy(a, b)
|
||||
|
||||
self.add_class = AddStrategy
|
||||
self.subtract_class = SubtractStrategy
|
||||
self.solver_class = Solver
|
||||
|
||||
def test_add_strategy(self):
|
||||
"""
|
||||
Test the add strategy.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
solver = self.solver_class(self.add_class())
|
||||
|
||||
self.assertEquals(15, solver.solve(5, 10))
|
||||
|
||||
def test_subtract_strategy(self):
|
||||
"""
|
||||
Test the subtract strategy.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
solver = self.solver_class(self.subtract_class())
|
||||
|
||||
self.assertEquals(10, solver.solve(100, 90))
|
||||
|
||||
def test_switch_strategies(self):
|
||||
"""
|
||||
Test changing out strategies.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
solver = self.solver_class(self.add_class())
|
||||
self.assertEquals(5, solver.solve(2, 3))
|
||||
|
||||
solver.strategy = self.subtract_class()
|
||||
self.assertEquals(-1, solver.solve(2, 3))
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
from unittest import TestCase
|
||||
from pypatterns.behavioral.template import Template
|
||||
|
||||
|
||||
class TemplateTestCase(TestCase):
|
||||
"""
|
||||
Unit testing class for the Template class
|
||||
"""
|
||||
def setUp(self):
|
||||
"""
|
||||
Initialize testing data.
|
||||
"""
|
||||
class MakeMeal(Template):
|
||||
|
||||
def __init__(self):
|
||||
self.prepared = False
|
||||
self.cooked = False
|
||||
self.eaten = False
|
||||
self.drank = False
|
||||
|
||||
def go(self):
|
||||
self.prepare()
|
||||
self.cook()
|
||||
self.eat()
|
||||
self.drink()
|
||||
|
||||
def prepare(self):
|
||||
pass
|
||||
|
||||
def cook(self):
|
||||
pass
|
||||
|
||||
def eat(self):
|
||||
pass
|
||||
|
||||
def drink(self):
|
||||
pass
|
||||
|
||||
class MakePizza(MakeMeal):
|
||||
|
||||
def prepare(self):
|
||||
self.prepared = True
|
||||
|
||||
def cook(self):
|
||||
self.cooked = True
|
||||
|
||||
def eat(self):
|
||||
self.eaten = True
|
||||
|
||||
class MakeTea(MakeMeal):
|
||||
|
||||
def prepare(self):
|
||||
self.prepared = True
|
||||
|
||||
def cook(self):
|
||||
self.cooked = True
|
||||
|
||||
def drink(self):
|
||||
self.drank = True
|
||||
|
||||
self.make_pizza = MakePizza()
|
||||
self.make_tea = MakeTea()
|
||||
|
||||
def test_go(self):
|
||||
"""
|
||||
Test the go method.
|
||||
|
||||
@raise AssertionError: If the test fails.
|
||||
"""
|
||||
self.make_pizza.go()
|
||||
self.make_tea.go()
|
||||
|
||||
self.assertTrue(self.make_pizza.prepared)
|
||||
self.assertTrue(self.make_pizza.cooked)
|
||||
self.assertTrue(self.make_pizza.eaten)
|
||||
self.assertFalse(self.make_pizza.drank)
|
||||
|
||||
self.assertTrue(self.make_tea.prepared)
|
||||
self.assertTrue(self.make_tea.cooked)
|
||||
self.assertFalse(self.make_tea.eaten)
|
||||
self.assertTrue(self.make_tea.drank)
|
||||
Reference in New Issue
Block a user