Esempio n. 1
0
class TestSpellChecker(unittest.TestCase):
    def setUp(self):
        self.spellChecker = SpellChecker()
        self.spellChecker.load_words('spell.words')

    def test_spell_checker(self):
        self.assertTrue(self.spellChecker.check_word('zygotic'))
        failed_words = self.spellChecker.check_words(
                'zygotic mistasdas elementary')
        self.assertEquals(1, len(failed_words))
        self.assertEquals('mistasdas', failed_words[0])
        self.assertEquals(0, len(self.spellChecker.check_words(
                'our first correct sentence')))
        # handle case sensitivity
        self.assertEquals(0, len(self.spellChecker.check_words(
                'Our first correct sentence')))
        # handle full stop
        self.assertEquals(0, len(self.spellChecker.check_words(
                'Our first correct sentence.')))
        failed_words = self.spellChecker.check_words(
                'zygotic mistasdas spelllleeeing elementary')
        self.assertEquals(2, len(failed_words))
        self.assertEquals('mistasdas', failed_words[0])
        self.assertEquals('spelllleeeing', failed_words[1])
        # more bugs because the spell checker doesn't spell check itself correctly 21 entries not correct dictionary words need to be lower
        self.assertEqual(0, len(self.spellChecker.check_document('spell.words')))
Esempio n. 2
0
class TestSpellChecker(unittest.TestCase):
    def setUp(self):
        self.spellChecker = SpellChecker()
        self.spellChecker.load_words('spell.words')

    def test_spell_checker(self):
        self.assertTrue(self.spellChecker.check_word('zygotic'))
        failed_words = self.spellChecker.check_words('zygotic mistasdas elementary')
        self.assertEquals(1, len(failed_words))
        self.assertEquals('mistasdas', failed_words[0]['word'])
        self.assertEquals(1, failed_words[0]['line'])
        self.assertEquals(9, failed_words[0]['pos'])
        self.assertEquals(0, len(self.spellChecker.check_words('our first correct sentence')))
        # handle case sensitivity
        self.assertEquals(0, len(self.spellChecker.check_words('Our capital sentence')))
        # handle full stop
        self.assertEquals(0, len(self.spellChecker.check_words('Our full stop sentence.')))
        failed_words = self.spellChecker.check_words('zygotic mistasdas spelllleeeing elementary')
        self.assertEquals(2, len(failed_words))
        self.assertEquals('mistasdas', failed_words[0]['word'])
        self.assertEquals(1, failed_words[0]['line'])
        self.assertEquals(9, failed_words[0]['pos'])
        self.assertEquals('spelllleeeing', failed_words[1]['word'])
        self.assertEquals(1, failed_words[1]['line'])
        self.assertEquals(19, failed_words[1]['pos'])
        self.assertEqual(0, len(self.spellChecker.check_document('spell.words')))
class TestSpellChecker(unittest.TestCase):

    def setUp(self):
        self.spellChecker = SpellChecker()
        self.spellChecker.load_words('spell.words')

    def test_spell_checker(self):
        self.assertTrue(len(self.spellChecker.words) > 50000)
        self.assertTrue(self.spellChecker.check_word('zygotic'))
        self.assertFalse(self.spellChecker.check_word('zogotic'))
        self.assertEqual([{'line': 1, 'pos': 9, 'word': 'mistasdas'}],
                self.spellChecker.check_words('zygotic mistasdas elementary'))
        self.assertEqual([],
                self.spellChecker.check_words('our first correct sentence'))
        self.assertEqual(0,
                len(self.spellChecker.check_words('Our first correct sentence.')))
        self.assertEqual([{'line': 1, 'pos': 9, 'word': 'mistasdas'}, {'line': 1, 'pos': 19, 'word': 'spelllleeeing'}],
                self.spellChecker.check_words('zygotic mistasdas spelllleeeing elementary'))
        self.assertEqual(2,
                len(self.spellChecker.check_words('zygotic mistasdas spelllleeeing elementary')))
        #self.assertEqual(0, len(self.spellChecker.check_document('spell.words')))
        self.assertEqual([{'line': 2, 'pos': 8, 'word': 'larn'}, 
                          {'line': 2, 'pos': 13, 'word': 'huw'}, 
                          {'line': 2, 'pos': 26, 'word': 'wurdz'}],
                self.spellChecker.check_document('darren.txt'))
        self.assertEqual({'darren.txt': [{'line': 2, 'pos': 8, 'word': 'larn'}, 
                          {'line': 2, 'pos': 13, 'word': 'huw'}, 
                          {'line': 2, 'pos': 26, 'word': 'wurdz'}]},
                self.spellChecker.check_directory('*.txt'))
