class  PyRedBlackTestCases(unittest.TestCase):
    def setUp(self):
        self.lukija = WordReader()
        # test addFileNames
        self.redblack = RedBlack(self.lukija)

    def tearDown(self):
        self.lukija.clear('all')
        self.redblack.clear()
        self.lukija = None
        self.redblack = None

    def testSimpleAddFind(self): # Red Black would fail this test now
        """ Add some objects to Red Black tree and see if you can find them """
        checklist = []
        for object in WordsToAdd:
            self.redblack.add(object[0], object[1:]) # Add words to Trie
        for word in WordsToAdd:
            # Get the position of each word
            pos, _,  _ = self.redblack.find(word[0])
            # We add the word and the found positions to match list formatting
            # to the input
            checklist.append((word[0], pos[0][0], pos[0][1]))
        self.assertEqual(checklist , WordsToAdd,
                         'Did not find all words that were supposed to add')

        self.redblack.clear()
        self.lukija.readWords()
        self.redblack.addFromReader()



    def testMultiWordFind(self):
        """ Tests that multiple instances of a word are found correctly """
        for object in MultiWordAdd:
            self.redblack.add(object[0], object[1:]) # Add words to Trie

        pos, _, _ = self.redblack.find('a')
        self.assertEqual(pos, MultiWordFindA,
                         'RB: Error finding multiple instances of a word')
        pos, _, _ = self.redblack.find('b')
        self.assertEqual(pos, MultiWordFindB,
                         'RB: Error finding multiple instances of a word')

    def testWordCounter(self):
        """ Tests that both the reader and the tree can count the words """
        self.lukija.clear('all')
        self.lukija.addFileNames(["../../Material/50words_in_UTF-8.txt"])
        self.assertEqual(self.lukija.wordcount, 0,
                         'RB: WordReader clearing failed')
        self.lukija.readWords()
        self.assertEqual(self.lukija.wordcount, 50,
                         'RB: WordReader failed in reading words')
        self.redblack.clear()
        self.redblack.addFromReader()
        self.assertEqual(self.redblack.wordCount, 50,
                         'RB: word counting failed')
Example #2
0
class  PyTrieTestCases(unittest.TestCase):
    def setUp(self):
        self.lukija = WordReader()
        # test addFileNames
        self.lukija.addFileNames(["../../Material/The Adventures of Tom Sawyer by Mark Twain.txt"])
        self.trie = Trie(self.lukija)

    def tearDown(self):
        self.lukija.clear('all')
        self.trie.clear()
        self.lukija = None
        self.trie = None

    def testSimpleAddFind(self):
        """ Add some objects to Trie and see if you can find them """
        checklist = []
        for object in WordsToAdd:
            self.trie.add(object[0], object[1:]) # Add words to Trie
        for word in WordsToAdd:
            # Get the position of each word
            pos, _, _ = self.trie.find(word[0])
            # We add the word and the found positions to match list formatting
            # to the input
            checklist.append((word[0], pos[0][0], pos[0][1]))
        self.assertEqual(checklist , WordsToAdd,
                         'Trie: Did not find all words that were supposed to add')

    def testMultiWordFind(self):
        for object in MultiWordAdd:
            self.trie.add(object[0], object[1:]) # Add words to Trie
        pos, _, _ = self.trie.find('a')
        self.assertEqual(pos, MultiWordFindA,
                         'Trie: Error finding multiple instances of a word')
        pos, _, _ = self.trie.find('b')
        self.assertEqual(pos, MultiWordFindB,
                         'Trie: Error finding multiple instances of a word')


    def testWordCounter(self):
        """ Tests that both the reader and the tree can count the words """
        self.lukija.clear('all')
        self.lukija.addFileNames(["../../Material/50words_in_UTF-8.txt"])
        self.assertEqual(self.lukija.wordcount, 0,
                         'Trie: WordReader clearing failed')
        self.lukija.readWords()
        self.assertEqual(self.lukija.wordcount, 50,
                         'Trie: WordReader failed in reading words')
        self.trie.clear()
        self.trie.addFromReader()
        self.assertEqual(self.trie.wordCount, 50,
                         'Trie: word counting failed')
Example #3
0
 def setUp(self):
     self.lukija = WordReader()
     # test addFileNames
     self.lukija.addFileNames(["../../Material/The Adventures of Tom Sawyer by Mark Twain.txt"])
     self.trie = Trie(self.lukija)
 def setUp(self):
     self.lukija = WordReader()
     # test addFileNames
     self.redblack = RedBlack(self.lukija)