def language_equivalence_automaton(student_answer, other, length):
    try:
        A = parse_pda(student_answer)
    except RuntimeError as e:
        return {'correct': False, 'feedback': str(e)}
    A_words = generate_language(A, length)
    B = parse_pda(other)
    B_words = generate_language(B, length)
    feedback = compare_languages(A_words, B_words)
    if len(feedback) == 0:
        return {'correct': True}
    else:
        return {'correct': False, 'feedback': " / ".join(feedback)}
Exemplo n.º 2
0
def state_count(student_answer, max_states):
    try:
        A = parse_pda(student_answer)
    except RuntimeError as e:
        return {'correct': False,
                'feedback': str(e)}
    num_states = len(A.Q)
    if num_states <= max_states:
        return {'correct': True}
    else:
        return {'correct': False,
                'feedback': "You used too many states (at most " +
                        str(max_states) + " allowed)"}
def language_equivalence_words(student_answer, word_list, length):
    word_list = " ".join(word_list)
    try:
        A = parse_pda(student_answer)
    except RuntimeError as e:
        return {'correct': False, 'feedback': str(e)}
    A_words = generate_language(A, length)
    words = parse_word_list(word_list)
    feedback = compare_languages(A_words, words)
    if len(feedback) == 0:
        return {'correct': True}
    else:
        return {'correct': False, 'feedback': " / ".join(feedback)}
Exemplo n.º 4
0
def pda_rejects(student_answer, word_list):
    try:
        A = parse_pda(student_answer)
    except RuntimeError as e:
        return {'correct': False,
                'feedback': str(e)}

    word_list = " ".join(word_list)
    words = parse_word_list(word_list)

    for word in words:
        if pda_accepts_word(A, word):
            return {'correct': False,
                    'feedback': 'a word was accepted',
                    'word': word}

    return {'correct': True,
            'feedback': 'correct'}