class  PySearcherTestCases(unittest.TestCase):
    def setUp(self):
        self.reader = WordReader()
        self.finder = Trie(self.reader)
        self.searcher = Searcher(self.finder, '')

    def tearDown(self):
        self.reader = None
        self.finder = None
        self.searcher = None

    def testRandomWord(self):
       """ Tests that non-empty words are found and they are not the same """
       word1 = self.searcher.randomWord()
       word2 = self.searcher.randomWord()
       self.assertTrue(len(word1) > 1, 'Word length too short')
       self.assertTrue(len(word2) > 1, 'Word length too short')
       self.assertNotEqual(word1, word2, 'Found the same word')

    def testRandomWords(self):
       """ Tests that a set of random words do not contain the same words """
       words = self.searcher.randomWord(5)
       self.assertTrue(len(set(words)) == 5, 'Did not find 5 unique words')

    def testBinaryOperationsAreWorking(self):
        """
        Checks that operations are not identic and that correct number of hits
        is returned for every known result.
        """
        self.reader.addFileName(MaterialFilePath, readNow=True)
        self.finder.addFromReader()

        results = []
        for operation in operations:
            results.append(self.searcher.search(operations[operation],
                                                returnCount=True))
        self.assertTrue(len(set(results)) == 6, #i.e. operations are not identic
                        'Searcher failed binary operation check')
        for searchTerm in binaryOperationsSearch:
            self.assertEqual(self.searcher.search(searchTerm, returnCount=True),
                             binaryOperationsSearch[searchTerm],
                            'Searcher found wrong number of hits on some search')
    print "Hello World";



    lukija = WordReader(["../Material/Grimm's Fairy Tales.txt"])
#    lukija.readWords()
    punamusta = RedBlack(lukija)
    trie = Trie(lukija)
#    print 'Adding all words to Punamusta'
#    punamusta.addFromReader()

    searcher = Searcher(trie, '')
    words = {}
    checklist = [0]*11
    while(True):
        word = searcher.randomWord()
        if len(word) > 10 or len(word) < 4:
            continue
        if not len(word) in words:
            words[len(word)] = [word]
        elif len(words[len(word)]) < 10:
            words[len(word)].append(word)
        else:
            words[len(word)].append(word)
            checklist[len(word)] = 1
        print word, checklist
        if sum(checklist[4:]) == 7:
            break

    pickle.dump( words, open( "save.p", "wb" ) )