def test_save_learning_state():
    # This file will be empty
    fake_file = mock_open(read_data='{}')
    # Function open returns fake_file
    flexmock(builtins, open=fake_file)

    # MyVocabulary and LearningState is not saved
    flexmock(MyVocabulary, save_my_vocabulary=lambda: None)
    my_vocabulary = MyVocabulary()
    # Setting my_vocabulary.chosen_words
    my_vocabulary.chosen_words = {"koupit": "buy"}

    flexmock(LearningState, __del__=lambda: None)
    # Setting learning_state with my_vocabulary.chosen_words
    learning_state = LearningState(my_vocabulary)

    learning_state.save_learning_state()

    string = ''
    for call in fake_file.return_value.write.mock_calls:
        string += (call[1][0])

    assert string == '{"round_mistakes": 0,' \
                     ' "successful": 0,' \
                     ' "unsuccessful": 0,' \
                     ' "ordered_words": ["koupit"],' \
                     ' "words": {' \
                     '"koupit": {"value": "buy", "learned": false,' \
                     ' "round_mistakes": 0, "total_mistakes": 0}}}\n'
예제 #2
0
def test_check_guessing_successfully(offered_word, answered_word):
    __mock()
    my_vocabulary = MyVocabulary()
    my_vocabulary.chosen_words = {
        "koupit": "buy",
        "být": "be",
        "postavit": "build"
    }

    learning_process = LearningProcess(LearningState(my_vocabulary))

    assert learning_process.check_guessing(offered_word, answered_word)
예제 #3
0
def test_check_guessing_unsuccessfully(offered_word, answered_word):
    __mock()

    my_vocabulary = MyVocabulary()
    my_vocabulary.chosen_words = {
        "koupit": "buy",
        "být": "be",
        "postavit": "build"
    }

    flexmock(LearningState, __del__=lambda: None)
    learning_process = LearningProcess(LearningState(my_vocabulary))
    assert not learning_process.check_guessing(offered_word, answered_word)
def test_get_value(key, value):
    __mock()

    my_vocabulary = MyVocabulary()
    my_vocabulary.chosen_words = {
        "koupit": "buy",
        "být": "be",
        "postavit": "build"
    }

    learning_state = LearningState(my_vocabulary)
    learning_state.reset_learning_state()

    assert learning_state.get_value(key) == value
예제 #5
0
def test_fail_counters(key):
    __mock()

    my_vocabulary = MyVocabulary()
    my_vocabulary.chosen_words = {
        "koupit": "buy",
        "být": "be",
        "postavit": "build"
    }

    learning_state = LearningState(my_vocabulary)
    total_m = learning_state.words[key]['total_mistakes']
    unsuccessful = learning_state.unsuccessful
    round_m = learning_state.round_mistakes

    learning_process = LearningProcess(learning_state)
    learning_process.increment_fail_counters(key)

    assert learning_state.words[key]['total_mistakes'] == total_m + 1
    assert learning_state.round_mistakes == round_m + 1
    assert learning_state.unsuccessful == unsuccessful + 1