def build_match_function(*, compare_mode: CompareMode, error: Optional[float], judge_command: Optional[str], silent: bool, test_input_path: pathlib.Path, test_output_path: Optional[pathlib.Path]) -> Callable[[bytes, bytes], bool]: """build_match_function builds the function to compare actual outputs and expected outputs. This function doesn't any I/O. """ if judge_command is not None: special_judge = output_comparators.SpecialJudge(judge_command=judge_command, is_silent=silent) def run_judge_command(actual: bytes, expected: bytes) -> bool: # the second argument is ignored return special_judge.run( actual_output=actual, input_path=test_input_path, expected_output_path=test_output_path, ) return run_judge_command is_exact = False if compare_mode == CompareMode.EXACT_MATCH and error is None: is_exact = True file_comparator: output_comparators.OutputComparator = output_comparators.ExactComparator() elif compare_mode == CompareMode.CRLF_INSENSITIVE_EXACT_MATCH and error is None: is_exact = True file_comparator = output_comparators.CRLFInsensitiveComparator(output_comparators.ExactComparator()) else: if error is not None: word_comparator: output_comparators.OutputComparator = output_comparators.FloatingPointNumberComparator(rel_tol=error, abs_tol=error) else: word_comparator = output_comparators.ExactComparator() if compare_mode in (CompareMode.EXACT_MATCH, CompareMode.CRLF_INSENSITIVE_EXACT_MATCH, CompareMode.IGNORE_SPACES): file_comparator = output_comparators.SplitLinesComparator(output_comparators.SplitComparator(word_comparator)) elif compare_mode == CompareMode.IGNORE_SPACES_AND_NEWLINES: file_comparator = output_comparators.SplitComparator(word_comparator) else: assert False file_comparator = output_comparators.CRLFInsensitiveComparator(file_comparator) def compare_outputs(actual: bytes, expected: bytes) -> bool: result = file_comparator(actual, expected) if not result and is_exact: non_stcict_comparator = output_comparators.CRLFInsensitiveComparator(output_comparators.SplitComparator(output_comparators.ExactComparator())) if non_stcict_comparator(actual, expected): logger.warning('This was AC if spaces and newlines were ignored. Please use --ignore-spaces (-S) option or --ignore-spaces-and-newline (-N) option.') return result return compare_outputs
def compare_outputs(actual: bytes, expected: bytes) -> bool: result = file_comparator(actual, expected) if not result and is_exact: non_stcict_comparator = output_comparators.CRLFInsensitiveComparator(output_comparators.SplitComparator(output_comparators.ExactComparator())) if non_stcict_comparator(actual, expected): logger.warning('This was AC if spaces and newlines were ignored. Please use --ignore-spaces (-S) option or --ignore-spaces-and-newline (-N) option.') return result