Sha256: 0f623ba2fe0dbc0ed05fd52aea05b1a05cff5643b6300c0865e428cd6bd9093f

Contents?: true

Size: 1.12 KB

Versions: 90

Compression:

Stored size: 1.12 KB

Contents

require 'exercise_cases'

class ClockCase < OpenStruct
  def name
    'test_%s' % description
                .gsub(/[() -]/, '_')
                .gsub('=', 'is_equal_to')
                .chomp('_')
  end

  def test_body
    section == 'equal' ? compare_clocks : simple_test
  end

  def compare_clocks
    "clock1 = Clock.at(#{clock1['hour']}, #{clock1['minute']})
    clock2 = Clock.at(#{clock2['hour']}, #{clock2['minute']})
    #{assert_or_refute} clock1 == clock2"
  end

  def simple_test
    [
      "assert_equal #{expected.inspect}, ",
      "#{'(' if add_to_clock}Clock.at(#{hour}, ",
      "#{minute})#{add_to_clock}#{')' if add_to_clock}.to_s"
    ].join
  end

  def assert_or_refute
    expected ? 'assert' : 'refute'
  end

  def add_to_clock
    " + #{add}" if add
  end

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

ClockCases = proc do |data|
  i = 0
  json = JSON.parse(data)
  cases = []
  %w(create add equal).each do |section|
    json[section]['cases'].each do |row|
      row = row.merge(row.merge('index' => i, 'section' => section))
      cases << ClockCase.new(row)
      i += 1
    end
  end
  cases
end

Version data entries

90 entries across 90 versions & 1 rubygems

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