Sha256: 9a72a2a362cf728521cc986981c0ef3acf3aa2885a7fd12f8fe46f1e0d4f5f88

Contents?: true

Size: 861 Bytes

Versions: 90

Compression:

Stored size: 861 Bytes

Contents

require 'exercise_cases'

class RunLengthEncodingCase < OpenStruct
  def name
    'test_%s' % cleaned_description
  end

  def assign_input
    "input = '#{input}'"
  end

  def assign_output
    "output = '#{expected}'"
  end

  def assertion
    case description
    when /decode.+encode/
      'assert_equal output,
                 RunLengthEncoding.decode(RunLengthEncoding.encode(input))'
    when /encode/
      'assert_equal output, RunLengthEncoding.encode(input)'
    when /decode/
      'assert_equal output, RunLengthEncoding.decode(input)'
    end
  end

  def skipped?
    index > 0
  end

  # internal

  def cleaned_description
    description.gsub(/\W+/, '_').squeeze('_')
  end
end

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

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
trackler-2.0.6.21 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.20 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.19 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.18 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.17 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.16 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.15 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.14 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.13 tracks/ruby/lib/run_length_encoding_cases.rb
trackler-2.0.6.12 tracks/ruby/lib/run_length_encoding_cases.rb