I don’t understand why in the test file,in the “assert_equal” lines,how the computer knows what the ‘directions’ means when I type it before ‘north’.How does the computer know that the word before ‘north’ is not an element of a tuple as well?
from nose.tools import *
from lexicon import Lexicon
def test_directions():
assert_equal(Lexicon.scan("north"), [('direction', 'north')])
result = Lexicon.scan("north south east")
assert_equal(result, [('direction', 'north'),
('direction', 'south'),
('direction', 'east')])
def test_verbs():
assert_equal(Lexicon.scan("go"), [('verb', 'go')])
result = Lexicon.scan("go kill eat open")
assert_equal(result, [('verb', 'go'),
('verb', 'kill'),
('verb', 'eat'),
('verb', 'open')])
def test_stops():
assert_equal(Lexicon.scan("the"), [('stop', 'the')])
result = Lexicon.scan("the in of")
assert_equal(result, [('stop', 'the'),
('stop', 'in'),
('stop', 'of')])
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():
assert_equal(Lexicon.scan("1234"), [('number', 1234)])
result = Lexicon.scan("3 91234")
assert_equal(result, [('number', 3),
('number', 91234)])
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_capitalization():
result = Lexicon.scan("the The tHe thE")
assert_equal(result, [('stop', 'the'),
('stop', 'the'),
('stop', 'the'),
('stop', 'the')])