class TestController(TestCase): def setUp(self): super().setUp() self.repo = Repo( SentenceValidator, "/Users/Stefan/PycharmProjects/hangman/sentence_test.txt") self.controller = Controller(self.repo) def test_add(self): self.assertEqual(len(self.repo.get_all()), 3, "Error at loading") self.controller.add("planes are quick") self.assertEqual(len(self.repo.get_all()), 4, "Error at adding") self.assertRaises(ControllerException, self.controller.add, "planes are quick") def test_get_random_sentence(self): random_sentence = self.controller.get_random_sentence() self.assertEqual(type(random_sentence), Sentence, "Fail at getting random") def test_get_available_letters(self): sentence = Sentence("anna has apples") char_list = self.controller.get_available_letters(sentence) self.assertEqual(True, 'a' in char_list, "fail at getting letter") self.assertEqual(True, 'h' in char_list, "fail at getting letter") self.assertEqual(True, 's' in char_list, "fail at getting letter")
class TestRepo(TestCase): def setUp(self): super().setUp() self.repo = Repo( SentenceValidator, "/Users/Stefan/PycharmProjects/hangman/sentence_test.txt") def test_init_from_file(self): self.assertEqual(3, len(self.repo.get_all()), "Error at initial value.") def test_store(self): self.repo.store(Sentence("ana are mere")) self.assertEqual(4, len(self.repo.get_all()), "Error after adding entity") self.assertRaises(RepositoryException, self.repo.store, Sentence("eu")) def test_get_all_string(self): string_list = self.repo.get_all_string() self.assertEqual(3, len(string_list), "Error at getting string list.") self.assertEqual("anna has apples", string_list[0], "Matching error.") def test_get_all(self): sentence_list = self.repo.get_all() self.assertEqual(3, len(sentence_list), "Error at getting sentence list.") cmp_sentence = Sentence("anna has apples") self.assertEqual(cmp_sentence.hidden, sentence_list[0].hidden, "Matching error.") self.assertEqual(cmp_sentence.string, sentence_list[0].string, "Matching error.")