Sha256: 1d47aad300fbe2b2afcb560444f1bffe1ac42759208588bc2353e838ce8b51f9

Contents?: true

Size: 733 Bytes

Versions: 13

Compression:

Stored size: 733 Bytes

Contents

class AlphameticsCase < OpenStruct
  PAIRS_PER_LINE = 4
  SPACE = ->(num) { ' ' * num }

  def test_name
    "test_#{description.tr(' ', '_')}"
  end

  def work_load
    "Alphametics.new.solve('#{puzzle}')"
  end

  def expect
    return 'nil' if expected.nil?
    expected_values
  end

  def expected_values
    "{\n" << expected.each_slice(PAIRS_PER_LINE).map do |pairs|
      '%s'.prepend(SPACE[6]) %
      pairs.map { |k, v| "'#{k}' => #{v}" }.join(', ')
    end.join(",\n") << "\n    }"
  end

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
trackler-2.0.0.2 tracks/ruby/lib/alphametics_cases.rb
trackler-2.0.0.1 tracks/ruby/lib/alphametics_cases.rb
trackler-2.0.0.0 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.4.1 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.4.0 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.3.0 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.2.1 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.2.0 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.1.2 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.1.1 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.1.0 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.0.1 tracks/ruby/lib/alphametics_cases.rb
trackler-1.0.0 tracks/ruby/lib/alphametics_cases.rb