class TestDAWGPrefixSearch(unittest.TestCase): def test_dawg_prefix_search(self): self.dawg = DAWG() self.dawg.add_all(['ashlame', 'ashley', 'askoiu', 'ashlo']) self.assertIsInstance(self.dawg, DAWG, "Object should be of type `lexpy.dawg.DAWG`") self.assertFalse('ash' in self.dawg, "Word should not be in dawg") self.assertTrue('ashley' in self.dawg, "Word should be in dawg") self.assertEqual(4, self.dawg.get_word_count(), "Word count not equal") self.assertTrue(self.dawg.contains_prefix('ash'), "Prefix should be present in DAWG") self.assertEqual(sorted(self.dawg.search_with_prefix('ash')), sorted(['ashlame', 'ashley', 'ashlo']), 'The lists should be equal')
class TestDAWGPrefixExists(unittest.TestCase): def test_dawg_node_prefix_exists(self): self.dawg = DAWG() self.dawg.add_all(['ash', 'ashley']) self.dawg.reduce() self.assertIsInstance(self.dawg, DAWG, "Object should be of type `lexpy.dawg.DAWG`") self.assertTrue('ash' in self.dawg, "Word should be in dawg") self.assertTrue('ashley' in self.dawg, "Word should be in dawg") self.assertEqual(2, self.dawg.get_word_count(), "Word count not equal") self.assertTrue(self.dawg.contains_prefix('ash'), "Prefix should be present in DAWG") self.assertTrue(self.dawg.contains_prefix('as'), "Prefix should be present in DAWG") self.assertTrue(self.dawg.contains_prefix('a'), "Prefix should be present in DAWG") def test_dawg_node_prefix_not_exists(self): self.dawg = DAWG() self.dawg.add_all(['ash', 'ashley']) self.dawg.reduce() self.assertIsInstance(self.dawg, DAWG, "Object should be of type `lexpy.dawg.DAWG`") self.assertTrue('ash' in self.dawg, "Word should be in dawg") self.assertTrue('ashley' in self.dawg, "Word should be in dawg") self.assertEqual(2, self.dawg.get_word_count(), "Word count not equal") self.assertFalse(self.dawg.contains_prefix('xmas'), "Prefix should be present in DAWG") self.assertFalse(self.dawg.contains_prefix('xor'), "Prefix should be present in DAWG") self.assertFalse(self.dawg.contains_prefix('sh'), "Prefix should be present in DAWG")