class Test(unittest.TestCase): def setUp(self): self.d = Dictionary(['CAR', 'CAT', 'CARD', 'CART']) # tests for the Dictionary class def test_word_is_in_dictionary(self): self.assertTrue(self.d.is_word('CAR')) def test_word_is_not_in_dictionary(self): self.assertFalse(self.d.is_word('CA')) def test_prefix_is_in_dictionary(self): self.assertTrue(self.d.is_prefix('CA')) def test_prefix_is_not_in_dictionary(self): self.assertFalse(self.d.is_prefix('D')) # tests for the whole solution def test_example(self): g = Grid([['A', 'A', 'R'], ['T', 'C', 'D']]) self.assertSetEqual(search_words(g, self.d), {'CAT', 'CAR', 'CARD'}) def test_empty_dict(self): g = Grid([['A', 'A', 'R']]) d = Dictionary([]) self.assertEqual(search_words(g, d), set()) def test_empty_grid(self): g = Grid([[]]) self.assertEqual(search_words(g, self.d), set())
def test_findmatch(self): grid = Grid(['AAR', 'TCD']) dictionary = Dictionary(['CAR', 'CART', 'CARD', 'CAT']) self.assertSetEqual(findMatch(grid, dictionary, 0, 0), set()) self.assertSetEqual(findMatch(grid, dictionary, 1, 1), {'CAR', 'CAT', 'CARD'}) dictionary = Dictionary( ['CAR', 'CART', 'CARD', 'CAT', 'RAT', 'RCDAAT', 'RCDAATA']) self.assertSetEqual(findMatch(grid, dictionary, 0, 2), {'RAT', 'RCDAAT'})
def test_findmatches(self): grid = Grid(['AAR', 'TCD']) dictionary = Dictionary(['CAR', 'CART', 'CARD', 'CAT']) self.assertSetEqual(findMatches(grid, dictionary), {'CAR', 'CAT', 'CARD'}) dictionary = Dictionary( ['CAR', 'CART', 'CARD', 'CAT', 'RAT', 'RCDAATA']) self.assertSetEqual(findMatches(grid, dictionary), {'RAT', 'CAR', 'CAT', 'CARD'}) self.assertSetEqual(findMatches(Grid(['A']), Dictionary(['A', 'B'])), {'A'}) self.assertSetEqual(findMatches(Grid(['A']), Dictionary(['AA', 'B'])), set())
def test_isprefix(self): dictionary = Dictionary(['CAR', 'CART', 'CARD', 'CAT']) self.assertEqual(dictionary.isPrefix('A'), False) self.assertEqual(dictionary.isPrefix('car'), False) self.assertEqual(dictionary.isPrefix('CARDS'), False) self.assertEqual(dictionary.isPrefix(''), True) self.assertEqual(dictionary.isPrefix('CARD'), True) self.assertEqual(dictionary.isPrefix('CAR'), True)
def setUp(self): self.d = Dictionary(['CAR', 'CAT', 'CARD', 'CART'])
def test_empty_dict(self): g = Grid([['A', 'A', 'R']]) d = Dictionary([]) self.assertEqual(search_words(g, d), set())