def test_numbers(): assert_equal(lexicon.scan("1234"), [('number', 1234)]) result = lexicon.scan("3 91234") assert_equal(result, [ ('number', 3), ('number', 91234), ])
def test_nouns(): assert_equal(lexicon.scan("bear"), [('noun', 'bear')]) result = lexicon.scan("bear princess") assert_equal(result, [ ('noun', 'bear'), ('noun', 'princess'), ])
def test_stops(): assert_equal(lexicon.scan("the"), [('stop', 'the')]) result = lexicon.scan("the in a of") assert_equal(result, [('stop', 'the'), ('stop', 'in'), ('stop', 'a'), ('stop', 'of')])
def testing_parse_verb(): '''testing the parse_verb function.''' word_list = lexicon.scan('kill at door') assert_equal(parser.parse_verb(word_list), ('verb', 'kill')) word_list = lexicon.scan('bear kill princess') # word_list is assigned with a value in this module, thus not preceeded by parser assert_raises(parser.ParseError, parser.parse_verb, word_list)
def test_numbers(): assert_equal(lexicon.scan("1234"), [('number', 1234)]) result = lexicon.scan("3 91234 0 -1234") assert_equal(result, [('number', 3), ('number', 91234), ('number', 0), ('number', -1234)])
def test_parse_objeto(): lista_de_palavras = lexicon.scan('o porta') assert_equal(parser.parse_objeto(lista_de_palavras), ('noun', 'porta')) lista_de_palavras = lexicon.scan('o oeste') assert_equal(parser.parse_objeto(lista_de_palavras), ('direcao', 'oeste')) lista_de_palavras = lexicon.scan('o e') assert_raises(parser.ParserError, parser.parse_objeto, lista_de_palavras)
def test_parse_object(): word_list = lexicon.scan('the cabinet') assert_equal(parser.parse_object(word_list), ('noun', 'cabinet')) word_list = lexicon.scan('the north') assert_equal(parser.parse_object(word_list), ('direction', 'north')) word_list = lexicon.scan('in of the eat bla') assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_directions(): assert_equal(lexicon.scan("north"), [('direction', 'north')]) result = lexicon.scan("north south east west") assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east'), ('direction', 'west')])
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_nouns(): assert_equal(lexicon.scan("bear"), [('noun', 'bear')]) result = lexicon.scan("bear princess tree bush") assert_equal(result, [('noun', 'bear'), ('noun', 'princess'), ('noun', 'tree'), ('noun', 'bush')])
def test_verbs(): assert_equal(lexicon.scan('go'), [('verb', 'go')]) result = lexicon.scan('go kill eat run') assert_equal(result, [('verb', 'go'), ('verb', 'kill'), ('verb', 'eat'), ('verb', 'run')])
def test_directions(): pass assert_equal(lexicon.scan("north"), [('direction', 'north')]) result = lexicon.scan("north south east") assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east')])
def test_parse_sentence(): err = lexicon.scan("this will error") result = lexicon.scan("the princess kill the bear") result2 = lexicon.scan("kill the bear") assert_equal(ex49.parse_sentence(result), (("noun","princess"), ("verb","kill"), ("noun","bear"))) assert_equal(ex49.parse_sentence(result2), (("noun","player"), ("verb","kill"), ("noun","bear"))) assert_raises(ex49.ParserError, ex49.parse_sentence, err)
def test_capitalize(): assert_equal(lexicon.scan("Stop"), [('verb', 'Stop')]) result = lexicon.scan("Stop the The Bearo princess") assert_equal(result, [('verb', 'Stop'), ('stop', 'the'), ('stop', 'The'), ('error', 'Bearo'), ('noun', 'princess')])
def testing_parse_object(): '''testing the parse_object function.''' word_list = lexicon.scan('the princess') assert_equal(parser.parse_object(word_list), ('noun', 'princess')) word_list = lexicon.scan('the south') assert_equal(parser.parse_object(word_list), ('direction', 'south')) word_list = lexicon.scan('the kill') assert_raises(parser.ParseError, parser.parse_object, word_list)
def test_capital(): assert_equal(lexicon.scan("NOrTh"), [('direction', 'north')]) result = lexicon.scan("Kill BEAR iN tHe East") assert_equal(result, [('verb', 'kill'), ('noun', 'bear'), ('stop', 'in'), ('stop', 'the'), ('direction', 'east')])
def test_directions(): #if "north" passed to lexicon.scan, is result "direction, north"? assert_equal(lexicon.scan("north"), [('direction','north')]) #if "north south east" passed to lexicon.scan, is result list? result = lexicon.scan("north south east") assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east')])
def test_pverb(): assert_equal(parser.parse_verb(lexicon.scan("eat it")), ('verb', 'eat')) assert_equal(parser.parse_verb(lexicon.scan("in the eat")), ('verb', 'eat')) assert_equal(parser.parse_verb(lexicon.scan("of the kill")), ('verb', 'kill')) assert_raises(Exception, parser.parse_verb, lexicon.scan("princess ate the bear"))
def test_verbs(): assert_equal(lexicon.scan("go"), [('verb', 'go')]) result = lexicon.scan("go kill eat open close") assert_equal(result, [('verb', 'go'), ('verb', 'kill'), ('verb', 'eat'), ('verb', 'open'), ('verb', 'close')])
def test_match(): assert_equal(parser.match(lexicon.scan("kill stop bear"), "verb"), ('verb', 'kill')) assert_equal(parser.match(lexicon.scan("Eat kill bear"), "verb"), ('verb', 'Eat')) assert_equal(parser.match(lexicon.scan("kill stop bear"), "stop"), None) assert_equal(parser.match(lexicon.scan("bear walks in woods"), "noun"), ('noun', 'bear'))
def test_capitalization(): assert_equal(lexicon.scan("pRinCEsS"), [('noun', 'princess')]) result = lexicon.scan("tHE tReE IS A BusH") assert_equal(result, [('stop', 'the'), ('noun', 'tree'), ('stop', 'is'), ('stop', 'a'), ('noun', 'bush')])
def test_directions(): assert_equal(lexicon.scan("north"), [('direction', 'north')]) result = lexicon.scan("north south east forward under") assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east'), ('direction', 'forward'), ('direction', 'under')])
def test_parse_sentenca(): lista_de_palavras = lexicon.scan('urso come porta') s = parser.parse_sentenca(lista_de_palavras) assert_equal(s.to_tuple(), ('urso', 'come', 'porta')) lista_de_palavras = lexicon.scan('dentro come porta') s = parser.parse_sentenca(lista_de_palavras) assert_equal(s.to_tuple(), ('player', 'come', 'porta')) lista_de_palavras = lexicon.scan('norte come porta') assert_raises(parser.ParserError, parser.parse_sentenca, lista_de_palavras)
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_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_match(): word_list = [] assert None == parser.match(word_list, 'noun') word_list = lexicon.scan('princess kill bear') assert ('noun', 'princess') == parser.match(word_list, 'noun') word_list = lexicon.scan('princess kill bear') assert None == parser.match(word_list, 'verb')
def test_skip(): input_string = "the in from" word_list = lexicon.scan(input_string) lexicon.skip(word_list, 'stop') assert_equal(word_list, []) word_list = lexicon.scan("in at from bear jump") lexicon.skip(word_list, 'stop') assert_equal(word_list, [('noun', 'bear'), ('error', 'jump')])
def test_peek(): assert_equal(parser.peek(lexicon.scan("north south east west")), "direction") assert_equal(parser.peek(lexicon.scan("NORTH south east west")), "direction") assert_equal(parser.peek(lexicon.scan("moo ias blargh")), 'error') #result = parser.peek(lexicon.scan("north, south, ")) result = parser.peek( lexicon.scan("north south east west up downn left right")) assert_equal(result, 'direction')
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 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_parse_object(): scanner = lexicon.scan("the north bear") assert_equal(scanner, [('stop', 'the'), ('direction', 'north'), ('noun', 'bear')]) assert_equal(parser.parse_object(scanner), ('direction', 'north')) assert_equal(scanner, [('noun', 'bear')]) scanner = lexicon.scan("the bear north") assert_equal(scanner, [('stop', 'the'), ('noun', 'bear'), ('direction', 'north')]) assert_equal(parser.parse_object(scanner), ('noun', 'bear')) assert_equal(scanner, [('direction', 'north')])
def test_parse_sentence(): tuple_list = lexicon.scan(sentence) s = parser.Sentence(tuple_list[0],tuple_list[1],tuple_list[2]) word_list = s.subject, s.verb, s.object assert_equal(word_list, ('princess', 'go', 'east')) tuple_list = lexicon.scan(verb_sentence) s = parser.Sentence(tuple_list[0],tuple_list[1],tuple_list[2]) # word_list = s.subject, s.verb, s.object assert_equal(s,('player', 'go', 'east')) word_list = lexicon.scan('bad sentence') assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_parse_sentence(): word_list = lexicon.scan("the bear eat the princess") sentence = ex49.parse_sentence(word_list) assert_equal(sentence.subject, 'bear') assert_equal(sentence.verb, 'eat') assert_equal(sentence.object, 'princess') word_list = lexicon.scan("go right") sentence = ex49.parse_sentence(word_list) assert_equal(sentence.subject, 'player') assert_equal(sentence.verb, 'go') assert_equal(sentence.object, 'right') word_list = lexicon.scan("a a a a a a") assert_raises(ex49.ParserError, ex49.parse_sentence, word_list)
def test_parse_sentence(): word_list = lexicon.scan("bear eat honey") assert_raises(lexicon.parse_sentence(word_list), lexicon.ParserError) word_list = lexicon.scan("princess stop at the door") sentence = lexicon.parse_sentence(word_list) assert_equal(sentence.subject, ('noun', 'princess')) assert_equal(sentence.verb, ('verb', 'stop')) assert_equal(sentence.obj, ('noun', 'door')) word_list = lexicon.scan("kill bear") sentence = lexicon.parse_sentence(word_list) assert_equal(sentence.subject, ('noun', 'player')) assert_equal(sentence.verb, ('verb', 'kill')) assert_equal(sentence.obj, ('noun', 'bear'))
def test_parse_verb(): scanner = lexicon.scan("the in go north bear") assert_equal(scanner, [('stop', 'the'), ('stop', 'in'), ('verb', 'go'), ('direction', 'north'), ('noun', 'bear')]) assert_equal(parser.parse_verb(scanner), ('verb', 'go')) assert_equal(scanner, [('direction', 'north'), ('noun', 'bear')]) assert_raises(parser.ParserError, parser.parse_verb, scanner)
def test_peek(): word = 'one' scaner = lexicon.scan('bear') assert_equal(parser.peek(word), 'o') assert_equal(parser.peek(scaner), 'noun') assert_equal(parser.peek(None), None)
def test_parse_sentence(): word_list = lexicon.scan('man kill bear') s = parser.Sentence(('noun', 'man'), ('verb', 'kill'), ('number', 1), ('obj', 'bear')) assert_equal(s.subj, 'man') assert_equal(s.verb, 'kill') assert_equal(s.number, 1) assert_equal(s.obj, 'bear')
def test_skip(): word_list = lexicon.scan("the bear") ex49.skip(word_list, 'verb') assert_equal(len(word_list), 2) ex49.skip(word_list, 'stop') assert_equal(word_list[0], ('noun', 'bear')) assert_equal(len(word_list), 1)
def test_skip(): word_list = lexicon.scan('eat the bear bla') assert_equal(word_list, [('verb', 'eat'), ('stop', 'the'), ('noun', 'bear'), ('error', 'bla')]) parser.skip(word_list, 'verb') assert_equal(word_list, [('stop', 'the'), ('noun', 'bear'), ('error', 'bla')]) parser.skip(word_list, 'stop') assert_equal(word_list, [('noun', 'bear'), ('error', 'bla')])
def testing_skip(): '''testing the skip function.''' word_list = lexicon.scan('bear kill princess') assert_equal(word_list, [('noun', 'bear'), ('verb', 'kill'), ('noun', 'princess')]) parser.skip(word_list, 'noun') assert_equal(word_list, [('verb', 'kill'), ('noun', '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_case_insensitivity(): result = lexicon.scan("909 OOPSALA A bEAR kill GO") assert_equal(result, [('number', 909), ('error', 'OOPSALA'), ('stop', 'a'), ('noun', 'bear'), ('verb', 'kill'), ('verb', 'go')])
def test_match_word(): word_list = lexicon.scan("kick the bear") assert_equal(ex49.match(word_list, 'error'), ('error', 'kick')) assert_equal(len(word_list), 2) assert_equal(ex49.match(word_list, 'stop'), ('stop', 'the')) assert_equal(len(word_list), 1) assert_equal(ex49.match(word_list, 'noun'), ('noun', 'bear')) assert_equal(len(word_list), 0)
def TestSkip(): inputsent = lexicon.scan("bear eat castle") assert_equal(inputsent, [('noun', 'bear'), ('verb', 'eat'), ('noun', 'castle')]) parser.skip(inputsent, 'noun') assert_equal(inputsent, [('verb', 'eat'), ('noun', 'castle')]) parser.skip(inputsent, 'verb') assert_equal(inputsent, [('noun', 'castle')])
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_object(): input_string = "princess stop the door of the cabinet" word_list = lexicon.scan(input_string) assert_equal(lexicon.parse_object(word_list), ('noun', 'princess')) assert_raises(lexicon.parse_object(word_list), lexicon.ParserError) assert_equal(lexicon.parse_object(word_list), ('noun', 'door')) assert_equal(lexicon.parse_object(word_list), ('noun', 'cabinet'))
def test_Sentence(): tuple_list = lexicon.scan(sentence) s = parser.Sentence(tuple_list[0],tuple_list[1],tuple_list[2]) assert_equal(s.subject, 'princess') assert_equal(s.verb, 'go') assert_equal(s.object, 'east') word_list = [s.subject, s.verb, s.object] assert_equal(word_list, (['princess', 'go', 'east']))
def test_peek(): word_list = [] assert None == parser.peek(word_list) word_list = [('noun', 'bear'), ('verb', 'go')] assert 'noun' == parser.peek(word_list) word_list = lexicon.scan('princess kill bear') assert 'noun' == parser.peek(word_list)
def test_variety(): result = lexicon.scan("909 URF of 9 eat dumbbell bear") assert_equal(result, [('number', 909), ('error', 'URF'), ('stop', 'of'), ('number', 9), ('verb', 'eat'), ('noun', 'dumbbell'), ('noun', 'bear')])
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_errors(): assert_equal(lexicon.scan("ASDFADFASDF"), [('error', 'asdfadfasdf')]) result = lexicon.scan('bear IAS princess') assert_equal(result, [('noun', 'bear'), ('error', 'ias'), ('noun', 'princess')])
def test_errors(): assert_equal(lexicon.scan('1234'), [('number', 1234)]) result = lexicon.scan('3 91234') assert_equal(result, [('number', 3), ('number', 91234)])
def test_nouns(): assert_equal(lexicon.scan('bear'), [('noun', 'bear')]) result = lexicon.scan('bear princess') assert_equal(result, [('noun', 'bear'), ('noun', 'princess')])
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_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'))