Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- THIS IS THE TEST GIVEN TO ME:
- ------------------------------
- require 'test/unit'
- require_relative "../lib/lexicon"
- class LexiconTests < Test::Unit::TestCase
- Pair = Lexicon::Pair
- @@lexicon = Lexicon.new()
- def test_directions()
- assert_equal([Pair.new(:direction, 'north')], @@lexicon.scan("north"))
- result = @@lexicon.scan("north south east")
- assert_equal(result, [Pair.new(:direction, 'north'),
- Pair.new(:direction, 'south'),
- Pair.new(:direction, 'east')])
- end
- def test_verbs()
- assert_equal(@@lexicon.scan("go"), [Pair.new(:verb, 'go')])
- result = @@lexicon.scan("go kill eat")
- assert_equal(result, [Pair.new(:verb, 'go'),
- Pair.new(:verb, 'kill'),
- Pair.new(:verb, 'eat')])
- end
- def test_stops()
- assert_equal(@@lexicon.scan("the"), [Pair.new(:stop, 'the')])
- result = @@lexicon.scan("the in of")
- assert_equal(result, [Pair.new(:stop, 'the'),
- Pair.new(:stop, 'in'),
- Pair.new(:stop, 'of')])
- end
- def test_nouns()
- assert_equal(@@lexicon.scan("bear"), [Pair.new(:noun, 'bear')])
- result = @@lexicon.scan("bear princess")
- assert_equal(result, [Pair.new(:noun, 'bear'),
- Pair.new(:noun, 'princess')])
- end
- def test_numbers()
- assert_equal(@@lexicon.scan("1234"), [Pair.new(:number, 1234)])
- result = @@lexicon.scan("3 91234")
- assert_equal(result, [Pair.new(:number, 3),
- Pair.new(:number, 91234)])
- end
- def test_errors()
- assert_equal(@@lexicon.scan("ASDFADFASDF"), [Pair.new(:error, 'ASDFADFASDF')])
- result = @@lexicon.scan("bear IAS princess")
- assert_equal(result, [Pair.new(:noun, 'bear'),
- Pair.new(:error, 'IAS'),
- Pair.new(:noun, 'princess')])
- end
- end
- -------------------------------------------------------
- THI IS THE FILES I AM TRYING TO BUILD FROM IT
- /lib/lexicon.rb
- /lib/ex48.rb
- Here what I've done so far:
- ----------------------------------------------------------
- # here what I've done for lexicon.rb
- # Lexicon
- Direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right']
- Verbs = ['go', 'stop', 'kill', 'eat']
- Stop_words = ['the', 'in', 'of', 'from', 'at', 'it']
- Nouns = ['door', 'bear', 'princess', 'cabinet']
- # here what I've done for ex48.rb
- require_relative "lexicon"
- module Lexicon
- class Pair
- attr_accessor :token, :word
- # the token are: direction, verb, stop, noun, number
- # the words are the words from those tokens
- def initialize(token, word)
- @token = token
- @word = word
- end
- def scan(stuff)
- @words = stuff.split()
- if @words.include? @word
- return token
- else
- puts "The word %s was not found" % @token
- end
- end
- def add_words(words)
- @words.update(words)
- end
- end
- end
- ----------------------------------
- ERROR
- osiris:ex48 $ ruby test/test_lexicon.rb
- test/test_lexicon.rb:8:in `<class:LexiconTests>': undefined method `new' for Lexicon:Module (NoMethodError)
- from test/test_lexicon.rb:5:in `<main>'
- osiris:ex48 $
- -----------------------------------
- I want to know what I am doing wrong.
- this assignment is based from: http://ruby.learncodethehardway.org/book/ex48.html
- All the information from the assignment are available there.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement