Sha256: 0349ee9ed6ef18a0919684d331f4a356a2984c3c6a9ce3c573cca5e42c666419

Contents?: true

Size: 835 Bytes

Versions: 87

Compression:

Stored size: 835 Bytes

Contents

require 'exercise_cases'

class AnagramCase < OpenStruct
  def test_name
    'test_%s' % description.gsub(/[ -]/, '_')
  end

  def work_load
    indent_lines([show_comment, detector, anagram, assert].compact)
  end

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

  private

  def indent_lines(code, indent = 2)
    code.join("\n" + ' '*2*indent)
  end

  def show_comment
    "# #{comment}" unless comment.nil?
  end

  def detector
    "detector = Anagram.new('#{subject}')"
  end

  def anagram
    "anagrams = detector.match(#{candidates})"
  end

  def assert
    actual = expected.size > 1 ? 'anagrams.sort' : 'anagrams'
    "assert_equal #{expected.sort}, #{actual}"
  end
end

AnagramCases = proc do |data|
  JSON.parse(data)['cases'].map.with_index do |row, i|
    AnagramCase.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/anagram_cases.rb
trackler-2.0.8.53 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.52 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.51 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.50 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.49 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.48 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.47 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.46 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.45 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.44 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.43 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.42 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.41 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.40 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.39 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.38 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.37 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.36 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.8.35 tracks/ruby/lib/anagram_cases.rb