def assertAlgorithm(self, module, level, expected, dea, number): algo = ALGO_NAMES[level] #call algorithm witness = getattr(module, algo)(dea) msg1 = "#%d,%s: Witness should be equal to %s but was %s %s" % \ (number,algo, expected, valid_witness(witness), witness) if valid_witness(witness): try: check = checker[level] t = check(dea, witness) print(" -%s " % algo , end="") except Exception as e: msg2 = "#%d: Witness %s rejected by checker for %s" % \ (number, witness, algo) # raise AssertionError(msg2) from e raise AssertionError(msg2,e) else: print(" +%s " % algo , end="") if not (level == L32 and module == algorithms1): self.assertEqual(expected, valid_witness(witness), msg1);
def __call__(self, dea, witness): if not valid_witness(witness): return False for chck in self.call_checkers: chck(dea, witness) for checker in self.checks: checker(dea, witness) # False by Exception return True
if args.classes: algorithms = set(args.classes) else: algorithms = KNOWN_ALGORITHMS print_witnesses = args.witnesses verify_wintesses = args.witnesses alg_module = __import__(args.module) for fil in files: dea = dfa.DFA(fil) for algorithm in algorithms: witness = run(alg_module, algorithm, dea) if dfa.valid_witness(witness): print("File: %s ∉ %s" % (fil, algorithm)) if print_witnesses: print(" " * 4, end="") pprint(witness, indent=4) if verify_wintesses: import witnesscheck as wc if wc.CHECKERS[algorithm](dea, witness): print("witness passed", end="") else: print("witness failed", end="") print() else: print("File: %s ∈ %s" % (fil, algorithm)) print("-" * 80)