class TestSpellChecker(unittest.TestCase):

    def setUp(self):
        self.spellChecker = SpellChecker()
        # This is the path name for our dictionary file
        file_name = '/Users/barrysheppard/Github/DBSDataAnalysis/'
        file_name = file_name + 'BigData/04Lecture/spell.words'
        self.spellChecker.load_words(file_name)

    def test_spell_checker(self):
        self.assertTrue(self.spellChecker.check_word('zygotic'))
        failed_words = self.spellChecker.check_words('zygotic mistasdas elementary')
        self.assertEqual(1, len(failed_words))
        self.assertEqual('mistasdas', failed_words[0]['word'])
        self.assertEqual(1, failed_words[0]['line'])
        self.assertEqual(9, failed_words[0]['pos'])
        self.assertEqual(0, len(self.spellChecker.check_words('our first correct sentence')))
        # handle case sensitivity
        self.assertEqual(0, len(self.spellChecker.check_words('Our capital sentence')))
        # handle full stop
        self.assertEqual(0, len(self.spellChecker.check_words('Our full stop sentence.')))
        failed_words = self.spellChecker.check_words('zygotic mistasdas spelllleeeing elementary')
        self.assertEqual(2, len(failed_words))
        self.assertEqual('mistasdas', failed_words[0]['word'])
        self.assertEqual(1, failed_words[0]['line'])
        self.assertEqual(9, failed_words[0]['pos'])
        self.assertEqual('spelllleeeing', failed_words[1]['word'])
        self.assertEqual(1, failed_words[1]['line'])
        self.assertEqual(19, failed_words[1]['pos'])
        self.assertEqual(0, len(self.spellChecker.check_document('spell.words')))
Esempio n. 5
0
class TestSpellChecker(unittest.TestCase):
    def setUp(self):
        self.spellChecker = SpellChecker()
        self.spellChecker.load_words('spell.words')

    def test_spell_checker(self):
        self.assertEqual(53751, len(self.spellChecker.words))
        self.assertTrue(self.spellChecker.check_word('zygotic'))
        self.assertEqual([{
            'line': 1,
            'pos': 9,
            'word': 'mistasdas'
        }], self.spellChecker.check_words('zygotic mistasdas elementary'))
        self.assertEqual(
            [], self.spellChecker.check_words('our first correct sentence'))
        self.assertEqual(
            0,
            len(self.spellChecker.check_words('Our first correct sentence.')))
        self.assertEqual([{
            'line': 1,
            'pos': 9,
            'word': 'mistasdas'
        }, {
            'line': 1,
            'pos': 19,
            'word': 'spelllleeeing'
        }],
                         self.spellChecker.check_words(
                             'zygotic mistasdas spelllleeeing elementary'))
        self.assertEqual(
            2,
            len(
                self.spellChecker.check_words(
                    'zygotic mistasdas spelllleeeing elementary')))
        self.assertEqual(0, len(self.spellChecker.check_document("karen.txt")))
        #self.assertEqual(0, len(self.spellChecker.check_document('spell.words')))
        self.assertEqual(
            26,
            len(
                self.spellChecker.check_dir(
                    "/Users/karenbyrne/Desktop/python_files/")))
        self.assertEqual(
            2,
            len(
                self.spellChecker.check_dir(
                    "/Users/karenbyrne/Desktop/python_files/")))
