Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Dec 28, 2023
1 parent a96d087 commit 9654442
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions tests/spellchecker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,12 @@ def test_correction(self):
def test_candidates(self):
"""test spell checker candidates"""
spell = SpellChecker()
cands = {
"tes",
"thas",
"tis",
"thes",
"thus",
"thu",
"thy",
"thi",
"tas",
"tus",
"thos",
"tho",
"tha",
"the",
"this",
}
cands = {"ts", "thy", "tho", "thus", "ohs", "this", "the"}
self.assertEqual(spell.candidates("ths"), cands)
self.assertEqual(spell.candidates("the"), {"the"})
self.assertEqual(spell.candidates("-"), {"-"})
# something that cannot exist... should return None...
self.assertEqual(spell.candidates("manasaeds"), None)
self.assertEqual(spell.candidates("bugalouoo"), None)

def test_words(self):
"""test the parsing of words"""
Expand Down Expand Up @@ -77,8 +61,6 @@ def test_word_known(self):
"""test if the word is a `known` word or not"""
spell = SpellChecker()
self.assertEqual(spell.known(["this"]), {"this"})
self.assertEqual(spell.known(["sherlock"]), {"sherlock"})
self.assertEqual(spell.known(["holmes"]), {"holmes"})
self.assertEqual(spell.known(["known"]), {"known"})

self.assertEqual(spell.known(["-"]), set())
Expand All @@ -90,8 +72,6 @@ def test_unknown_words(self):
"""test the unknown word functionality"""
spell = SpellChecker()
self.assertEqual(spell.unknown(["this"]), set())
self.assertEqual(spell.unknown(["sherlock"]), set())
self.assertEqual(spell.unknown(["holmes"]), set())
self.assertEqual(spell.unknown(["known"]), set())
self.assertEqual(spell.unknown(["-"]), set())

Expand Down Expand Up @@ -257,13 +237,14 @@ def test_remove_by_threshold(self):
spell = SpellChecker()
cnt = 0
for key in spell.word_frequency.keys():
if spell.word_frequency[key] < 300:
if spell.word_frequency[key] <= 300:
cnt += 1
self.assertGreater(cnt, 0)
spell.word_frequency.remove_by_threshold(300)
cnt = 0
for key in spell.word_frequency.words(): # synonym for keys
if spell.word_frequency[key] < 300:
if spell.word_frequency[key] <= 300:
print(key)
cnt += 1
self.assertEqual(cnt, 0)

Expand All @@ -272,13 +253,13 @@ def test_remove_by_threshold_using_items(self):
spell = SpellChecker()
cnt = 0
for _, val in spell.word_frequency.items():
if val < 300:
if val <= 300:
cnt += 1
self.assertGreater(cnt, 0)
spell.word_frequency.remove_by_threshold(300)
cnt = 0
for _, val in spell.word_frequency.items(): # synonym for keys
if val < 300:
if val <= 300:
cnt += 1
self.assertEqual(cnt, 0)

Expand Down

0 comments on commit 9654442

Please sign in to comment.