Example #1
0
 def test_number_of_words(self):
     print()
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     self.assertEqual(game_app.calc_number_of_words(), 0)
     game_app.add_word("house", "casa")
     self.assertEqual(game_app.calc_number_of_words(), 1)
Example #2
0
 def test_check_solution(self):
     print("\ntest_check_solution()")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("house", "casa, vivenda")
     self.assertEqual(game_app.check_solution("house", "casa"), (True, game_app.words[0]))
     self.assertEqual(game_app.check_solution("house", "Casa"), (True, game_app.words[0]))
     self.assertEqual(game_app.check_solution("house", "CASA"), (True, game_app.words[0]))
     self.assertEqual(game_app.check_solution("house", "caasa"), (False, game_app.words[0]))
     self.assertEqual(game_app.check_solution("house", "vivenda"), (True, game_app.words[0]))
Example #3
0
 def test_pick_random_word(self):
     print("\ntest_pick_random_word()")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("house", "casa")
     self.assertEqual(game_app.pick_random_word("en", "pt"), {"en": "house", "pt": "casa", "points": 1})
     self.assertEqual(game_app.pick_random_word("pt", "en"), {"pt": "casa", "en": "house", "points": 1})
     with self.assertRaises(Exception):
         game_app.pick_random_word("pt", "en1")
     self.assertEqual(game_app.pick_random_word(), {"en": "house", "pt": "casa", "points": 1})
Example #4
0
    def test_add_word(self):
        game_app = main.GameApp()
        game_app.add_languages("en", "pt")

        game_app.add_word("house", "casa")
        sol = {"en": "house", "pt": "casa", "points": POINTS["word"]["init"]}
        self.assertIn(sol, game_app.words)

        game_app.add_word("house", "casa, vivenda")
        sol = {"en": "house", "pt": "casa, vivenda", "points": POINTS["word"]["init"]}
        self.assertIn(sol, game_app.words)
Example #5
0
 def test_order_by(self):
     print("\ntest_order_by()")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("tree", "árvore")
     game_app.add_word("house", "casa")
     game_app.update_word_points("house", "casa")
     self.tree_word["points"] = POINTS["word"]["init"]
     self.house_word["points"] = POINTS["word"]["init"] * POINTS["word"]["increase_rate"]
     self.assertEqual(game_app.order_by("points"), [self.tree_word, self.house_word])
     self.assertEqual(game_app.order_by("points", True), [self.house_word, self.tree_word])
     self.assertEqual(game_app.order_by("en"), [self.house_word, self.tree_word])
     self.assertEqual(game_app.order_by("pt"), [self.tree_word, self.house_word])
Example #6
0
 def test_update_points(self):
     print("\ntest_update_points")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("tree", "árvore")
     game_app.points = 500
     down4right_words = 50
     up4wrong_words_a = 10_000
     up4wrong_words_b = 20
     game_app.update_points("tree", "bad")
     self.assertEqual(game_app.points, 500 - 500/down4right_words)
     game_app.points = 500
     increment = up4wrong_words_a / ( game_app.points + up4wrong_words_b)
     game_app.update_points("tree", "árvore")
     self.assertEqual(game_app.points, 500 + increment)
Example #7
0
 def test_update_word_points(self):
     print("\ntest_update_word_points()")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("tree", "árvore")
     increase_rate = POINTS["word"]["increase_rate"]
     decreased_rate = POINTS["word"]["decreased_rate"]
     sol = {"en": "tree", "pt": "árvore", "points": POINTS["word"]["init"] * increase_rate}
     self.assertEqual(game_app.update_word_points("tree", "árvore"), sol)
     game_app.add_word("house", "casa, vivenda")
     sol = {"en": "house", "pt": "casa, vivenda", "points": POINTS["word"]["init"] * increase_rate}
     self.assertEqual(game_app.update_word_points("house", "casa"), sol)
     sol["points"] /= decreased_rate
     self.assertEqual(game_app.update_word_points("house", "casaa"), sol)
     sol["points"] /= decreased_rate
     self.assertEqual(game_app.update_word_points("house", ""), sol)
     game_app.add_word("brew", "preparar")
     sol = {"en": "brew", "pt": "preparar", "points": POINTS["word"]["init"] / decreased_rate}
     self.assertEqual(game_app.update_word_points("brew", ""), sol)
Example #8
0
 def test_delete_word(self):
     print("\ntest_delete_word()")
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     game_app.add_word("house", "casa")
     game_app.delete_word("house", "en")
     self.assertEqual([], game_app.words)
     game_app.add_word("house", "casa")
     game_app.add_word("tree", "árvore")
     game_app.delete_word("tree", "en")
     self.assertEqual([self.house_word], game_app.words)
     game_app.delete_word(self.house_word)
     self.assertEqual([], game_app.words)
     game_app.add_word("house", "casa")
     game_app.delete_word("house")
     self.assertEqual([], game_app.words)
     game_app.add_word("house", "casa")
     game_app.delete_word("tree")
     self.assertEqual([self.house_word], game_app.words)
Example #9
0
 def test_add_languages(self):
     game_app = main.GameApp()
     game_app.add_languages("en", "pt")
     self.assertEqual(game_app.languages, ["en", "pt"])