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.3.1 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.3.0 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.2.0 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.1.2 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.1.1 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.1.0 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.10 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.9 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.8 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.7 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.6 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.5 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.4 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.3 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.2 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.1 tracks/ruby/lib/anagram_cases.rb
trackler-2.0.0.0 tracks/ruby/lib/anagram_cases.rb
trackler-1.0.4.1 tracks/ruby/lib/anagram_cases.rb