def testTokenOverlap(self):
        tokens = Tokens()
        tokens.addLettersWithValue(1, "abccd")

        assert tokens.countOverlapForValue(1, "acd") == 3
        assert tokens.countOverlapForValue(1, "accd") == 4
        assert tokens.countOverlapForValue(1, "acdd") == 3
        
        pass
Example #2
0
'''
from alphabear_wizard.vocabulary import fillVocabulary
from alphabear_wizard.solver import VocabularySolver
from alphabear_wizard.scorer import Scorer
from alphabear_wizard.boardSetup import Tokens
from __builtin__ import str
    
if __name__ == '__main__':
    pass
# intitialization
vocabulary = fillVocabulary()
solver = VocabularySolver(vocabulary)
scorer = Scorer()

# create board
board = Tokens()
while True:
    while True:
        cInput = raw_input("Add Value\t:")
        if len(cInput) < 1:
            break
        try:
            value = int(cInput)
            if value >= 1 and value <= 10 : 
                pass
            else :
                print 'Invalid number'
                continue
        except ValueError:
            print 'Invalid number'
            continue
Example #3
0
def isPossible(word, solver):
    if len(word) > 5 and containsVocal(word):
        return True
    if len(solver.solve(word)) > 0:
        return True
    return False
    
if __name__ == '__main__':
    pass
# intitialization
vocabulary = fillVocabulary()
solver = VocabularySolver(vocabulary)
scorer = Scorer()

# create board
board = Tokens()

random.seed(666)
charList = generateCharacterOccurance()
currentWord = '12345'
for k in range(1000):
    
    if len(currentWord) < 1:
        currentWord = '1'
    newChars = ''
    while not len(newChars) > 0 or not len(newChars) < 15 or not isPossible(board.getCharacters() + newChars, solver): 
        newChars = ''
        for i in range(len(currentWord)):
            for k in range(random.randrange(3)):
                newChars += charList[random.randrange(len(charList))]
               
 def testDeltetDecrementTokens(self):   
     tokens = Tokens()
     tokens.addLettersWithValue(1, "ham")
     tokens.addLettersWithValue(3, "spam")
     tokens.addLettersWithValue(5, "shrubbery")
     
     tokens.deleteLowestLetters('shamm')
     tokens.decrement()
     assert tokens.countOverlapForValue(1, "ham") == 0
     assert tokens.countOverlapForValue(0, "ham") == 0
     assert tokens.countOverlapForValue(3, "spam") == 0
     assert tokens.countOverlapForValue(2, "spam") == 2
     assert tokens.countOverlapForValue(5, "shrubbery") == 0
     assert tokens.countOverlapForValue(4, "shrubbery") == 9
     
     tokens.deleteLowestLetters('shamm')
     tokens.decrement()
     assert tokens.countOverlapForValue(3, "spam") == 0
     assert tokens.countOverlapForValue(2, "spam") == 0
     assert tokens.countOverlapForValue(1, "spam") == 1
     assert tokens.countOverlapForValue(5, "shrubbery") == 0
     assert tokens.countOverlapForValue(4, "shrubbery") == 0
     assert tokens.countOverlapForValue(3, "shrubbery") == 7
     
     pass
 def testAddDeleteTokens(self):
     
     tokens = Tokens()
     tokens.addLettersWithValue(1, "ham")
     tokens.addLettersWithValue(2, "spam")
     
     assert tokens.countOverlapForValue(1, "ham") == 3
     assert tokens.countOverlapForValue(2, "ham") == 2
     assert tokens.countOverlapForValue(1, "spam") == 2
     assert tokens.countOverlapForValue(2, "spam") == 4
     assert tokens.countOverlapForValue(2, "egg") == 0
     
     tokens.addLettersWithValue(3, "egg")
     assert tokens.countCharacterForValue(3, 'g') == 2
     assert tokens.countOverlapForValue(3, "egg") == 3
     tokens.deleteLowestLetters('ag')
     assert tokens.countCharacterForValue(1, 'a') == 0
     assert tokens.countCharacterForValue(2, 'a') == 1
     assert tokens.countCharacterForValue(3, 'g') == 1
     
     tokens.deleteLowestLetters('mm')
     assert tokens.countCharacterForValue(1, 'm') == 0
     assert tokens.countCharacterForValue(2, 'm') == 0
     assert tokens.countCharacterForValue(3, 'm') == 0
 def testDecrement(self):
     tokens = Tokens()
     tokens.addLettersWithValue(2, "ham")
     tokens.addLettersWithValue(3, "spam")
     
     tokens.decrement()
     assert tokens.countOverlapForValue(1, "ham") == 3
     assert tokens.countOverlapForValue(2, "spam") == 4
     
     tokens.decrement()
     assert tokens.countOverlapForValue(0, "ham") == 3
     assert tokens.countOverlapForValue(1, "spam") == 4
     
     tokens.decrement()
     assert tokens.countOverlapForValue(0, "ham") == 3
     assert tokens.countOverlapForValue(0, "spam") == 4
     
     pass