def test_elim_chains(self): eliminated_b = cnf.chain_elim(self.grammar.rules) for values in eliminated_b.values(): for val in values: self.assertFalse(val.isupper() and len(val) == 1, ERRMSG_CHAIN) print("eliminated_ all occurrences of chained rules:") print_grammar(eliminated_b)
def test_elim_long_right(self): self.grammar.rules = cnf.epsilon_elim(self.grammar.start, self.grammar.rules) print_grammar(self.grammar.rules) self.grammar.rules = cnf.chain_elim(self.grammar.rules) print_grammar(self.grammar.rules) self.grammar.rules = cnf.non_iso_term_elim(self.grammar.rules, self.grammar.variables, self.grammar.alphabet) if isinstance(self.grammar.rules, tuple): print_grammar(self.grammar.rules[0]) shorted_d = cnf.long_right_elim(self.grammar.rules[0], self.grammar.alphabet) for value in shorted_d.values(): for val in value: self.assertIsNot(len(val), 3 or 4 or 5, ERRMSG_LONG_RIGHT) else: print_grammar(self.grammar.rules) shorted_d = cnf.long_right_elim(self.grammar.rules, self.grammar.alphabet) for value in shorted_d.values(): for val in value: self.assertIsNot(len(val), 3 or 4 or 5, ERRMSG_LONG_RIGHT) print("successfully eliminated_ long right sides for TEST_A: ") print_grammar(shorted_d)
def test_epsilon_elim(self): self.grammar.rules = cnf.chain_elim(self.grammar.rules) eliminated_e = cnf.epsilon_elim(self.grammar.start, self.grammar.rules) for key, val in eliminated_e.items(): if key is not self.grammar.start: self.assertNotIn(r'\E', val, ERRMSG_ELIM) print("eliminated_ all occurrences of epsilon:") print_grammar(eliminated_e)