Пример #1
0
 def test_add_word_with_common_first_letters(self):
     trie = Trie()
     first_noun = Noun({'Entry': 'Hund'})
     second_noun = Noun({'Entry': 'Hundert'})
     trie.add_word(first_noun)
     trie.add_word(second_noun)
     self.assertEqual(trie.search_for_word('Hund'), first_noun)
     self.assertEqual(trie.search_for_word('Hundert'), second_noun)
Пример #2
0
 def test_delete_word_with_no_common_first_letters(self):
     trie = Trie()
     first_noun = Noun({'Entry': 'Hund'})
     second_noun = Noun({'Entry': 'Katze'})
     trie.add_word(first_noun)
     trie.add_word(second_noun)
     trie.delete_word('Hund')
     self.assertEqual(trie.search_for_word('Hund'), None)
     self.assertEqual(trie.search_for_word('Katze'), second_noun)
Пример #3
0
 def test_delete_word_that_has_common_first_letters(self):
     trie = Trie()
     first_noun = Noun({'Entry': 'Baum'})
     second_noun = Noun({'Entry': 'Bart'})
     trie.add_word(first_noun)
     trie.add_word(second_noun)
     trie.delete_word('Bart')
     self.assertEqual(trie.search_for_word('Baum'), first_noun)
     self.assertEqual(trie.search_for_word('Bart'), None)
     self.assertEqual(trie.search_for_word('Ba'), None)
Пример #4
0
 def test_delete_word_that_contains_another_as_substring(self):
     trie = Trie()
     first_noun = Noun({'Entry': 'Hund'})
     second_noun = Noun({'Entry': 'Hundert'})
     trie.add_word(first_noun)
     trie.add_word(second_noun)
     trie.delete_word('Hundert')
     self.assertEqual(trie.search_for_word('Hund'), first_noun)
     self.assertEqual(trie.search_for_word('Hundert'), None)
     self.assertEqual(trie.search_for_word('Hunde'), None)
Пример #5
0
 def test_add_single_word(self):
     trie = Trie()
     test_noun = Noun({'Entry': 'Hund'})
     self.assertEqual(trie.search_for_word('Hund'), None)
     trie.add_word(test_noun)
     self.assertEqual(trie.search_for_word('Hund'), test_noun)
     self.assertEqual(trie.search_for_word('Hun'), None)
     self.assertEqual(trie.search_for_word('Hu'), None)
     self.assertEqual(trie.search_for_word('H'), None)
 def test_add_noun_and_delete(self):
     dictionary = Dictionary(DATABASE)
     test_noun = Noun({'Entry': 'xyz', 'Gender': 'das',
                       'Plural': 'Beispiele', 'Genetive': 'Beispieles',
                       'Meaning': 'example', 'Examples': 'Too lazy'})
     self.assertEqual(dictionary.exists_entry('xyz'), False)
     dictionary.add_entry(test_noun)
     self.assertEqual(dictionary.exists_entry('xyz'), True)
     dictionary.delete_entry('xyz')
     self.assertEqual(dictionary.exists_entry('xyz'), False)
Пример #7
0
 def test_to_str(self):
     test_noun = Noun({
         'Entry': 'Beispiel',
         'Gender': 'das',
         'Plural': 'Beispiele',
         'Genetive': 'Beispieles',
         'Meaning': 'example',
         'Examples': 'Too lazy'
     })
     self.assertEqual(str(test_noun),
                      ("Entry: Beispiel\nGender: das\nPlural: Beispiele\n"
                       "Genetive: Beispieles\nMeaning: example\n"
                       "Examples: Too lazy"))
Пример #8
0
 def test_word_hash(self):
     test_noun = Noun({
         'Entry': 'Beispiel',
         'Gender': 'das',
         'Plural': 'Beispiele',
         'Genetive': 'Beispieles',
         'Meaning': 'example',
         'Examples': 'Too lazy'
     })
     self.assertEqual(test_noun.word_hash['Entry'], 'Beispiel')
     self.assertEqual(test_noun.word_hash['Gender'], 'das')
     self.assertEqual(test_noun.word_hash['Plural'], 'Beispiele')
     self.assertEqual(test_noun.word_hash['Genetive'], 'Beispieles')
     self.assertEqual(test_noun.word_hash['Meaning'], 'example')
     self.assertEqual(test_noun.word_hash['Examples'], 'Too lazy')
 def test_add_noun_and_delete(self):
     handler = DatabaseHandler()
     test_noun = Noun({
         'Entry': 'xyz',
         'Gender': 'das',
         'Plural': 'Beispiele',
         'Genetive': 'Beispieles',
         'Meaning': 'example',
         'Examples': 'Too lazy'
     })
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_noun(test_noun, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_existing_noun(self):
     dictionary = Dictionary(DATABASE)
     test_noun = Noun({'Entry': 'Hund', 'Gender': 'a',
                       'Plural': 'b', 'Genetive': 'c',
                       'Meaning': 'd', 'Examples': 'e'})
     self.assertRaises(DatabaseError, dictionary.add_entry, test_noun)
Пример #11
0
 def test_delete_single_word(self):
     trie = Trie()
     test_noun = Noun({'Entry': 'Hund'})
     trie.add_word(test_noun)
     trie.delete_word('Hund')
     self.assertEqual(trie.search_for_word('Hund'), None)