def match_result(self, other): return MatchResult([ MatchVariant([ Isomorphic(target=self.concrete_element(), pattern=other.concrete_element()), Isomorphic(target=self.concrete_visitor(), pattern=other.concrete_visitor()), Isomorphic(target=self.element(), pattern=other.element()), Isomorphic(target=self.visitor(), pattern=other.visitor()), Isomorphic(target=self.visitor_visit(), pattern=other.visitor_visit()), Isomorphic(target=self.concrete_visitor_visit(), pattern=other.concrete_visitor_visit()), Isomorphic(target=self.element_accept(), pattern=other.element_accept()), Isomorphic(target=self.concrete_element_accept(), pattern=other.concrete_element_accept()), Isomorphic(target=self.visitor_type(), pattern=other.visitor_type()), Isomorphic(target=self.concrete_element_type(), pattern=other.concrete_element_type()), Isomorphic(target=self.visitor_visit_concrete_element(), pattern=other.visitor_visit_concrete_element()), Isomorphic( target=self.concrete_visitor_visit_concrete_element(), pattern=other.concrete_visitor_visit_concrete_element(), ), Isomorphic(target=self.element_accept_visitor(), pattern=other.element_accept_visitor()), Isomorphic(target=self.concrete_element_accept_visitor(), pattern=other.concrete_element_accept_visitor()), ]) ])
def test_make_not_empty_should_succeed(self): match_result = MatchResult([ MatchVariant([Isomorphic(Class('A'), Class('B'))]), MatchVariant([ Isomorphic(Class('C'), Class('D')), Isomorphic(Class('E'), Class('F')), ]), ]) assert_that( str(match_result), equal_to('class A === class B\n' '\n' 'class C === class D\n' 'class E === class F')) assert_that( repr(match_result), equal_to("MatchResult([\n" "MatchVariant([\n" "Isomorphic(Class('A'), Class('B'))\n" "]),\n" "MatchVariant([\n" "Isomorphic(Class('C'), Class('D')),\n" "Isomorphic(Class('E'), Class('F'))\n" "])\n" "])")) assert_that(len(match_result), equal_to(2))
def match_result(self, other): return MatchResult([ MatchVariant([ Isomorphic(target=self.abstract_factory(), pattern=other.abstract_factory()), Isomorphic(target=self.concrete_factory(), pattern=other.concrete_factory()), Isomorphic(target=self.abstract_product(), pattern=other.abstract_product()), Isomorphic(target=self.concrete_product(), pattern=other.concrete_product()), Isomorphic(target=self.abstract_factory_create(), pattern=other.abstract_factory_create()), Isomorphic(target=self.concrete_factory_create(), pattern=other.concrete_factory_create()), Isomorphic(target=self.abstract_product_type(), pattern=other.abstract_product_type()), ]) ])
def test_match_abstract_factory_pattern_in_bukkit_example(self): t = BukkitExample() p = AbstractFactory() expected_match_result = MatchResult([ MatchVariant([ Isomorphic(t.command(), p.abstract_factory()), Isomorphic(t.command_sender(), p.abstract_product()), Isomorphic(t.console_command_sender(), p.concrete_product()), Isomorphic(t.plugin_command(), p.concrete_factory()), Isomorphic(t.command_create(), p.abstract_factory_create()), Isomorphic(t.plugin_command_create(), p.concrete_factory_create()), Isomorphic(t.command_sender_type(), p.abstract_product_type()) ]), MatchVariant([ Isomorphic(t.command(), p.abstract_factory()), Isomorphic(t.command_sender(), p.abstract_product()), Isomorphic(t.console_command_sender(), p.concrete_product()), Isomorphic(t.formatted_command_alias(), p.concrete_factory()), Isomorphic(t.command_create(), p.abstract_factory_create()), Isomorphic(t.formatted_command_alias_create(), p.concrete_factory_create()), Isomorphic(t.command_sender_type(), p.abstract_product_type()) ]), ]) assert_that(t.command().equiv_pattern(p.abstract_factory())) assert_that(t.command_create().equiv_pattern( p.abstract_factory_create())) assert_that(t.command_sender().equiv_pattern(p.abstract_product())) assert_that(t.command_sender_type().equiv_pattern( p.abstract_product_type())) assert_that(t.console_command_sender().equiv_pattern( p.concrete_product())) assert_that(t.formatted_command_alias().equiv_pattern( p.concrete_factory())) assert_that(t.formatted_command_alias_create().equiv_pattern( p.concrete_factory_create())) assert_that(t.plugin_command().equiv_pattern(p.concrete_factory())) assert_that(t.plugin_command_create().equiv_pattern( p.concrete_factory_create())) match_result = t.create().match(p.create()) assert_that(match_result, equal_to(expected_match_result))
def test_match_decorator_pattern_in_burgers_limit_one(self): t = Burgers() p = Decorator() expected_match_result = MatchResult([ MatchVariant([ Isomorphic(t.burger(), p.component()), Isomorphic(t.burger_with(), p.decorator()), Isomorphic(t.cheese(), p.concrete_decorator()), Isomorphic(t.cheeseburger(), p.concrete_component()), Isomorphic(t.burger_with_burger(), p.decorator_component()), Isomorphic(t.burger_price(), p.component_operation()), Isomorphic(t.burger_with_price(), p.decorator_operation()), Isomorphic(t.cheese_price(), p.concrete_decorator_operation()), Isomorphic(t.cheeseburger_price(), p.concrete_component_operation()), Isomorphic(t.burger_type(), p.component_type()), ]), ]) match_result = t.create().match(p.create(), 1) assert_that(match_result, equal_to(expected_match_result))
def match_result(self, other): return MatchResult([ MatchVariant([ Isomorphic(target=self.component(), pattern=other.component()), Isomorphic(target=self.concrete_component(), pattern=other.concrete_component()), Isomorphic(target=self.decorator(), pattern=other.decorator()), Isomorphic(target=self.concrete_decorator(), pattern=other.concrete_decorator()), Isomorphic(target=self.decorator_component(), pattern=other.decorator_component()), Isomorphic(target=self.component_operation(), pattern=other.component_operation()), Isomorphic(target=self.decorator_operation(), pattern=other.decorator_operation()), Isomorphic(target=self.concrete_component_operation(), pattern=other.concrete_component_operation()), Isomorphic(target=self.concrete_component_operation(), pattern=other.concrete_component_operation()), Isomorphic(target=self.component_type(), pattern=other.component_type()), ]) ])
def test_match_empty_should_has_empty_match_result(self): assert_that(Model().match(Model()), equal_to(MatchResult()))
def test_make_empty_should_succeed(self): match_result = MatchResult() assert_that(str(match_result), equal_to('')) assert_that(repr(match_result), equal_to('MatchResult()')) assert_that(len(match_result), equal_to(0))