Skip to content

Instantly share code, notes, and snippets.

@jdecuirm
Created February 20, 2015 03:32
Show Gist options
  • Select an option

  • Save jdecuirm/769171504970b3128ff8 to your computer and use it in GitHub Desktop.

Select an option

Save jdecuirm/769171504970b3128ff8 to your computer and use it in GitHub Desktop.
Unit test with custom class objects
def parse_sentence(word_list)
puts "First state of the array"
p word_list
subj = parse_subject(word_list)
puts "First shift getting the subject, if no subject, player goes default"
p word_list
verb = parse_verb(word_list)
puts "Second shift getting the verb."
p word_list
obj = parse_object(word_list)
puts "Third shift deleting the stop words, and getting the object for sentence"
p word_list
Sentence.new(subj,verb,obj)
end
p x = parse_sentence([['noun','jorge'],['verb','eats'],['stop','a'],['noun','sandwich']])
class Sentence
attr_accessor :subject, :verb, :obj
def initialize(subject, verb, obj)
@subject = subject[1]
@verb = verb[1]
@obj = obj[1]
end
def ==(another_sentence)
if self.subject == another_sentence.subject && self.verb == another_sentence.verb && self.obj == another_sentence.obj
true
end
end
end
require 'EX48/parser.rb'
require 'EX48/sentence.rb'
require 'test/unit'
class TestParser < Test::Unit::TestCase
#parse_sentence must return a #Sentence object like
#<Sentence:0x000000033dc450 @obj="sandwich", @subject="jorge", @verb="eats">
def test_good_sentences()
assert_equal(parse_sentence([['noun','jorge'],['verb','eats'],['stop','a'],['noun','sandwich']]),Sentence.new('jorge','eats','sandwich'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment