def test_parse_subject(): test = [('verb', 'eat'), ('noun', 'bear')] assert_equal(parser.parse_subject(test), ('noun', 'player')) test2 = [('noun', 'bear'), ('verb', 'eat')] assert_equal(parser.parse_subject(test2), ('noun', 'bear')) test3 = [('direction', 'up')] assert_raises(parser.ParseError, parser.parse_subject, test3)
def test_parse_subject(): assert_equal(parser.parse_subject([('noun', 'butterfly')]), ('noun', 'butterfly')) assert_equal(parser.parse_subject([('verb', 'flutter')]), ('noun', 'player')) assert_raises(parser.ParserError, parser.parse_subject, [('direction', 'left')])
def test_parse_subject(): scanner = lexicon.scan("the bear go") assert_equal(scanner, [('stop', 'the'), ('noun', 'bear'), ('verb', 'go')]) assert_equal(parser.parse_subject(scanner), ('noun', 'bear')) assert_equal(scanner, [('verb', 'go')]) scanner = lexicon.scan("the go bear") assert_equal(scanner, [('stop', 'the'), ('verb', 'go'), ('noun', 'bear')]) assert_equal(parser.parse_subject(scanner), ('noun', 'player')) assert_equal(scanner, [('verb', 'go'), ('noun', 'bear')])
def test_parse_subject(): # test that parse_subject returns ('noun', 'player') when there is no noun before finding a verb word_list = [('stop', 'at'), ('stop', 'the'), ('verb', 'run'), ('stop', 'is')] assert_equal(parser.parse_subject(word_list), ('noun', 'player')) # test that parse_subject returns the correct subject tuple if a noun is found before a verb word_list = [('stop', 'at'), ('stop', 'the'), ('noun', 'bear'), ('stop', 'is')] assert_equal(parser.parse_subject(word_list), ('noun', 'bear')) # test that parse_subject raises an error if word type other than a noun or a verb is found first word_list = [('stop', 'at'), ('stop', 'the'), ('number', 123456), ('stop', 'is')] assert_raises(parser.ParserError, parser.parse_subject, 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(): 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_parse_subject(): # parse word lists with no verb after initial stops word_list = lexicon.scan("After from south") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) word_list = lexicon.scan("After from") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) word_list = lexicon.scan("bear After from") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) # parse word lists with no obj after: initial stops, verb and further stops word_list = lexicon.scan("After at go") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) word_list = lexicon.scan("After at go at") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) word_list = lexicon.scan("After at go at 191919") assert_raises(ParserError, parser.parse_subject, word_list, ("", "")) # parse a correct word list and a subject word_list = lexicon.scan("at kill from bear") sentence = parser.parse_subject(word_list, ("noun", "Player")) assert_equal(sentence.subject, "Player") assert_equal(sentence.object, "bear") assert_equal(sentence.verb, "kill")
def test_parse_subject(): word_list = [('verb', 'kill'), ('direction', 'north')] subj = ('noun', 'princess') verb = ('verb', 'kill') obj = ('direction', 'north') obj_sent = Sentence(subj, verb, obj) #This is the first instance of Sentence() assert_equal(parser.parse_subject(word_list, subj), obj_sent)
def test_subject(): test_list = [('verb', 'eat'), ('stop', 'the'), ('noun', 'princess')] test_subj = ('noun', 'bear') result = parser.parse_subject(test_list, test_subj) assert_equal(result.subject, 'bear') assert_equal(result.verb, 'eat') assert_equal(result.object, 'princess')
def test_parse_sentence(): word_list = [("noun", "bear"), ("stop", "the"), ("verb", "eat"), ("noun", "honey")] subj = parser.parse_subject(word_list) verb = parser.parse_verb(word_list) obj = parser.parse_object(word_list) x = parser.Sentence(subj, verb, obj) y = parser.Sentence(("noun", "bear"), ("verb", "eat"), ("noun", "honey")) assert_equal(x.subject, y.subject) assert_equal(x.object, y.object) assert_equal(x.verb, y.verb)
def test_parse_subject(): word_list_1 = [('noun', 'dog'), ('verb', 'go'), ('direction', 'north'), ('stop', 'with'), ('noun', 'bear')] result = parser.parse_subject(word_list_1) assert_equal(result, ('noun', 'dog')) # Next word is a noun word_list_2 = [('stop', 'the'), ('noun', 'cows'), ('verb', 'go'), ('direction', 'north'), ('stop', 'with'), ('noun', 'bears')] result = parser.parse_subject(word_list_2) assert_equal(result, ('noun', 'cows')) # Next word is a noun, skip the 'stop' word_list_3 = [('adverb', 'quickly'), ('verb', 'run'), ('direction', 'north'), ('stop', 'with'), ('stop', 'the'), ('noun', 'bears')] assert_raises(parser.ParserError, parser.parse_subject, word_list_3) word_list_4 = [('verb', 'run'), ('direction', 'north'), ('stop', 'with'), ('stop', 'the'), ('noun', 'bear')] result = parser.parse_subject(word_list_4) assert_equal(result, ('noun', 'player'))
def test_subj(): assert_equal(parser.parse_subject(lexicon.scan("door in the forest")), ('noun', 'door')) assert_equal(parser.parse_subject(lexicon.scan("Door in the forest")), ('noun', 'Door')) assert_equal(parser.parse_subject(lexicon.scan("in the cabinet")), ('noun', 'cabinet')) assert_equal(parser.parse_subject(lexicon.scan("in the kill cabinet")), ('noun', 'player')) assert_equal(parser.parse_subject(lexicon.scan("kill the forest")), ('noun', 'player')) assert_equal( parser.parse_subject(lexicon.scan("in the cabinet kill bear")), ('noun', 'cabinet')) assert_raises(Exception, parser.parse_subject, lexicon.scan("From the north"))
def test_parse_subject(): word_list = lexicon.scan('eat door') subj = ('noun', 'bear') s = parser.parse_subject(word_list, subj)
def test_parse_subject(): word_list = lexicon.scan('the bear') assert_equal(parser.parse_subject(word_list), ('noun', 'bear'))
def test_parse_subject(): wordlist = [("verb", "kill"), ("noun", "princess")] subj = ("noun", "player") result = parser.parse_subject(wordlist, subj) assert_equal((result.subject, result.verb, result.object), ("player", "kill", "princess"))
def TestParseSubject(): inputsent = lexicon.scan("eat bear castle") sentence = parser.Sentence(inputsent[0], inputsent[1], inputsent[2]) resultsentence = parser.parse_subject(inputsent, inputsent[0]) #assert_raises(parser.ParserError,parser.parse_subject,inputsent,inputsent[0]) assert_equal(sentence.subject, resultsentence.subject)
def test_parse_subject(): word_list = lexicon.scan("eat door") subj = ("noun", "bear") s = parser.parse_subject(word_list, subj) assert_equal(s.to_tuple(), ("bear", "eat", 1, "door"))
def test_parse_subject(): assert_equal(parser.parse_subject(word_list), 'test')
def test_parse_subject(): sentence = parser.parse_subject([('verb', 'eat'), ('noun', 'princess')], ('noun', 'bear')) assert_equal(sentence.subject, 'bear') assert_equal(sentence.verb, 'eat') assert_equal(sentence.object, 'princess')
def testing_parse_subject(): '''testing the parse_subject function.''' word_list = lexicon.scan('kill princess') subj = ('noun', 'bear') foo = parser.parse_subject(word_list, subj) assert_equal(foo.assign_tuple(), ('bear', 'kill', 'princess'))
def test_parse_subject(): word_list = lexicon.scan('eat door') subj = ('noun', 'bear') s = parser.parse_subject(word_list, subj) assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
def test_parse_subject(): x = parser.parse_subject([("noun", "bear")]) assert_equal(x, ("noun", "bear")) y = parser.parse_subject([("verb", "eat")]) assert_equal(y, ("noun", "player"))