def test_match_with_one_explicit_labeled_arc_should_succeed(self): first = Graph({Red(1, 2)}) second = Graph({Red('a', 'b')}) first_variants = to_list(replace_node_by_obj(match(first, second))) assert_that(first_variants, equal_to([[(1, 'a'), (2, 'b')]])) second_variants = to_list(replace_node_by_obj(match(second, first))) assert_that(second_variants, equal_to([[('a', 1), ('b', 2)]]))
def test_make_complex_should_succeed(self): graph = Graph([Red(1, 2), (1, 2), Blue(2, 4), Blue(3, 2), (4, 3)]) assert_that(replace_node_by_obj(graph.nodes), equal_to({1, 2, 3, 4})) assert_that(repr(graph), equal_to('[1] ---> 2' '\n' '[1] -Red-> 2' '\n' '[2] -Blue-> 4' '\n' '[3] -Blue-> 2' '\n' '[4] ---> 3')) assert_that(graph.connections_types, equal_to({tuple, Red, Blue}))
def test_with_one_labeled_arc(self): graph = Graph([Red(1, 2)]) assert_that(graph.as_dot().to_string(), equal_to( 'digraph Model {\n' '"1" [shape=box];\n' '"1" -> "2" [label=Red];\n' '"2" [shape=box];\n' '}\n' ))
def test_check_current_isomorphism_before_add_to_visited(self): target = Graph({ Red(1, 3), Red(1, 4), Red(2, 3), Blue(5, 4), Blue(6, 3), Blue(2, 4), }) pattern = Graph({ Red('a', 'b'), Red('a', 'c'), Blue('d', 'b'), Blue('e', 'c'), }) variants = to_list(replace_node_by_obj(match(target, pattern))) assert_that( variants, equal_to([ [(1, 'a'), (2, 'd'), (3, 'c'), (4, 'b'), (6, 'e')], [(1, 'a'), (3, 'c'), (4, 'b'), (5, 'd'), (6, 'e')], [(1, 'a'), (2, 'e'), (3, 'b'), (4, 'c'), (6, 'd')], [(1, 'a'), (3, 'b'), (4, 'c'), (5, 'e'), (6, 'd')], ]))
def test_two_twice_labeled_connected_should_succeed(self): assert_that(get_connected_components(Graph([Red(1, 2), Blue(1, 2)])), equal_to([{1, 2}]))
def test_make_one_node_and_one_labeled_arc_should_succeed(self): graph = Graph({1, Red(2, 3)}) assert_that(replace_node_by_obj(graph.nodes), equal_to({1, 2, 3})) assert_that(repr(graph), equal_to('[1]' '\n' '[2] -Red-> 3')) assert_that(graph.connections_types, equal_to({Red}))
def test_make_self_connected_by_labeled_arc_node_should_succeed(self): graph = Graph({Red(1, 1)}) assert_that(replace_node_by_obj(graph.nodes), equal_to({1})) assert_that(repr(graph), equal_to('[1] * Red')) assert_that(graph.connections_types, equal_to({Red}))
def test_make_with_one_labeled_arc_should_succeed(self): graph = Graph({Red(1, 2)}) assert_that(replace_node_by_obj(graph.nodes), equal_to({1, 2})) assert_that(repr(graph), equal_to('[1] -Red-> 2'))
def test_match_with_one_different_labeled_arcs_should_be_empty_result( self): first = Graph({Red(1, 2)}) second = Graph({Blue('a', 'b')}) variants = to_list(replace_node_by_obj(match(first, second))) assert_that(variants, empty())