def test_8(self): gate = SeqGate() gate.parse( 'xor({f}{d}and({e}xor(lop(xor({f}{d}))lop({a}))))and({b}{a})') all_length_3_routes = gate.get_all_n_length_routes(3) self.assertCountEqual([ EventGroupMatcher( EventGroup( [Event('f'), EventGroupParallel(string_to_events('ba'))])), EventGroupMatcher( EventGroup( [Event('d'), EventGroupParallel(string_to_events('ba'))])), EventGroupMatcher( EventGroup( [Event('e'), EventGroupParallel(string_to_events('ba'))])) ], all_length_3_routes)
def test_get_next_possible_states_9_4(self): gate = SeqGate() gate.parse( 'seq({a})xor({b}{f}{c}){d}and(xor({h}xor(and(xor(and({c})))lo0(xor({b}{f}{d}{g})))){e})opt({h})' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[0] e2 = keys[1] e3 = keys[4] e4 = keys[11] e5 = keys[12] actual = set( list(events_with_parents[e4].get_next_possible_states( (e1, e2, e3, e4), e4, e5))) self.assertEqual(7, len(actual))
def test_get_next_possible_states_9_7(self): gate = SeqGate() gate.parse( '{a}and(and(opt({e})seq(xor({d}{e}){b}))xor(opt({g})xor(xor({h}xor({f}{h}))xor({f}and(and({c}{h}){a})))))' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[0] e2 = keys[2] e3 = keys[4] e4 = keys[1] e5 = keys[6] actual = set( list(events_with_parents[e4].get_next_possible_states( (e1, e2, e3, e4), e4, e5))) self.assertEqual(8, len(actual))
def test_get_next_possible_states_9_1(self): gate = SeqGate() gate.parse( '{a}seq({b}and(opt(seq({d}){e})){h})xor({g}and(opt({a}))opt(opt(and({d}))xor(seq({c}){e}seq({e}){a})))' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[0] e2 = keys[1] e3 = keys[2] e4 = keys[8] e5 = keys[10] actual = set( list(events_with_parents[e4].get_next_possible_states( (e1, e2, e3, e4), e4, e5))) self.assertEqual(1, len(actual))
def test_get_next_possible_states_9_2(self): gate = SeqGate() gate.parse( '{a}xor(xor(xor({b})lo2({b}){b}){c}seq(and(and({b})){e})){d}opt(xor(and({e}opt(xor({h}{g})))){h}' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[0] e2 = keys[1] e3 = keys[2] e4 = keys[7] e5 = keys[9] actual = set( list(events_with_parents[e4].get_next_possible_states( (e1, e2, e3, e4), e4, e5))) self.assertEqual(4, len(actual))
def test_get_next_possible_states_6_6(self): gate = SeqGate() gate.parse( 'and(xor(opt(lop({f}))xor(and({e}{a}seq({c}{d})opt({g}{a}))and({b}{h}){g})' 'xor(xor(and({e}{a}seq({c}{d}))opt({b}))xor(xor(opt({c})lop({c}))seq({b}{d}))))opt({h}))' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[2] e2 = keys[3] e3 = keys[4] e4 = keys[1] e5 = keys[18] actual = set( list(events_with_parents[e4].get_next_possible_states( (e1, e2, e3, e4), e4, e5))) self.assertEqual(3, len(actual))
def test_get_next_possible_states_9_8(self): gate = SeqGate() gate.parse( '{a}xor({f}{b})opt(lo1(and({g}xor({f}{b})){d}){c}{d})and(seq({e}))' ) events_with_parents = gate.get_all_child_events_with_parents() keys = [x for x in events_with_parents.keys()] e1 = keys[0] e2 = keys[1] e3 = keys[8] e4 = keys[7] e5 = keys[3] e6 = keys[4] e7 = keys[6] e8 = keys[3] e9 = keys[4] actual = set( list(events_with_parents[e8].get_next_possible_states( (e1, e2, e3, e4, e5, e6, e7, e8), e8, e9))) self.assertEqual(2, len(actual))
def test_2(self): gate = SeqGate() gate.parse('{f}xor({d}and({b}lop({c})opt({a})))') actual = gate.get_all_n_length_routes(5) expected_1 = EventGroupMatcher( EventGroup([ Event('f'), EventGroupParallel( [Event('b'), EventGroup(string_to_events('ccc'))]) ])) expected_2 = EventGroupMatcher( EventGroup([ Event('f'), EventGroupParallel([ Event('b'), EventGroup(string_to_events('cc')), Event('a') ]) ])) expected = [expected_1, expected_2] self.assertCountEqual(expected, actual)
def test_count_repeating_if_seq_parent_3(self): gate = SeqGate() gate.parse('{a}{e}lop({f}and(xor({b}{c}){d}){e})xor({g}{h})') self.assertEqual(1, gate.elements[2].count_repeating_if_seq_parent())
def test_get_min_complexity_legend2(self): gate = SeqGate() gate.parse('{a}{c}{d}{e}{h}') self.assertEqual(1, gate.complexity) self.assertEqual(1, gate.complexity_for_metric)
def test_legend_3_1(self): gate = SeqGate() gate.parse('{a}lop(opt({b}{c}{d}{e}{f}))xor({g}{h})') all_length_5_routes = gate.get_all_n_length_routes( 5, ('a', 'c', 'e', 'd', 'h')) self.assertEqual(19100, len(all_length_5_routes))
def test_legend_1_2(self): gate = SeqGate() gate.parse('lop({f}and(xor({b}{c}){d}){e})') all_length_4_routes = gate.get_all_n_length_routes( 4, ('a', 'c', 'd', 'e', 'f', 'd', 'b', 'e', 'h')) self.assertEqual(2, len(all_length_4_routes))
def test_95(self): gate = SeqGate() gate.parse('lop(lop(seq(xor({d}{a})and(lop({c}){b})))and(lop({b}){e}))' 'opt(xor(seq({b}{d})lop(opt({f}xor({a}{d})))))') all_length_6_routes = gate.get_all_n_length_routes(6) self.assertEqual([], all_length_6_routes)
def test_93(self): gate = SeqGate() gate.parse('lop(xor(opt({f})seq({f}and(opt({a})lop({d})))))') all_length_3_routes = gate.get_all_n_length_routes(3) self.assertEqual(8, len(all_length_3_routes))