removed proxy, bridge, template, and strategy patterns as they were too abstract to offer much use.

This commit is contained in:
tylerlaberge
2016-08-28 20:32:45 -04:00
parent 7501604bbf
commit 6ce017a391
8 changed files with 0 additions and 385 deletions

View File

@@ -1,93 +0,0 @@
from unittest import TestCase
from pypatterns.structural.bridge import Bridge
class BridgeTestCase(TestCase):
"""
Unit testing class for the Bridge class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class DrawingAPI(object):
def __init__(self): pass
def draw_circle(self): pass
def draw_rectangle(self): pass
class DrawingAPI1(DrawingAPI):
def draw_circle(self):
return 'draw circle 1'
def draw_rectangle(self):
return 'draw rectangle 1'
class DrawingAPI2(DrawingAPI):
def draw_circle(self):
return 'draw circle 2'
def draw_rectangle(self):
return 'draw rectangle 2'
class Shape(Bridge):
def draw(self): pass
def do_something_high_level(self): pass
class CircleShape(Shape):
def draw(self):
return self.implementor.draw_circle()
def do_something_high_level(self):
return 'high level circle'
class RectangleShape(Shape):
def draw(self):
return self.implementor.draw_rectangle()
def do_something_high_level(self):
return 'high level rectangle'
self.drawing_api_one = DrawingAPI1()
self.drawing_api_two = DrawingAPI2()
self.circle_shape_one = CircleShape(self.drawing_api_one)
self.circle_shape_two = CircleShape(self.drawing_api_two)
self.rectangle_shape_one = RectangleShape(self.drawing_api_one)
self.rectangle_shape_two = RectangleShape(self.drawing_api_two)
def test_init(self):
"""
Test the __init__ method.
@raise AssertionError: If the test fails.
"""
self.assertEquals(self.drawing_api_one, self.circle_shape_one.implementor)
self.assertEquals(self.drawing_api_two, self.circle_shape_two.implementor)
self.assertEquals(self.drawing_api_one, self.rectangle_shape_one.implementor)
self.assertEquals(self.drawing_api_two, self.rectangle_shape_two.implementor)
def test_implementation(self):
"""
Test an implementation of the bridge pattern
@raise AssertionError: If the test fails.
"""
self.assertEquals('draw circle 1', self.circle_shape_one.draw())
self.assertEquals('draw circle 2', self.circle_shape_two.draw())
self.assertEquals('draw rectangle 1', self.rectangle_shape_one.draw())
self.assertEquals('draw rectangle 2', self.rectangle_shape_two.draw())
self.assertEquals('high level circle', self.circle_shape_one.do_something_high_level())
self.assertEquals('high level circle', self.circle_shape_two.do_something_high_level())
self.assertEquals('high level rectangle', self.rectangle_shape_one.do_something_high_level())
self.assertEquals('high level rectangle', self.rectangle_shape_two.do_something_high_level())

View File

@@ -1,65 +0,0 @@
from unittest import TestCase
from pypatterns.structural.proxy import Proxy
class ProxyTestCase(TestCase):
"""
Unit testing class for the Proxy class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Car(object):
def drive_car(self):
return 'drive car'
class Driver(object):
def __init__(self, age):
self.age = age
self.car = Car()
self.driver = Driver(17)
def test_valid_proxy(self):
"""
Test a Proxy class following the same interface as the subject.
@raise AssertionError: If the test fails.
"""
class ProxyCar(Proxy):
def __init__(self, subject, driver):
super().__init__(subject)
self.driver = driver
def drive_car(self):
if self.driver.age > 16:
return self._subject.drive_car()
else:
return 'Driver is too young to drive'
try:
proxy = ProxyCar(self.car, self.driver)
except AttributeError:
raise AssertionError()
else:
self.assertEqual('drive car', proxy.drive_car())
proxy.driver.age = 15
self.assertEqual('Driver is too young to drive', proxy.drive_car())
def test_invalid_proxy(self):
"""
Test a Proxy class that is not following the same interface as the subject.
@raise AssertionError: If the test fails.
"""
class ProxyCar(Proxy):
def __init__(self, subject, driver):
super().__init__(subject)
self.driver = driver
self.assertRaises(AttributeError, lambda: ProxyCar(self.car, self.driver))