Sha256: 7af4c537abf3f05bc5198606ad2fa7a2b2465b38518918b1a229ed85f83f5e74

Contents?: true

Size: 1.03 KB

Versions: 90

Compression:

Stored size: 1.03 KB

Contents

require 'exercise_cases'

class GrainsCase < OpenStruct
  def test_name
    'test_%s' % description.downcase.tr_s(' ', '_')
  end

  def workload
    fail NotImplementedError
  end

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

  private

  def underscore_format(number)
    number.to_s.reverse.gsub(/...(?=.)/, '\&_').reverse
  end
end

class GrainsCase::SquareMethod < GrainsCase
  def workload
    return error_assertion if expected < 0

    "assert_equal #{underscore_format(expected)}, Grains.square(#{input})"
  end

  private

  def error_assertion
    "assert_raises(ArgumentError) { Grains.square(#{input}) }"
  end
end

class GrainsCase::TotalMethod < GrainsCase
  def workload
    "assert_equal #{underscore_format(expected)}, Grains.total"
  end
end

GrainsCases = proc do |data|
  data = JSON.parse(data)

  cases = data['square']['cases'].map.with_index do |row, i|
    GrainsCase::SquareMethod.new(row.merge('index' => i))
  end

  cases << GrainsCase::TotalMethod.new(
    data['total'].merge('index' => cases.size)
  )
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
trackler-2.1.0.1 tracks/ruby/lib/grains_cases.rb
trackler-2.1.0.0 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.55 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.54 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.53 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.52 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.51 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.50 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.49 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.48 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.47 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.46 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.45 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.44 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.43 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.42 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.41 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.40 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.39 tracks/ruby/lib/grains_cases.rb
trackler-2.0.8.38 tracks/ruby/lib/grains_cases.rb