<commit_before>#!/usr/bin/env python3
"""
Copyright (c) the Selfie Project authors. All rights reserved.
Please see the AUTHORS file for details. Use of this source code is governed
by a BSD license that can be found in the LICENSE file.

Selfie is a project of the Computational Systems Group at the Department of
Computer Sciences of the University of Salzburg in Austria. For further
information and code please refer to:

http://selfie.cs.uni-salzburg.at

This is the automatic grader of the selfie system.
"""

import sys
from typing import Callable, Optional, List, Set, Tuple, Any
from lib.functional import flatmap
from lib.cli import process_arguments
from lib.model import Assignment, Check
from lib.output_processing import is_interleaved_output, is_permutation_of, contains_name
from lib.checks import (check_assembler_instruction_format, check_compilable,
                        check_compile_warnings, check_execution,
                        check_hypster_execution, check_interleaved_output,
                        check_mipster_execution, check_riscv_instruction, check_bootstrapping_compile_warnigns)
from lib.system import (AND_INSTRUCTION, LR_INSTRUCTION, NOT_INSTRUCTION,
                        OR_INSTRUCTION, SC_INSTRUCTION, SLL_INSTRUCTION,
                        SRL_INSTRUCTION)

REPO_BLOB_BASE_URI = 'https://github.com/cksystemsteaching/selfie/blob/main/'

def check_bootstrapping() -> List[Check]:
    return check_bootstrapping_compile_warnigns('bootstrapping works without warnings', mandatory=False)

def check_self_compilation(mandatory=False) -> List[Check]:
    return check_execution('make self', 'selfie compiles selfie.c', mandatory=mandatory) + \
        check_compile_warnings(
            'selfie.c', 'self-compilation does not lead to warnings or syntax errors', mandatory=mandatory)


def check_print_your_name() -> List[Check]:
    return check_execution('./selfie -c selfie.c -m 1',
                           'selfie prints first and second name',
                           success_criteria=lambda code, out: contains_name(out))


def check_hex_literal() -> List[Check]:
    return check_compilable('all-digit-characters.c',
                            'hex integer literal with all characters compiled') + \
        check_mipster_execution('all-digit-characters.c', 42,
                                'hex integer literal with all characters has the right value') + \
        check_compilable('max-value.c',
                         'maximum hex integer literal compiled') + \
        check_mipster_execution('max-value.c', 42,
                                'maximum hex integer literal has the right value') + \
        check_compilable('min-value.c',
                         'minimum hex integer literal compiled') + \
        check_mipster_execution('min-value.c', 42,
                                'minimum hex integer literal has the right value')


def check_bitwise_shift_compilation() -> List[Check]:
    def check_direction(direction: str) -> List[Check]:
        literal_file = direction + '-shift-with-literals.c'
        variable_file = direction + '-shift-with-variables.c'
        invalid_file = 'invalid-' + direction + '-shift.c'

        return check_compilable(literal_file, 'bitwise-' + direction +
                                '-shift operator with literals does compile') + \
            check_compilable(variable_file,
                             'bitwise-' + direction + '-shift operator with variables does compile') + \
            check_compilable(invalid_file,
                             'bitwise-' + direction + '-shift operator with invalid syntax does not compile', should_succeed=False)<commit_msg>Improve grading of print-your-name<commit_after>#!/usr/bin/env python3
"""
Copyright (c) the Selfie Project authors. All rights reserved.
Please see the AUTHORS file for details. Use of this source code is governed
by a BSD license that can be found in the LICENSE file.

Selfie is a project of the Computational Systems Group at the Department of
Computer Sciences of the University of Salzburg in Austria. For further
information and code please refer to:

http://selfie.cs.uni-salzburg.at

This is the automatic grader of the selfie system.
"""

import sys
from typing import Callable, Optional, List, Set, Tuple, Any
from lib.functional import flatmap
from lib.cli import process_arguments
from lib.model import Assignment, Check
from lib.output_processing import is_interleaved_output, is_permutation_of, contains_name
from lib.checks import (check_assembler_instruction_format, check_compilable,
                        check_compile_warnings, check_execution,
                        check_hypster_execution, check_interleaved_output,
                        check_mipster_execution, check_riscv_instruction, check_bootstrapping_compile_warnigns)
from lib.system import (AND_INSTRUCTION, LR_INSTRUCTION, NOT_INSTRUCTION,
                        OR_INSTRUCTION, SC_INSTRUCTION, SLL_INSTRUCTION,
                        SRL_INSTRUCTION)

REPO_BLOB_BASE_URI = 'https://github.com/cksystemsteaching/selfie/blob/main/'

def check_bootstrapping() -> List[Check]:
    return check_bootstrapping_compile_warnigns('bootstrapping works without warnings', mandatory=False)

def check_self_compilation(mandatory=False) -> List[Check]:
    return check_execution('make self', 'selfie compiles selfie.c', mandatory=mandatory) + \
        check_compile_warnings(
            'selfie.c', 'self-compilation does not lead to warnings or syntax errors', mandatory=mandatory)


def check_print_your_name() -> List[Check]:
    return check_execution('./selfie -c selfie.c',
                           'selfie prints first and second name',
                           success_criteria=lambda code, out: contains_name(out))


def check_hex_literal() -> List[Check]:
    return check_compilable('all-digit-characters.c',
                            'hex integer literal with all characters compiled') + \
        check_mipster_execution('all-digit-characters.c', 42,
                                'hex integer literal with all characters has the right value') + \
        check_compilable('max-value.c',
                         'maximum hex integer literal compiled') + \
        check_mipster_execution('max-value.c', 42,
                                'maximum hex integer literal has the right value') + \
        check_compilable('min-value.c',
                         'minimum hex integer literal compiled') + \
        check_mipster_execution('min-value.c', 42,
                                'minimum hex integer literal has the right value')


def check_bitwise_shift_compilation() -> List[Check]:
    def check_direction(direction: str) -> List[Check]:
        literal_file = direction + '-shift-with-literals.c'
        variable_file = direction + '-shift-with-variables.c'
        invalid_file = 'invalid-' + direction + '-shift.c'

        return check_compilable(literal_file, 'bitwise-' + direction +
                                '-shift operator with literals does compile') + \
            check_compilable(variable_file,
                             'bitwise-' + direction + '-shift operator with variables does compile') + \
            check_compilable(invalid_file,
                             'bitwise-' + direction + '-shift operator with invalid syntax does not compile', should_succeed=False)
{'fraction_non_alphanumeric': 0.08092407457443934, 'fraction_numerical': 0.002026479329910835, 'mean_word_length': 2.7257171615500755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '601514', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1926, 'n_words': 570}