def test_draw_random_word_when_forbidden_words_list_given(self, mock_path): tdict = sm.Dictionary("en") forbidden = [] for word in ["test", "code", "snowman", "computer", "school", "house"]: forbidden.append(sm.Word(word)) self.assertEqual(tdict.draw_random_word(forbidden), sm.Word("jacket"), "Incorrect word.")
def test_hashable(self): tword2 = sm.Word("test") tword3 = sm.Word("snowman") tset = set() tset.add(self.tword) tset.add(tword2) tset.add(tword3) self.assertEqual(hash(self.tword), hash(tword3), "Expected the same hash for objects.") self.assertNotEqual(hash(self.tword), hash(tword2), "Expected different hashes for objects") self.assertEqual(len(tset), 2, "Expected two objects in set.")
def test_reset_game_state(self, mock_dict): mock_dict.return_value.draw_random_word.return_value = self.tword tgame = sm.Game() tword2 = sm.Word("house") tgame.words_used.add(tword2) tgame.word_to_guess = tword2 tgame.letters_missed = set("qrtyipd") tgame.letters_used = set("qrtyipdus") tgame.reset_game_state() self.assertIsInstance(tgame.letters_missed, set, "Expected type of set.") self.assertEqual(len(tgame.letters_missed), 0, "Expected empty set.") self.assertIsInstance(tgame.letters_used, set, "Expected type of set.") self.assertEqual(len(tgame.letters_used), 0, "Expected empty set.") self.assertNotEqual(tgame.word_to_guess, tword2, "Expected new word drawed.")
def setUp(self): self.tword = sm.Word("snowman")
def test_draw_random_word(self, mock_randint, mock_path): tdict = sm.Dictionary("en") self.assertEqual(tdict.draw_random_word([]), sm.Word("snowman"), "Incorrect word.")
def test_non_equality(self): tword2 = sm.Word("test") self.assertIsNot(self.tword, tword2, "Expected differen objects.") self.assertNotEqual(self.tword, tword2, "Expected objects not to be equal.")
def test_equality(self): tword2 = sm.Word("snowman") self.assertIsNot(self.tword, tword2, "Expected differen objects.") self.assertEqual(self.tword, tword2, "Expected objects to be equal.")