def test_1(self): self.assertEqual(word_search([["a"]], \ Dictionary(iterable=["a"])), \ {'a'}) self.assertEqual(word_search([["a", "a", "r"], ["t", "c", "d"]], \ Dictionary(iterable=["car", "card", "cart", "cat"])), \ {'car', 'card', 'cat'})
def testExample(self): grid_chars = [['w', 'm', 'l'], ['l', 'i', 'a'], ['e', 'k', 'c']] dictionary = EnglishDictionary() ground_truth = set([ 'mile', 'i', 'aim', 'iw', 'lack', 'ia', 'milk', 'ca', 'mil', 'mak', 'el', 'lam', 'c', 'wi', 'kc', 'ai', 'la', 'ma', 'ml', 'cam', 'k', 'lek', 'ie', 'li', 'mac', 'ci', 'ka', 'mi', 'a', 'make', 'w', 'l', 'al', 'ki', 'le', 'm', 'lei', 'il', 'lac', 'cim', 'elk', 'cia', 'lm', 'elm', 'ic', 'ak', 'ali', 'mack', 'ac', 'ail', 'lie', 'am', 'e', 'ilk' ]) self.assertEqual(word_search(grid_chars, dictionary), ground_truth)
def testSimpleDictionary(self): grid_chars = [['a', 'a', 'r'], ['t', 'c', 'd']] simple_dictionary = MySimpleDictionary(['car', 'card', 'cart', 'cat']) ground_truth = set(['cat', 'car', 'card']) self.assertEqual(word_search(grid_chars, simple_dictionary), ground_truth)
def testEmptyGrid(self): _dict = MySimpleDictionary(['flower']) self.assertEqual(len(word_search([], _dict)), 0)
def testEmptyDictionary(self): _dict = MySimpleDictionary([]) self.assertEqual(len(word_search(['a', 'b'], _dict)), 0)
def test_2(self): words = ['crash', 'crush'] self.assertEqual(word_search([['c','r','a','s','h'], ['z','z','u','z','z']],\ Dictionary(iterable=words)), {'crush', 'crash'})
def test_0(self): self.assertEqual(word_search([], Dictionary()), set()) self.assertEqual(word_search([[]], Dictionary()), set()) self.assertEqual(word_search([["a"]], Dictionary()), set())