Sha256: 23695f03faf07d357cab90a4b165f994b526eddea69ade0c02f5d2e548d36679
Contents?: true
Size: 1005 Bytes
Versions: 216
Compression:
Stored size: 1005 Bytes
Contents
require 'generator/exercise_case' class WordyCase < Generator::ExerciseCase def workload [ "question = '#{input}'", indent(4, assertion), ].join("\n") end private def indent(size, lines) lines.lines.each_with_object('') { |line, obj| obj << ' ' * size + line } end def assertion return error_assertion if expected == false return message_assertion if message "assert_equal(#{expected}, WordProblem.new(question).answer)" end def error_assertion [ 'assert_raises ArgumentError do', indent(2, 'WordProblem.new(question).answer'), 'end', ].join("\n") end def message_assertion [ 'answer = WordProblem.new(question).answer', "message = \"#{message % '#{answer}'}\"", "assert_equal(#{expected}, answer, message)", ].join("\n") end def message return unless input == 'What is -3 plus 7 multiplied by -2?' 'You should ignore order of precedence. -3 + 7 * -2 = -8, not %s' end end
Version data entries
216 entries across 216 versions & 1 rubygems