ran code reformat
This commit is contained in:
@@ -12,6 +12,7 @@ class ChainLink(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
Abstract ChainLink object as part of the Chain of Responsibility pattern.
|
Abstract ChainLink object as part of the Chain of Responsibility pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialize a new ChainLink instance.
|
Initialize a new ChainLink instance.
|
||||||
@@ -52,6 +53,7 @@ class Chain(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
Abstract Chain class as part of the Chain of Responsibility pattern.
|
Abstract Chain class as part of the Chain of Responsibility pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, chainlink):
|
def __init__(self, chainlink):
|
||||||
"""
|
"""
|
||||||
Initialize a new Chain instance.
|
Initialize a new Chain instance.
|
||||||
@@ -76,4 +78,4 @@ class Chain(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
The method to call when the chain could not handle a request.
|
The method to call when the chain could not handle a request.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ class InvalidInvokerCommandException(Exception):
|
|||||||
"""
|
"""
|
||||||
Exception for when an invalid command is given to an Invoker to execute.
|
Exception for when an invalid command is given to an Invoker to execute.
|
||||||
"""
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Receiver(object, metaclass=ABCMeta):
|
class Receiver(object, metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
Abstract receiver class as part of the Command pattern.
|
Abstract receiver class as part of the Command pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def action(self, name, *args, **kwargs):
|
def action(self, name, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Delegates which method to be called for a desired action.
|
Delegates which method to be called for a desired action.
|
||||||
@@ -37,6 +39,7 @@ class Command(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
Abstract Command class as part of the Command pattern.
|
Abstract Command class as part of the Command pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, receiver):
|
def __init__(self, receiver):
|
||||||
"""
|
"""
|
||||||
Initialize a new command instance.
|
Initialize a new command instance.
|
||||||
@@ -65,6 +68,7 @@ class Invoker(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
Abstract Invoker class as part of the Command pattern.
|
Abstract Invoker class as part of the Command pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, valid_commands):
|
def __init__(self, valid_commands):
|
||||||
"""
|
"""
|
||||||
Initialize a new Invoker instance.
|
Initialize a new Invoker instance.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Director(object, metaclass=ABCMeta):
|
|||||||
|
|
||||||
Part of the builder pattern.
|
Part of the builder pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialize a new Director.
|
Initialize a new Director.
|
||||||
@@ -39,6 +40,7 @@ class Builder(object):
|
|||||||
|
|
||||||
Part of the builder pattern.
|
Part of the builder pattern.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, constructed_object):
|
def __init__(self, constructed_object):
|
||||||
"""
|
"""
|
||||||
Initialize a new Builder.
|
Initialize a new Builder.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Factory(object, metaclass=ABCMeta):
|
|||||||
|
|
||||||
All Factories should inherit this class and overwrite the create method.
|
All Factories should inherit this class and overwrite the create method.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create(self, **kwargs):
|
def create(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -23,6 +24,7 @@ class AbstractFactory(object):
|
|||||||
"""
|
"""
|
||||||
Abstract Factory Class.
|
Abstract Factory Class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialize the abstract factory.
|
Initialize the abstract factory.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class Reusable(object):
|
|||||||
"""
|
"""
|
||||||
An abstract reusable class.
|
An abstract reusable class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialize a new Reusable instance.
|
Initialize a new Reusable instance.
|
||||||
@@ -24,6 +25,7 @@ class Pool(object, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
An Object Pool design pattern implementation.
|
An Object Pool design pattern implementation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, reusable_class, *args, **kwargs):
|
def __init__(self, reusable_class, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize a new object pool instance.
|
Initialize a new object pool instance.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class Prototype(object):
|
|||||||
"""
|
"""
|
||||||
Prototype design pattern abstract class.
|
Prototype design pattern abstract class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def copy(self, **attributes):
|
def copy(self, **attributes):
|
||||||
"""
|
"""
|
||||||
Copy this object and optionally update attributes.
|
Copy this object and optionally update attributes.
|
||||||
@@ -21,6 +22,3 @@ class Prototype(object):
|
|||||||
setattr(obj, attribute, attributes[attribute])
|
setattr(obj, attribute, attributes[attribute])
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from pypatterns.behavioral.chain import ChainException, ChainLink, Chain
|
from pypatterns.behavioral.chain import ChainException, ChainLink, Chain
|
||||||
|
|
||||||
|
|
||||||
@@ -6,10 +7,12 @@ class ChainLinkTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the ChainLink class.
|
Unit testing class for the ChainLink class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class ConcreteChainLinkThree(ChainLink):
|
class ConcreteChainLinkThree(ChainLink):
|
||||||
|
|
||||||
def handle(self, request):
|
def handle(self, request):
|
||||||
@@ -71,10 +74,12 @@ class ChainTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Chain class.
|
Unit testing class for the Chain class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class ConcreteChainLinkThree(ChainLink):
|
class ConcreteChainLinkThree(ChainLink):
|
||||||
|
|
||||||
def handle(self, request):
|
def handle(self, request):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from pypatterns.behavioral.command import InvalidActionException, InvalidInvokerCommandException, \
|
from pypatterns.behavioral.command import InvalidActionException, InvalidInvokerCommandException, \
|
||||||
Receiver, Command, Invoker
|
Receiver, Command, Invoker
|
||||||
|
|
||||||
@@ -7,12 +8,13 @@ class ReceiverTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Receiver class.
|
Unit testing class for the Receiver class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
class Thermostat(Receiver):
|
|
||||||
|
|
||||||
|
class Thermostat(Receiver):
|
||||||
def raise_temp(self, amount):
|
def raise_temp(self, amount):
|
||||||
return "Temperature raised by {0} degrees".format(amount)
|
return "Temperature raised by {0} degrees".format(amount)
|
||||||
|
|
||||||
@@ -44,10 +46,12 @@ class CommandTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Command class.
|
Unit testing class for the Command class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Thermostat(Receiver):
|
class Thermostat(Receiver):
|
||||||
def raise_temp(self, amount):
|
def raise_temp(self, amount):
|
||||||
return "Temperature raised by {0} degrees".format(amount)
|
return "Temperature raised by {0} degrees".format(amount)
|
||||||
@@ -56,7 +60,6 @@ class CommandTestCase(TestCase):
|
|||||||
return "Temperature lowered by {0} degrees".format(amount)
|
return "Temperature lowered by {0} degrees".format(amount)
|
||||||
|
|
||||||
class RaiseTempCommand(Command):
|
class RaiseTempCommand(Command):
|
||||||
|
|
||||||
def __init__(self, receiver, amount=5):
|
def __init__(self, receiver, amount=5):
|
||||||
super().__init__(receiver)
|
super().__init__(receiver)
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
@@ -68,7 +71,6 @@ class CommandTestCase(TestCase):
|
|||||||
return self._receiver.action('lower_temp', self.amount)
|
return self._receiver.action('lower_temp', self.amount)
|
||||||
|
|
||||||
class LowerTempCommand(Command):
|
class LowerTempCommand(Command):
|
||||||
|
|
||||||
def __init__(self, receiver, amount=5):
|
def __init__(self, receiver, amount=5):
|
||||||
super().__init__(receiver)
|
super().__init__(receiver)
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
@@ -100,10 +102,12 @@ class InvokerTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Invoker class.
|
Unit testing class for the Invoker class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Thermostat(Receiver):
|
class Thermostat(Receiver):
|
||||||
def raise_temp(self, amount):
|
def raise_temp(self, amount):
|
||||||
return "Temperature raised by {0} degrees".format(amount)
|
return "Temperature raised by {0} degrees".format(amount)
|
||||||
@@ -134,7 +138,6 @@ class InvokerTestCase(TestCase):
|
|||||||
return self._receiver.action('raise_temp', self.amount)
|
return self._receiver.action('raise_temp', self.amount)
|
||||||
|
|
||||||
class Worker(Invoker):
|
class Worker(Invoker):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__([LowerTempCommand, RaiseTempCommand])
|
super().__init__([LowerTempCommand, RaiseTempCommand])
|
||||||
|
|
||||||
@@ -158,8 +161,8 @@ class InvokerTestCase(TestCase):
|
|||||||
|
|
||||||
@raise AssertionError: If the test fails.
|
@raise AssertionError: If the test fails.
|
||||||
"""
|
"""
|
||||||
class Light(Receiver):
|
|
||||||
|
|
||||||
|
class Light(Receiver):
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
return "Light turned on"
|
return "Light turned on"
|
||||||
|
|
||||||
@@ -167,7 +170,6 @@ class InvokerTestCase(TestCase):
|
|||||||
return "Light turned off"
|
return "Light turned off"
|
||||||
|
|
||||||
class TurnOnLightCommand(Command):
|
class TurnOnLightCommand(Command):
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
return self._receiver.action('turn_on')
|
return self._receiver.action('turn_on')
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from pypatterns.creational.builder import Director, Builder
|
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
from pypatterns.creational.builder import Director, Builder
|
||||||
|
|
||||||
|
|
||||||
class BuilderTestCase(TestCase):
|
class BuilderTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
Unit testing class for the Builder class.
|
Unit testing class for the Builder class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Building(object):
|
class Building(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.floor = None
|
self.floor = None
|
||||||
@@ -20,7 +23,6 @@ class BuilderTestCase(TestCase):
|
|||||||
return 'Floor: {0.floor} | Size: {0.size}'.format(self)
|
return 'Floor: {0.floor} | Size: {0.size}'.format(self)
|
||||||
|
|
||||||
class HomeBuilder(Builder, metaclass=ABCMeta):
|
class HomeBuilder(Builder, metaclass=ABCMeta):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(Building())
|
super().__init__(Building())
|
||||||
self._register('floor', self._build_floor)
|
self._register('floor', self._build_floor)
|
||||||
@@ -35,7 +37,6 @@ class BuilderTestCase(TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class HouseBuilder(HomeBuilder):
|
class HouseBuilder(HomeBuilder):
|
||||||
|
|
||||||
def _build_floor(self):
|
def _build_floor(self):
|
||||||
self.constructed_object.floor = 'One'
|
self.constructed_object.floor = 'One'
|
||||||
|
|
||||||
@@ -43,7 +44,6 @@ class BuilderTestCase(TestCase):
|
|||||||
self.constructed_object.size = 'Big'
|
self.constructed_object.size = 'Big'
|
||||||
|
|
||||||
class FlatBuilder(HomeBuilder):
|
class FlatBuilder(HomeBuilder):
|
||||||
|
|
||||||
def _build_floor(self):
|
def _build_floor(self):
|
||||||
self.constructed_object.floor = 'More than one'
|
self.constructed_object.floor = 'More than one'
|
||||||
|
|
||||||
@@ -76,10 +76,12 @@ class DirectorTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Director class
|
Unit testing class for the Director class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Building(object):
|
class Building(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.floor = None
|
self.floor = None
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from pypatterns.creational.factory import Factory, AbstractFactory
|
from pypatterns.creational.factory import Factory, AbstractFactory
|
||||||
|
|
||||||
|
|
||||||
@@ -6,27 +7,25 @@ class FactoryTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Factory class.
|
Unit testing class for the Factory class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
class Cat(object):
|
|
||||||
|
|
||||||
|
class Cat(object):
|
||||||
def speak(self):
|
def speak(self):
|
||||||
return 'Meow'
|
return 'Meow'
|
||||||
|
|
||||||
class Dog(object):
|
class Dog(object):
|
||||||
|
|
||||||
def speak(self):
|
def speak(self):
|
||||||
return 'Woof'
|
return 'Woof'
|
||||||
|
|
||||||
class CatFactory(Factory):
|
class CatFactory(Factory):
|
||||||
|
|
||||||
def create(self, **kwargs):
|
def create(self, **kwargs):
|
||||||
return Cat()
|
return Cat()
|
||||||
|
|
||||||
class DogFactory(Factory):
|
class DogFactory(Factory):
|
||||||
|
|
||||||
def create(self, **kwargs):
|
def create(self, **kwargs):
|
||||||
return Dog()
|
return Dog()
|
||||||
|
|
||||||
@@ -55,10 +54,12 @@ class AbstractFactoryTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the AbstractFactory class.
|
Unit testing class for the AbstractFactory class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Cat(object):
|
class Cat(object):
|
||||||
def speak(self):
|
def speak(self):
|
||||||
return 'Meow'
|
return 'Meow'
|
||||||
@@ -76,7 +77,6 @@ class AbstractFactoryTestCase(TestCase):
|
|||||||
return Dog()
|
return Dog()
|
||||||
|
|
||||||
class AnimalFactory(AbstractFactory):
|
class AnimalFactory(AbstractFactory):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._register('cat', CatFactory)
|
self._register('cat', CatFactory)
|
||||||
@@ -103,4 +103,3 @@ class AbstractFactoryTestCase(TestCase):
|
|||||||
|
|
||||||
self.assertEquals('Meow', cat.speak())
|
self.assertEquals('Meow', cat.speak())
|
||||||
self.assertEquals('Woof', dog.speak())
|
self.assertEquals('Woof', dog.speak())
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from copy import deepcopy
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
from pypatterns.creational.pool import Reusable, Pool
|
from pypatterns.creational.pool import Reusable, Pool
|
||||||
|
|
||||||
|
|
||||||
@@ -7,12 +8,13 @@ class ReusableTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the reusable class.
|
Unit testing class for the reusable class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
class Dog(Reusable):
|
|
||||||
|
|
||||||
|
class Dog(Reusable):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sound = "woof"
|
self.sound = "woof"
|
||||||
super(Dog, self).__init__()
|
super(Dog, self).__init__()
|
||||||
@@ -52,19 +54,19 @@ class PoolTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Pool class.
|
Unit testing class for the Pool class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
class Dog(Reusable):
|
|
||||||
|
|
||||||
|
class Dog(Reusable):
|
||||||
def __init__(self, sound, name):
|
def __init__(self, sound, name):
|
||||||
self.sound = sound
|
self.sound = sound
|
||||||
self.name = name
|
self.name = name
|
||||||
super(Dog, self).__init__()
|
super(Dog, self).__init__()
|
||||||
|
|
||||||
class DogPool(Pool):
|
class DogPool(Pool):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DogPool, self).__init__(Dog, 'woof', 'george')
|
super(DogPool, self).__init__(Dog, 'woof', 'george')
|
||||||
|
|
||||||
@@ -118,14 +120,12 @@ class PoolTestCase(TestCase):
|
|||||||
dog_pool_two = self.dog_pool_class()
|
dog_pool_two = self.dog_pool_class()
|
||||||
|
|
||||||
class Cat(Reusable):
|
class Cat(Reusable):
|
||||||
|
|
||||||
def __init__(self, sound, name):
|
def __init__(self, sound, name):
|
||||||
self.sound = sound
|
self.sound = sound
|
||||||
self.name = name
|
self.name = name
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
class CatPool(Pool):
|
class CatPool(Pool):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(Cat, 'meow', 'tom')
|
super().__init__(Cat, 'meow', 'tom')
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from math import sqrt
|
from math import sqrt
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from pypatterns.creational.prototype import Prototype
|
from pypatterns.creational.prototype import Prototype
|
||||||
|
|
||||||
|
|
||||||
@@ -7,12 +8,13 @@ class PrototypeTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
Unit testing class for the Prototype class.
|
Unit testing class for the Prototype class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Initialize testing data.
|
Initialize testing data.
|
||||||
"""
|
"""
|
||||||
class Point(Prototype):
|
|
||||||
|
|
||||||
|
class Point(Prototype):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
@@ -87,7 +89,7 @@ class PrototypeTestCase(TestCase):
|
|||||||
point_one = self.__point_class(20, 25)
|
point_one = self.__point_class(20, 25)
|
||||||
|
|
||||||
def distance_to(this, other):
|
def distance_to(this, other):
|
||||||
return sqrt((this.x - other.x)**2 + (this.y - other.y)**2)
|
return sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2)
|
||||||
|
|
||||||
point_two = point_one.copy(distance_to=distance_to)
|
point_two = point_one.copy(distance_to=distance_to)
|
||||||
point_three = point_two.copy()
|
point_three = point_two.copy()
|
||||||
@@ -97,7 +99,3 @@ class PrototypeTestCase(TestCase):
|
|||||||
self.assertEquals(point_two.distance_to(point_one), 0)
|
self.assertEquals(point_two.distance_to(point_one), 0)
|
||||||
self.assertTrue(hasattr(point_three, 'distance_to'))
|
self.assertTrue(hasattr(point_three, 'distance_to'))
|
||||||
self.assertEquals(point_three.distance_to(point_two), 0)
|
self.assertEquals(point_three.distance_to(point_two), 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from abc import ABCMeta, ABC
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from abc import ABCMeta, ABC
|
||||||
from tests.utils.dummy import dummy_class_factory
|
from tests.utils.dummy import dummy_class_factory
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user