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

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.179 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.178 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.177 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.176 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.175 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.174 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.173 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.172 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.171 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.170 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.169 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.167 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.166 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.165 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.164 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.163 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.162 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.161 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb
trackler-2.2.1.160 tracks/ruby/exercises/wordy/.meta/generator/wordy_case.rb