Sha256: b6dcddb4f232ef2c3164a613b608f0521fad101b0a898419e62f409cce3d53fc

Contents?: true

Size: 779 Bytes

Versions: 87

Compression:

Stored size: 779 Bytes

Contents

require 'exercise_cases'

class BowlingCase < OpenStruct
  def test_name
    "test_#{description.downcase.tr(' ', '_')}"
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  def work_load
    indent_lines(assert)
  end

  private

  def roll
    "roll(#{rolls})"
  end

  def assert
    if assert_error?
      [
        'assert_raises Game::BowlingError do',
        "  #{roll}",
        '  @game.score',
        'end'
      ]
    else
      [roll, "assert_equal #{expected}, @game.score"]
    end
  end

  def assert_error?
    expected == -1
  end

  def indent_lines(code)
    code.join("\n" + ' ' * 4)
  end
end

BowlingCases = proc do |data|
  JSON.parse(data)['score']['cases'].map.with_index do |row, i|
    BowlingCase.new(row.merge('index' => i))
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
trackler-2.0.8.54 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.53 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.52 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.51 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.50 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.49 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.48 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.47 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.46 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.45 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.44 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.43 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.42 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.41 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.40 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.39 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.38 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.37 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.36 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.8.35 tracks/ruby/lib/bowling_cases.rb