Esempio n. 6
0
class TestSpellChecker(unittest.TestCase):
    def setUp(self):
        self.spellChecker = SpellChecker()
        self.spellChecker.load_words('spell.words')

    def test_spell_checker(self):
        self.assertTrue(self.spellChecker.check_word(
            'zygotic'))  # Checks if (single) word is present in list
        failed_words = self.spellChecker.check_words(
            'zygotic mistasdas tennyy elementary')  # two incorrect words
        self.assertEquals(
            2, len(failed_words)
        )  # Checks that failed_words has two entries, i.e. mistasdas and tennyy
        print('Contents of failed words array ',
              failed_words)  # print failed_words array to see what's in it.
        self.assertEquals(
            'mistasdas', failed_words[0]['word']
        )  # Checks that the zero'th failed word in the array is mistasda
        self.assertEquals(
            'tennyy', failed_words[1]['word']
        )  # checks that the 2nd failed word (in Position 1) is tennyy
        self.assertEquals(
            {
                'line': 1,
                'word': 'mistasdas',
                'pos': 9
            }, failed_words[0]
        )  # checks the line number, word (mistasdas) and caret position are correct
        self.assertEquals(
            {
                'line': 1,
                'word': 'tennyy',
                'pos': 19
            }, failed_words[1]
        )  # checks the line number, word (tenny) and caret position are correct
        self.assertEquals(
            1, failed_words[0]['line']
        )  # Checks that the zero'th failed (mistasdas) word occurs on line 1
        self.assertEquals(
            19, failed_words[1]['pos']
        )  # checks that the 2nd failed word occurs at caret position 19
        self.assertEquals(
            0, len(self.spellChecker.check_words('our first correct sentence'))
        )  # checks that lebgth of array is 0, i.e. includes no failed words

        # handle case sensitivity
        self.assertEquals(
            0,
            len(self.spellChecker.check_words('Our first correct sentence')))
        # handle full stop
        self.assertEquals(
            0,
            len(self.spellChecker.check_words('Our first correct sentence.')))

        failed_words = self.spellChecker.check_words(
            'zygotic mistasdas spelllleeeing elementary')
        print('Contents of failed words array ',
              failed_words)  # print failed_words array to see what's in it.
        self.assertEquals(
            2, len(failed_words)
        )  # Checks that array length is 2, i.e. has two failed words
        self.assertEquals('mistasdas', failed_words[0]['word'])
        self.assertEquals(
            1, failed_words[0]['line']
        )  # Checks that the zero'th failed (mistasdas) word occurs on line 1
        self.assertEquals(
            9, failed_words[0]['pos']
        )  # checks that the zero'th failed word occurs at caret position 9
        self.assertEquals(
            'spelllleeeing', failed_words[1]
            ['word'])  # checks the 2nd word in the failed words array
        self.assertEquals(
            1, failed_words[1]['line']
        )  # Checks that the 2nd failed (spelllleeeing) word occurs on line 1
        self.assertEquals(
            19, failed_words[1]['pos']
        )  # checks that the 2nd failed word occurs at caret position 19

        self.assertEquals(
            {
                'line': 1,
                'word': 'mistasdas',
                'pos': 9
            }, failed_words[0]
        )  # Checks the contents of zero'th position in failed words array
        self.assertEquals(
            {
                'line': 1,
                'word': 'spelllleeeing',
                'pos': 19
            }, failed_words[1]
        )  # Checks the contents of 2ND position in failed words array

        # more bugs because the spell checker doesn’t spell check itself correctly – 0 entries when .lower is used – dictionary words need to be lower
        self.assertEqual(0,
                         len(self.spellChecker.check_document('spell.words')))