Beispiel #1
0
def check_assignment(assignment: Assignment,
                     baseline: Assignment) -> Tuple[int, List[str]]:
    def check(a: Assignment):
        return list(map(execute_with_output, a.create_checks()))

    def change_result_to_mandatory(r: CheckResult):
        return CheckResult(r.result, r.msg, r.output, r.warning,
                           r.should_succeed, r.command, True)

    if assignment != baseline:
        baseline_results = list(
            map(change_result_to_mandatory, check(baseline)))
    else:
        baseline_results = []

    set_assignment_name(assignment.category)

    print_message('executing test \'{}\''.format(assignment.name))

    results = baseline_results + check(assignment)

    set_assignment_name('')

    (grade_value, reasons) = grade(results)

    for reason in reasons:
        print_warning(reason)

    print_grade(grade_value)
Beispiel #2
0
def grade():
    global results

    if len(results) == 0:
        return

    mandatory_tests = list(filter(lambda x: x[2], results))
    normal_tests = list(filter(lambda x: not x[2], results))

    number_of_tests = len(results) - len(mandatory_tests)
    number_of_tests_passed = len(
        list(filter(lambda x: x[0] == x[1], normal_tests)))
    number_of_positive_tests_passed = len(
        list(filter(lambda x: x[0] and x[1], normal_tests)))

    failed_mandatory_test = any(filter(lambda x: x[0] != x[1],
                                       mandatory_tests))

    if number_of_tests_passed == 0:
        passed = 0.0
    else:
        passed = number_of_tests_passed / float(number_of_tests)

    if failed_mandatory_test or number_of_positive_tests_passed == 0:
        if failed_mandatory_test:
            print_warning('you have failed a mandatory test')
        if number_of_positive_tests_passed == 0:
            print_warning(
                'warning: you have not passed at least one positive test')

        grade = 5
    elif passed == 1.0:
        grade = 2
    elif passed >= 0.5:
        grade = 3
    elif passed > 0.0:
        grade = 4
    else:
        grade = 5

    print_grade(grade)

    results = []