Created
February 11, 2015 03:58
-
-
Save jdecuirm/c09ebbc1bd04cda1aca1 to your computer and use it in GitHub Desktop.
Comparing Words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Lexicon | |
| #Arrays that holds the words to compare | |
| @directions = %w{south west east north} | |
| @verbs = %w{go kill eat play say talk jump fight throw smile hit punch climb} | |
| @nouns = %w{bear princess penguin mole cherry lollipop pillow} | |
| @stop_words = %w{the in of} | |
| #Class method that gets a string and classify the word. It makes an array of the classification and the word | |
| def self.scan(inputed_text) | |
| defined_array_words = [] | |
| words = inputed_text.split(" ") | |
| words.each do |word| | |
| @directions.each do |direction| | |
| if word == direction | |
| word_catego = [] | |
| word_catego << 'direction' | |
| word_catego << word | |
| defined_array_words << word_catego | |
| end | |
| end | |
| end | |
| defined_array_words | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rake/testtask' | |
| Rake::TestTask.new do |task| | |
| task.libs << "tests" | |
| task.test_files = FileList['tests/test*.rb'] | |
| task.verbose = true | |
| task.warning = true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './lib/EX48/lexicon.rb' | |
| require 'test/unit' | |
| class TestName < Test::Unit::TestCase | |
| 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']]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment