Sha256: 23ce2d0b7069cf33e11473afaa5f48dc56ff15aed6235ffa89e9d088eea06c8c

Contents?: true

Size: 809 Bytes

Versions: 58

Compression:

Stored size: 809 Bytes

Contents

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

58 entries across 58 versions & 1 rubygems

Version Path
trackler-2.0.6.11 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.10 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.9 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.8 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.7 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.6 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.5 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.4 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.3 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.2 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.1 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.6.0 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.18 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.17 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.16 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.15 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.14 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.13 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.12 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.5.11 tracks/ruby/lib/anagram_cases.rb