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