def test_parse_object(): a_word_list = lexicon.scan("door some noun.") b_word_list = lexicon.scan("north me if I failed.") c_word_list = lexicon.scan("at kill world") assert_equal(parser.parse_object(a_word_list), ('noun','door')) assert_equal(parser.parse_object(b_word_list), ('direction','north')) assert_raises(parser.ParserError, parser.parse_object, c_word_list)
def test_parse_object(): vector = lexicon.scan('unknown eat door') assert_raises(parser.ParseError, parser.parse_object, vector) vector = lexicon.scan('princess go door') assert_equal(parser.parse_object(vector), ('noun', 'princess')) vector = lexicon.scan('from north') assert_equal(parser.parse_object(vector), ('direction', 'north'))
def test_parse_object(self): self.assertRaises(parser.ParserError, parser.parse_object, [('verb', 'flies')]) self.assertEqual(parser.parse_object([('noun', 'paper')]), ('noun', 'paper')) self.assertEqual(parser.parse_object([('direction', 'north')]), ('direction', 'north'))
def test_parse_object(): word_list = lexicon.scan('the door') assert_equal(parser.parse_object(word_list), ('noun', 'door')) word_list = lexicon.scan('the east') assert_equal(parser.parse_object(word_list), ('direction', 'east')) word_list = lexicon.scan('the it') assert_raises(parser.ParserError, parser.parse_object, word_list)
def test(): assert_equal(parser.peek(lexicon.scan('go kill the princess')), 'verb') assert_equal(parser.match(lexicon.scan('go kill the princess'), 'verb'), ('verb', 'go')) assert_equal(parser.skip(lexicon.scan('go kill the princess'), 'verb'), None) assert_equal(parser.parse_verb(lexicon.scan('go kill the princess')), ('verb', 'go')) assert_raises(parser.ParserError, parser.parse_verb, ('noun', 'princess')) assert_equal(parser.parse_object(lexicon.scan('the princess')), ('noun', 'princess')) assert_equal(parser.parse_object(lexicon.scan('the north')), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, lexicon.scan('go kill the princess')) subj = 'bear' assert_equal( parser.parse_sentence( lexicon.scan('the bear eat the princess')).subject, subj) ver = 'eat' assert_equal( parser.parse_sentence(lexicon.scan('the bear eat the princess')).verb, ver) obj = 'princess' assert_equal( parser.parse_sentence( lexicon.scan('the bear eat the princess')).object, obj)
def test_object(): assert_equal(parser.parse_object([('direction', 'north')]), ('direction', 'north')) assert_equal(parser.parse_object([('noun', 'bear')]), ('noun', 'bear')) assert_raises(parser.ParserError, parser.parse_object, [('verb', 'kill'), ('stop', 'of'), ('verb', 'go')])
def test_parse_object(): word_list = [('noun', 'door'), ('verb', 'go'), ('direction', 'north'), ('stop', 'at')] assert_equal(parser.parse_object(word_list), ('noun', 'door')) word_list = [('direction', 'north'), ('stop', 'at')] assert_equal(parser.parse_object(word_list), ('direction', 'north')) word_list = [('verb', 'go'), ('direction', 'north'), ('stop', 'at')] assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_parse_object(): a_word_list = lexicon.scan("door some noun.") b_word_list = lexicon.scan("north me if I failed.") c_word_list = lexicon.scan("at kill world") assert_equal(parser.parse_object(a_word_list), ('noun', 'door')) assert_equal(parser.parse_object(b_word_list), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, c_word_list)
def parse_object_tests(): word_list = [('stop', 'stop_a'), ('verb', 'verb_a'), ('noun', 'noun_a'), ('direction', 'direction_a')] assert_raises(parser.ParserError, parser.parse_object, word_list) parser.parse_verb(word_list) assert_equals(word_list, [('noun', 'noun_a'), ('direction', 'direction_a')]) assert_equals(parser.parse_object(word_list), ('noun', 'noun_a')) assert_equals(parser.parse_object(word_list), ('direction', 'direction_a'))
def test_parse_object(): wordlist = [('stop', 'the'), ('noun', 'bear'), ('direction', 'north')] result = parser.parse_object(wordlist) assert_equal(result, ('noun', 'bear')) assert_equal(wordlist, [('direction', 'north')]) result = parser.parse_object(wordlist) assert_equal(result, ('direction', 'north')) assert_equal(wordlist, [])
def test_parse_object(): word_list = lexicon.scan("the in of stop") assert_raises(parser.ParserError, parser.parse_object, word_list) word_list = lexicon.scan("the princess in of stop") assert_equal(("noun", "princess"), parser.parse_object(word_list)) word_list = lexicon.scan("north of the bear") assert_equal(("direction", "north"), parser.parse_object(word_list)) assert_raises(parser.ParserError, parser.parse_object, [])
def test_parse_object(): word_list = lexicon.scan("at the bear") assert ('noun', "bear") == parser.parse_object(word_list) word_list = lexicon.scan("at the north") assert ('direction', "north") == parser.parse_object(word_list) word_list = lexicon.scan("at the eat")
def test_parse_object(): result = parser.parse_object(lexicon.scan("at in bear kill 34587")) assert_equal(result, ('noun', 'bear')) result = parser.parse_object(lexicon.scan("at in east kill 34587")) assert_equal(result, ('direction', 'east')) word_list = lexicon.scan("at in kill bear 34587") assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_parse_object(): word_list = lexicon.scan("the in of stop") assert_raises(parser.ParserError, parser.parse_object, word_list) word_list = lexicon.scan("the princess in of stop") assert_equal(('noun', 'princess'), parser.parse_object(word_list)) word_list = lexicon.scan("north of the bear") assert_equal(('direction', 'north'), parser.parse_object(word_list)) assert_raises(parser.ParserError, parser.parse_object, [])
def test_parse_object(): word_list = [('stop', 'the'), ('noun', 'cow')] assert_equal(parser.parse_object(word_list), ('noun', 'cow')) assert_equal(word_list, []) dir_list = [('stop', 'way'), ('direction', 'up')] parser.parse_object(dir_list) assert_equal(dir_list, []) error_list = [('stop', 'way'), ('verb', 'run')] assert_raises(parser.ParserError, parser.parse_object, error_list)
def test_parse_object(): raw_word_list = [('noun', 'gogo'), ('direction', 'up')] assert_equal(parser.parse_object(raw_word_list), ('noun', 'gogo')) expected_error_message = "Expected a noun or direction next." error_word_list = [('oh', 'go'), ('direction', 'up')] with assert_raises(parser.ParserError) as error: assert_equal(parser.parse_object(error_word_list), ('oh', 'go')) assert_equal(error.exception.message, expected_error_message)
def test_object(): word_list = [('stop', 'the'), ('noun', 'princess')] assert_equal(parser.parse_object(word_list), ('noun', 'princess')) word_list = [('stop', 'the'), ('direction', 'south')] assert_equal(parser.parse_object(word_list), ('direction', 'south')) word_list = [('verb', 'kill'), ('noun', 'bear')] assert_raises(Exception, parser.parse_object, word_list)
def test_parse_objects(): assert_equal(parser.parse_object([('stop', 'the'), ('noun', 'BMO')]), ('noun', 'BMO')) assert_equal( parser.parse_object([('stop', 'the'), ('noun', 'Lil Gideon')]), ('noun', 'Lil Gideon')) assert_equal( parser.parse_object([('stop', 'the'), ('direction', 'south')]), ('direction', 'south'))
def test_parse_object(): word_list1 = [("stop", "at"), ("stop", "the"), ("noun", "honey"), ("direction", "north")] word_list2 = [("direction", "north"), ("verb", "go"), ("stop", "at")] word_list3 = [("stop", "at"), ("stop", "the"), ("verb", "go")] word_list4 = [] assert_equal(parser.parse_object(word_list1), ("noun", "honey")) assert_equal(parser.parse_object(word_list2), ("direction", "north")) assert_raises(parser.ParserError, parser.parse_object, word_list3) assert_raises(parser.ParserError, parser.parse_object, word_list4)
def test_parse_object(): object_ = parser.parse_object([('noun', 'princess')]) assert_equal(object_, ('noun', 'princess')) object_ = parser.parse_object([('direction', 'west')]) assert_equal(object_, ('direction', 'west')) object_ = parser.parse_object([('number', 1234)]) assert_raises(parser.ParserError, parser.parse_object, [('verb', 'go')])
def test_parsesobject(): testsentence="the kill princess eat the bear" result=lexicon.scan(testsentence) assert_raises(parser.ParserError, parser.parse_object, result) testsentence="the princess eat the bear" result=lexicon.scan(testsentence) assert_equal(parser.parse_object(result), ('noun','princess')) testsentence="north" result=lexicon.scan(testsentence) assert_equal(parser.parse_object(result), ('direction','north'))
def test_parse_object(): word_list = [('stop', 'of'), ('stop', 'the'), ('noun', 'honey')] assert_equal(parser.parse_object(word_list), ('noun', 'honey')) word_list2 = [('stop', 'of'), ('stop', 'the'), ('direction', 'north')] assert_equal(parser.parse_object(word_list2), ('direction', 'north')) assert_raises(Exception, parser.parse_object, [('stop', 'of'), ('stop', 'the'), ('verb', 'run')])
def test_parsesobject(): testsentence = "the kill princess eat the bear" result = lexicon.scan(testsentence) assert_raises(parser.ParserError, parser.parse_object, result) testsentence = "the princess eat the bear" result = lexicon.scan(testsentence) assert_equal(parser.parse_object(result), ('noun', 'princess')) testsentence = "north" result = lexicon.scan(testsentence) assert_equal(parser.parse_object(result), ('direction', 'north'))
def test_parse_object(): sentence = lexicon.scan("door") assert_equal(parser.parse_object(sentence), ('noun', 'door')) sentence = lexicon.scan("in the bear") assert_equal(parser.parse_object(sentence), ('noun', 'bear')) sentence = lexicon.scan("in the the north bear") assert_equal(parser.parse_object(sentence), ('direction', 'north')) sentence = lexicon.scan("for the go bear") with assert_raises(parser.ParserError): parser.parse_object(sentence)
def test_parse_object(): # When object is a noun word_list = [('stop', 'the'), ('noun', 'bear')] word = parser.parse_object(word_list) assert_equal(('noun', 'bear'), word) # When object is a direction word_list = [('stop', 'the'), ('direction', 'north')] word = parser.parse_object(word_list) assert_equal(('direction', 'north'), word) # When object is neither a noun or direction word_list = [('stop', 'the'), ('verb', 'stop')] assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_object(): assert_equal( parser.parse_object([("noun", "bear")]), ('noun', 'bear') ) assert_equal( parser.parse_object([("noun", "princess"), ("error", "peach")]), ('noun', 'princess') ) assert_raises( parser.ParserError, # expected error parser.parse_object, # function to run [("verb", "go"), ("stop", "the")] # arg for function )
def test_sentence(): subj = parser.parse_subject([('stop', 'the'), ('noun', 'bear')]) verb = parser.parse_verb([('stop', 'the'), ('verb', 'run'), ('direction', 'north')]) obj = parser.parse_object([('stop', 'the'), ('direction', 'north')]) sentence = parser.Sentence(subj, verb, obj) assert_equal(sentence.subject, "bear") assert_equal(sentence.verb, "run") assert_equal(sentence.object, "north")
def test_object(): # 'north': object == 'north' assert_equal( parser.parse_object([ ('direction', 'north') ]), ('direction', 'north') ) # 'honey quickly': object == 'honey' ('quickly' irrelevant) assert_equal( parser.parse_object([ ('noun', 'honey'), ('error', 'quickly') ]), ('noun', 'honey') ) # 'the front': ParserError assert_raises( parser.ParserError, parser.parse_object, [('stop', 'the'), ('error', 'front')] )
def test_parse_object(): word_list = lexicon.scan("the north eat princess") assert_equal(('direction', 'north'), parser.parse_object(word_list))
def test_parse_object(): failing_sentence = [('verb', 'eat'), ('stop', 'a'), ('noun', 'bagel')] passing_sentence = [('stop', 'a'), ('noun', 'bagel')] assert_equal(parser.parse_object(passing_sentence), ('noun', 'bagel')) assert_raises(parser.ParserError, parser.parse_object, failing_sentence)
def test_object(): words = lexicon.scan("will bear west next") assert_equal(parser.parse_object(words), ('noun', 'bear')) assert_equal(parser.parse_object(words), ('direction', 'west')) assert_raises(parser.ParserError, parser.parse_object, words)
def test_parse_object(): assert_equal(parser.parse_object([('stop', 'the'), ('noun', 'bear'), ('direction', 'north')]), ('noun', 'bear')) assert_equal(parser.parse_object([('stop', 'the'), ('direction', 'north')]), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, [('foo', 'bar')])
def test_parse_object(): assert_equal(parser.parse_object([('noun', 'hip')]), ('noun', 'hip')) assert_equal(parser.parse_object([('stop', 'to'), ('noun', 'arm')]), ('noun', 'arm')) assert_raises(parser.ParserError, parser.parse_object, [('verb', 'bear')])
def test_parse_object(): word_list2 = lexicon.scan("in the west") result = parser.parse_object(word_list2) assert_equal(result, ('direction', 'west')) assert_raises(parser.ParserError, parser.parse_object, word_list2)
def test_parse_object(): assert_equal(parser.parse_object(word_list_1), ('noun', 'princess')) assert_equal(parser.parse_object(word_list_5), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, word_list_6)
def test_parse_object(): word_list = lexicon.scan('north') assert_equal(parser.parse_object(word_list), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, [('ddirection', 'north')])
def test_pobject(): assert_equal(parser.parse_object(lexicon.scan("north princess")),('direction','north')) assert_equal(parser.parse_object(lexicon.scan("princess bear")),('noun','princess')) assert_raises(Exception, parser.parse_object, lexicon.scan("Eat the bear"))
def test_parse_subject(): word_list = lexicon.scan('bear') assert_equal(parser.parse_object(word_list), ('noun', 'bear')) assert_raises(parser.ParserError, parser.parse_object, [('nNoun', 'bear')])
def test_parse_object(): assert_equal(parser.parse_object([('noun', 'bear')]), ('noun', 'bear'))
# pass def test_peek(): sample_list = [("first", "world"), ("hello", "world")] expected = "first" calculated = peek(sample_list) assert_equal(expected, calculated) # def test_match(): # assert_equal(match(("", ""), (""))) # test whether first element of first tuple = expecting # def test_skip(): # pass # No test # def test_parse_verb(): # pass # def test_parse_subject(): # pass # def test_parse_sentence(): # pass test_peek() parse_object([("door", "bear"), ("door", "bear")])
def test_parse_object(): assert_equal(parser.parse_object(lexicon.scan("in the princess")), ('noun', 'princess')) result = parser.parse_object(lexicon.scan("in the north")) assert_equal(result, ('direction', 'north'))
def test_parse_object_direction_next(): word_list = [('stop', 'the'), ('direction', 'north'), ('object', 'coins')] direction_next = parser.parse_object(word_list) assert_equal(direction_next, ('direction', 'north'))
def test_parse_object(): word_list = [('noun', 'player'), ('stop', 'the'), ('direction', 'north'), ('verb', 'open'), ('noun', 'door')] assert_equal(parser.parse_object(word_list), ('noun', 'player')) assert_equal(parser.parse_object(word_list), ('direction', 'north')) assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_parse_sentence(): word_list = lexicon.scan("princess kill the bear") subj = parser.parse_subject(word_list) verb = parser.parse_verb(word_list) obj = parser.parse_object(word_list) assert parser.Sentence(subj, verb, obj)
def test_parse_object_noun_next(): word_list = [('stop', 'the'), ('noun', 'hammer'), ('object', 'coins')] noun_next = parser.parse_object(word_list) assert_equal(noun_next, ('noun', 'hammer'))