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