def test_parse_sentence(): word_list = lexicon.scan('the bear eat door') s = parser.parse_sentence(word_list) word_list = lexicon.scan('in eat door') s = parser.parse_sentence(word_list) word_list = lexicon.scan('north eat door') assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_parse_sentence(): word_list = lexicon.scan("the bear eat door") s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ("bear", "eat", 1, "door")) word_list = lexicon.scan("in eat door") s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ("player", "eat", 1, "door")) word_list = lexicon.scan("north eat door") assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_parse_sentence(): word_list = lexicon.scan('the bear eat door') s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door')) word_list = lexicon.scan('in eat door') s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ('player', 'eat', 1, 'door')) word_list = lexicon.scan('north eat door') assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def testing_parse_sentence(): '''testing the parse_sentence function.''' word_list = lexicon.scan('the princess eat bear') foo = parser.parse_sentence(word_list) assert_equal(foo.assign_tuple(), ('princess', 'eat', 'bear')) word_list = lexicon.scan('it kill bear') foo = parser.parse_sentence(word_list) assert_equal(foo.assign_tuple(), ('player', 'kill', 'bear')) word_list = lexicon.scan('east it go') # here we don't need to assign to 'foo' as it goes straight to else # and doesn't return anything unlike the above assert_raises(parser.ParseError, parser.parse_sentence, word_list)
def test_sentence(): word_list = lexicon.scan("open the door") result1 = parser.parse_sentence(word_list) result2 = parser.parse_subject(lexicon.scan("open the door"), ("noun", "player")) assert_equal(result1.subject, result2.subject) assert_equal(result1.verb, result2.verb) assert_equal(result1.object, result2.object) word_list = lexicon.scan("now bear go east") result1 = parser.parse_sentence(word_list) result2 = parser.parse_subject(lexicon.scan("go east"), ("noun", "bear")) assert_equal(result1.subject, result2.subject) assert_equal(result1.verb, result2.verb) assert_equal(result1.object, result2.object)
def test_sentence(): test_list = [('stop', 'a'),('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'princess')] result = parser.parse_sentence(test_list) assert_equal(result.subject, 'bear') assert_equal(result.verb, 'eat') assert_equal(result.object, 'princess') test_list = [('verb', 'shoot'), ('stop', 'the'), ('noun', 'bear')] result = parser.parse_sentence(test_list) assert_equal(result.subject, 'player') assert_equal(result.verb, 'shoot') assert_equal(result.object, 'bear') test_list = [('direction', 'east'), ('stop', 'the'), ('noun', 'bear')] assert_raises(parser.ParserError, parser.parse_sentence, test_list)
def test_sentence(): word_list = lexicon.scan("open the door") result1 = parser.parse_sentence(word_list) result2 = parser.parse_subject(lexicon.scan("open the door"), ('noun', 'player')) assert_equal(result1.subject, result2.subject) assert_equal(result1.verb, result2.verb) assert_equal(result1.object, result2.object) word_list = lexicon.scan("now bear go east") result1 = parser.parse_sentence(word_list) result2 = parser.parse_subject(lexicon.scan("go east"), ('noun', 'bear')) assert_equal(result1.subject, result2.subject) assert_equal(result1.verb, result2.verb) assert_equal(result1.object, result2.object)
def test_sentence(): test_list = [('stop', 'a'), ('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'princess')] result = parser.parse_sentence(test_list) assert_equal(result.subject, 'bear') assert_equal(result.verb, 'eat') assert_equal(result.object, 'princess') test_list = [('verb', 'shoot'), ('stop', 'the'), ('noun', 'bear')] result = parser.parse_sentence(test_list) assert_equal(result.subject, 'player') assert_equal(result.verb, 'shoot') assert_equal(result.object, 'bear') test_list = [('direction', 'east'), ('stop', 'the'), ('noun', 'bear')] assert_raises(parser.ParserError, parser.parse_sentence, test_list)
def test_proper_sentence(): word_list = [('noun', 'bear'), ('verb', 'open'), ('stop', 'the'), ('noun', 'door'), ('error', 'and'), ('error', 'smack'), ('stop', 'the'), ('stop', 'in'), ('stop', 'the'), ('error', 'nose')] sentence = parser.parse_sentence(word_list) assert_equal(sentence.sentence(), 'bear open door')
def test_parse_sentence(): sen1 = parser.parse_sentence([('verb', 'kill'), ('stop', 'of'), ('noun', 'bear')]) assert_equal(sen1.subject, 'player') assert_equal(sen1.verb, 'kill') assert_equal(sen1.object, 'bear') sen2 = parser.parse_sentence([('noun', 'princess'), ('stop', 'of'), ('verb', 'go'), ('direction', 'west')]) assert_equal(sen2.subject, 'princess') assert_equal(sen2.verb, 'go') assert_equal(sen2.object, 'west') assert_raises(parser.ParserError, parser.parse_sentence, [('stop', 'the'), ('stop', 'of'), ('direction', 'west'), ('verb', 'go')])
def test_parse_sentence(): word_list_1 = [('verb', 'run'), ('direction', 'north'), ('stop', 'with'), ('stop', 'the'), ('noun', 'bear')] result = parser.parse_sentence(word_list_1) assert_equal(result.subject, ('player')) assert_equal(result.verb, ('run')) assert_equal(result.object, ('north'))
def test_parse_sentence(): result = lexicon.scan("bear eat the princess") sen = parser.parse_sentence(result) #ok = parser.Sentence("bear","eat","princess") #assert_equal(sen, parser.Sentence("bear","eat","princess")) assert_equal(sen.subject, "bear") assert_equal(sen.verb, "eat") assert_equal(sen.object, "princess")
def test_parse_sentence(): word_list = lexicon.scan('princess kill bear') print(word_list) s = parser.parse_sentence(word_list) print(s.subject) assert ('noun', 'princess') == s.subject assert ('verb', 'kill') == s.verb assert ('noun', 'bear') == s.object
def test_parse_sentence(): word_list = lexicon2.scan('kill north the') subj = ('noun', 'player') verb = ('verb', 'kill') obj = ('direction', 'north') obj_sent = Sentence(subj, verb, obj) assert_equal(parser.parse_sentence(word_list), obj_sent) assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_parse_sentence(): # parse an empty word list word_list = [] assert_raises(ParserError, parser.parse_sentence, word_list) # parse other wrong word lists word_list = lexicon.scan("999 go bear") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("go kill bear") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("stop") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("bear") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("Princess go") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("Princess bear") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("Princess jjkjkj ") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("Princess go kill bear") assert_raises(ParserError, parser.parse_sentence, word_list) word_list = lexicon.scan("Princess go now") assert_raises(ParserError, parser.parse_sentence, word_list) # parse correct word lists word_list = lexicon.scan("PrinceSS go from bear") sentence = parser.parse_sentence(word_list) assert_equal(sentence.subject, "PrinceSS") assert_equal(sentence.object, "bear") assert_equal(sentence.verb, "go") word_list = lexicon.scan("stop at the door") sentence = parser.parse_sentence(word_list) assert_equal(sentence.subject, "player") assert_equal(sentence.object, "door") assert_equal(sentence.verb, "stop")
def test_game_sentences(): sentences = [] sentences.append( (parser.parse_sentence(lexicon.scan("The bear eat the princess")), parser.Sentence(('noun', 'bear'), ('verb', 'eat'), ('noun', 'princess')))) sentences.append((parser.parse_sentence(lexicon.scan("Kill the bear")), parser.Sentence(('noun', 'player'), ('verb', 'Kill'), ('noun', 'bear')))) sentences.append( (parser.parse_sentence(lexicon.scan("The bear go to 1234")), parser.Sentence(('noun', 'bear'), ('verb', 'go'), ('number', 1234)))) sentences.append((parser.parse_sentence( lexicon.scan("The bear stop a door from opening")), parser.Sentence(('noun', 'bear'), ('verb', 'stop'), ('noun', 'door')))) for i in sentences: assert_equal(sentence_equivalent(i[0], i[1]), True)
def test_bear_go_FNORD_north(): tuples = lexicon.scan("bear go FNORD north") parseout = parser.parse_sentence(tuples) assert_equals(parseout, parser.Sentence(('number', 1), ('noun', 'bear'), ('verb', 'go'), ('number', 1), ('direction', 'north')))
def test_princess_eat_the_bear(): tuples = lexicon.scan("princess eat the bear") parseout = parser.parse_sentence(tuples) assert_equals(parseout, parser.Sentence(('number', 1), ('noun', 'princess'), ('verb', 'eat'), ('number', 1), ('noun', 'bear')))
def test_lexluthor_stole_40_cakes(): tuples = lexicon.scan("lexluthor stole 40 cakes") parseout = parser.parse_sentence(tuples) assert_equals(parseout, parser.Sentence(('number', 1), ('noun', 'lexluthor'), ('verb', 'stole'), ('number', 40), ('noun', 'cakes')))
def test_40_lexluthors_stole_1_cake(): tuples = lexicon.scan("40 lexluthors stole 1 cake") parseout = parser.parse_sentence(tuples) assert_equals(parseout, parser.Sentence(('number', 40), ('noun', 'lexluthors'), ('verb', 'stole'), ('number', 1), ('noun', 'cake')))
def test_parse_sentence(): def check(sent, subject, verb, object): assert_equal(sent.subject, subject) assert_equal(sent.verb, verb) assert_equal(sent.object, object) sent = parser.parse_sentence(lexicon.scan("Princess kill the bear")) check(sent, "Princess", "kill", "bear") assert_raises(Exception, parser.parse_sentence, (lexicon.scan('moo')))
def test_parse_sentence(): # test parse_sentence with an incorrect structure/empty raises an error word_list = [('verb', 'eats'), ('verb', 'jumps')] assert_raises(parser.ParserError, parser.parse_sentence, word_list) word_list = [] assert_raises(parser.ParserError, parser.parse_sentence, word_list) # test parse_sentence with a correct sentence structure word_list = [('stop', 'then'), ('verb', 'eats'), ('stop', 'lots'), ('stop', 'of'), ('noun', 'honey')] test_sentence = parser.parse_sentence(word_list) assert_equal(test_sentence.subject, 'player') assert_equal(test_sentence.verb, 'eats') assert_equal(test_sentence.obj, 'honey')
def test_2(): sentence = parser.parse_sentence(lexicon.scan("bear go west")) assert_equal(sentence.subject, 'bear') assert_equal(sentence.verb, 'go') assert_equal(sentence.object, 'west')
def test_numbers(): word_list = lexicon.scan('the bear eat door') s = parser.parse_sentence(word_list)
def TestParseSentence(): inputsent = lexicon.scan("the bear eat") assert_raises(parser.ParserError, parser.parse_sentence, inputsent) inputsent = lexicon.scan("bear eat castle") assert_equal('bear', parser.parse_sentence(inputsent).subject)
def test_parse_sentence(): assert_equal( parser.parse_sentence([('noun', 'butterfly'), ('stop', 'of'), ('verb', 'drinks'), ('noun', 'soup')]), parser.Sentence(('noun', 'butterfly'), ('verb', 'drinks'), ('noun', 'soup')))
def test_1(): sentence = parser.parse_sentence(lexicon.scan("eat the bear")) assert_equal(sentence.subject, 'player') assert_equal(sentence.verb, 'eat') assert_equal(sentence.object, 'bear')
def test_unknown_words(): word_list = lexicon.scan('the bear eat door') s = parser.parse_sentence(word_list)
def test_parse_sentence(): test = [('noun', 'bear'), ('verb', 'eat'), ('noun', 'honey')] result = parser.parse_sentence(test) assert_equal(result.subject, ('bear')) assert_equal(result.verb, ('eat')) assert_equal(result.object, ('honey'))
def empty_test_two(): empty_sentence_two = parser.parse_sentence(lexicon.scan(""))
def stop_test(): stop_sentence = parser.parse_sentence(lexicon.scan("bear go the in of from at it north")) assert_equal("bear", stop_sentence.subject) assert_equal("go", stop_sentence.verb) assert_equal("north", stop_sentence.object)
def test_stops(): t_list = lexicon.scan("kill the bear") result = parser.parse_sentence(t_list) assert_equal(result.subject, 'player') assert_equal(result.verb, 'kill') assert_equal(result.object, 'bear')
def test_parse_sentence(): word_list = [('verb', 'run'), ('direction', 'north')] sentence = parser.parse_sentence(word_list) assert_equal(sentence.subject, 'player') assert_equal(sentence.verb, 'run') assert_equal(sentence.object, 'north')
def test_parse_sentence(): wordlist = [("verb", "kill"), ("noun", "princess")] result = parser.parse_sentence(wordlist) assert_equal((result.subject, result.object, result.verb), ("player", "princess", "kill"))
def test_basic(): simple_sentence = parser.parse_sentence(lexicon.scan("go north")) assert_equal("player", simple_sentence.subject) assert_equal("go", simple_sentence.verb) assert_equal("north", simple_sentence.object)
def test_unknown_words(): word_list = lexicon.scan('xxx the xxx bear eat xxx door xxx') s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
def empty_test_one(): empty_sentence_one = parser.parse_sentence("")
def test_direction_sentence(): t_list = lexicon.scan("go north") result = parser.parse_sentence(t_list) assert_equal(result.subject, 'player') assert_equal(result.object, 'north') assert_equal(result.verb, 'go')
def error_tuple_test(): error_tuple_setence = parser.parse_sentence(lexicon.scan("bear punch the wall"))
def test_parse_sentence(): assert_equal(parser.parse_sentence(word_list), '')
def test_number(): word_list = lexicon.scan("xxx the xxx bear xxx eat xxx 5 xxx door xxx") s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ("bear", "eat", 5, "door"))
def test_objectexception(): result = lexicon.scan("bear eat the the eat") sen = parser.parse_sentence(result)
def test_numbers(): word_list = lexicon.scan('xxx the xxx bear xxx eat xxx 5 xxx door xxx') s = parser.parse_sentence(word_list) assert_equal(s.to_tuple(), ('bear', 'eat', 5, 'door'))
def test_parse_sentence2(): result = parser.parse_sentence([('noun', 'bear'), ('verb', 'eat'), ('stop', 'the'), ('noun', 'honey')]) assert_equal(result, parser.Sentence(subject='bear', verb='eat', obj='honey'))
def test_parse_sentence(): result = parser.parse_sentence([('verb', 'run'), ('direction', 'north')]) assert_equal(result, parser.Sentence('player', 'run', 'north'))
def test_parse_sentence(): scanner = lexicon.scan("1 bear go north") s = parser.parse_sentence(scanner) assert_equal(s.make_tuple(), (1, 'bear', 'go', 'north'))
def test_verbexception(): result = lexicon.scan("bear the princess") sen = parser.parse_sentence(result)