Advertisement
Guest User

Untitled

a guest
Feb 17th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. THIS IS THE TEST GIVEN TO ME:
  2. ------------------------------
  3. require 'test/unit'
  4. require_relative "../lib/lexicon"
  5.  
  6. class LexiconTests < Test::Unit::TestCase
  7.  
  8. Pair = Lexicon::Pair
  9. @@lexicon = Lexicon.new()
  10.  
  11. def test_directions()
  12. assert_equal([Pair.new(:direction, 'north')], @@lexicon.scan("north"))
  13. result = @@lexicon.scan("north south east")
  14. assert_equal(result, [Pair.new(:direction, 'north'),
  15. Pair.new(:direction, 'south'),
  16. Pair.new(:direction, 'east')])
  17. end
  18.  
  19. def test_verbs()
  20. assert_equal(@@lexicon.scan("go"), [Pair.new(:verb, 'go')])
  21. result = @@lexicon.scan("go kill eat")
  22. assert_equal(result, [Pair.new(:verb, 'go'),
  23. Pair.new(:verb, 'kill'),
  24. Pair.new(:verb, 'eat')])
  25. end
  26.  
  27. def test_stops()
  28. assert_equal(@@lexicon.scan("the"), [Pair.new(:stop, 'the')])
  29. result = @@lexicon.scan("the in of")
  30. assert_equal(result, [Pair.new(:stop, 'the'),
  31. Pair.new(:stop, 'in'),
  32. Pair.new(:stop, 'of')])
  33. end
  34.  
  35. def test_nouns()
  36. assert_equal(@@lexicon.scan("bear"), [Pair.new(:noun, 'bear')])
  37. result = @@lexicon.scan("bear princess")
  38. assert_equal(result, [Pair.new(:noun, 'bear'),
  39. Pair.new(:noun, 'princess')])
  40. end
  41.  
  42. def test_numbers()
  43. assert_equal(@@lexicon.scan("1234"), [Pair.new(:number, 1234)])
  44. result = @@lexicon.scan("3 91234")
  45. assert_equal(result, [Pair.new(:number, 3),
  46. Pair.new(:number, 91234)])
  47. end
  48.  
  49. def test_errors()
  50. assert_equal(@@lexicon.scan("ASDFADFASDF"), [Pair.new(:error, 'ASDFADFASDF')])
  51. result = @@lexicon.scan("bear IAS princess")
  52. assert_equal(result, [Pair.new(:noun, 'bear'),
  53. Pair.new(:error, 'IAS'),
  54. Pair.new(:noun, 'princess')])
  55. end
  56.  
  57. end
  58. -------------------------------------------------------
  59.  
  60. THI IS THE FILES I AM TRYING TO BUILD FROM IT
  61. /lib/lexicon.rb
  62. /lib/ex48.rb
  63.  
  64. Here what I've done so far:
  65. ----------------------------------------------------------
  66. # here what I've done for lexicon.rb
  67.  
  68. # Lexicon
  69. Direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right']
  70. Verbs = ['go', 'stop', 'kill', 'eat']
  71. Stop_words = ['the', 'in', 'of', 'from', 'at', 'it']
  72. Nouns = ['door', 'bear', 'princess', 'cabinet']
  73.  
  74. # here what I've done for ex48.rb
  75. require_relative "lexicon"
  76.  
  77. module Lexicon
  78. class Pair
  79.  
  80. attr_accessor :token, :word
  81. # the token are: direction, verb, stop, noun, number
  82. # the words are the words from those tokens
  83. def initialize(token, word)
  84. @token = token
  85. @word = word
  86. end
  87.  
  88.  
  89. def scan(stuff)
  90. @words = stuff.split()
  91. if @words.include? @word
  92. return token
  93. else
  94. puts "The word %s was not found" % @token
  95. end
  96. end
  97.  
  98. def add_words(words)
  99. @words.update(words)
  100. end
  101. end
  102. end
  103.  
  104. ----------------------------------
  105. ERROR
  106.  
  107. osiris:ex48 $ ruby test/test_lexicon.rb
  108. test/test_lexicon.rb:8:in `<class:LexiconTests>': undefined method `new' for Lexicon:Module (NoMethodError)
  109. from test/test_lexicon.rb:5:in `<main>'
  110. osiris:ex48 $
  111.  
  112. -----------------------------------
  113. I want to know what I am doing wrong.
  114. this assignment is based from: http://ruby.learncodethehardway.org/book/ex48.html
  115.  
  116.  
  117. All the information from the assignment are available there.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement