class TestWildCardSearch(unittest.TestCase): def test_dawg_asterisk_search(self): self.dawg = DAWG() self.dawg.add_all(['ash', 'ashley']) 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(sorted(self.dawg.search('a*')), sorted(['ash', 'ashley']), 'The lists should be equal') def test_dawg_question_search(self): self.dawg = DAWG() self.dawg.add_all(['ab', 'as', 'ash', 'ashley']) 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(sorted(self.dawg.search('a?')), sorted(['ab', 'as']), 'The lists should be equal') def test_dawg_wildcard_search(self): self.dawg = DAWG() self.dawg.add_all(['ab', 'as', 'ash', 'ashley']) 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(sorted(self.dawg.search('*a******?')), sorted(['ab', 'as', 'ash', 'ashley']), 'The lists should be equal') def test_dawg_wildcard_exception(self): self.dawg = DAWG() self.dawg.add_all(['ab', 'as', 'ash', 'ashley']) 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.assertRaises(InvalidWildCardExpressionError, self.dawg.search, '#$%^a')
def test_without_count(self): d = DAWG() d.add_all(['ash', 'ashes', 'ashes', 'ashley']) d.reduce() expected = ['ash', 'ashes', 'ashley'] self.assertListEqual(expected, d.search('a*'))
def test_with_count(self): d = DAWG() d.add_all(['ash', 'ashes', 'ashes', 'ashley']) d.reduce() expected = [('ash', 1), ('ashes', 2), ('ashley', 1)] self.assertListEqual(expected, d.search('a*', with_count=True))