示例#1
0
def test__judge_program__ac():
    c = get_command("tests/solutions/ac_tester.py")
    r = judge_program(c, [([""], [""]) for _ in range(tc)],
                      time_limit=tl,
                      memory_limit=ml)
    assert r.verdict == judge.ANSWER_CORRECT
    assert r.passed == r.total == tc
    assert r.maximum_memory <= MEBIBYTE * ml
    assert r.maximum_time <= 1000 * tl
示例#2
0
def test__judge_program__tle():
    c = get_command("tests/solutions/tle_tester.py")
    r = judge_program(c, [([""], [""]) for _ in range(tc)],
                      time_limit=tl,
                      memory_limit=ml)
    assert r.verdict == judge.TIME_LIMIT_EXCEEDED
    assert r.passed == 0
    assert r.total == tc
    assert r.maximum_memory <= MEBIBYTE * ml
    assert r.maximum_time > 1000 * tl
示例#3
0
def test__judge_program__rte():
    c = get_command("tests/solutions/rte_tester.py")
    r = judge_program(c, [([""], [""]) for _ in range(tc)],
                      time_limit=tl,
                      memory_limit=ml)
    assert r.verdict == judge.RUNTIME_ERROR
    assert r.passed == 0
    assert r.total == tc
    assert r.maximum_memory <= MEBIBYTE * ml
    assert r.maximum_time <= 1000 * tl
示例#4
0
def main():
    parser = argparse.ArgumentParser(description="Test your programs.")
    parser.add_argument(
        "exercise_name", action="store", nargs="?", type=str,
        help="the name of the exercise to test your program for.")
    parser.add_argument(
        "program_path", action="store", nargs="?", type=str,
        help="the path to the program to test.")
    parser.add_argument(
        "-l", "--list_exercises", action="store_true",
        help="display a list of all the exercises.", dest="list_exercises")
    parser.add_argument(
        "-s", "--see_description", action="store_true",
        help="display the description for the given exercise.", dest="see_description")
    parser.add_argument(
        "-e", "--exercises_location", action="store", default=DEFAULT_EXERCISES,
        help="set the base directory of the exercises.", dest="exercises_location")
    parser.add_argument(
        "-m", "--manual_command", action="store_true",
        help="enable this flag if you are entering the full command to run your program under "
             "`program_path` (instead of just the file name).", dest="manual_command")
    arguments = parser.parse_args()

    if arguments.list_exercises:
        lessons_list = exercise.list_exercises(arguments.exercises_location)
        lessons_list = [f"  тоб {lesson_name}" for lesson_name in lessons_list]

        display.display(f"Found {len(lessons_list)} lessons:")
        display.display("\n".join(lessons_list))
        sys.exit(0)

    if arguments.see_description:
        if arguments.exercise_name is None:
            raise AssertionError("no exercise name was specified")

        display.display(exercise.get_description(
            arguments.exercises_location, arguments.exercise_name
        ))
        sys.exit(0)

    if arguments.exercise_name is None or arguments.program_path is None:
        parser.print_help()

        missing_value = "exercise_name" if arguments.exercise_name is None else "program_path"
        raise AssertionError(f"the argument `{missing_value}` is missing")

    program_command = arguments.program_path
    if not arguments.manual_command:
        if not os.path.isfile(arguments.program_path):
            raise AssertionError(f"the file `{arguments.program_path}` does not exist")
        program_command = command.get_command(arguments.program_path)

    specifications = exercise.get_specs(arguments.exercises_location, arguments.exercise_name)

    display.d_exercise_specs(**specifications)
    result = judge.judge_program(
        program_command,
        **specifications,
        progress_hook=display.d_progress_hook
    )
    display.d_judging_summary(result)