mardi 15 décembre 2015

How to write a test file

I have written code that accepts standard input or file input (input1.in, input2.in). The output is standard output. The code lets people listen to words form files (input1.in, input2.in), and output the first word.

input1.in

happy
good
way
end

Output

happy

This is the code:

Class People
  words = []
  def talk first_word
    puts first_word
  end

  def listen file_name
    f = File.open(file_name, "r")
    f.each_line do |line|
      words << line
    end
    f.close
    talk words[0]
  end

People.new.listen ARGV[0]

How can I write a test file to test with each input file whether the output is correct? I know how to use rspec to test the methods talk and listen, but I don't know how to test with the whole input file.

Aucun commentaire:

Enregistrer un commentaire