Sha256: 7af4c537abf3f05bc5198606ad2fa7a2b2465b38518918b1a229ed85f83f5e74
Contents?: true
Size: 1.03 KB
Versions: 90
Compression:
Stored size: 1.03 KB
Contents
require 'exercise_cases' class GrainsCase < OpenStruct def test_name 'test_%s' % description.downcase.tr_s(' ', '_') end def workload fail NotImplementedError end def skipped index.zero? ? '# skip' : 'skip' end private def underscore_format(number) number.to_s.reverse.gsub(/...(?=.)/, '\&_').reverse end end class GrainsCase::SquareMethod < GrainsCase def workload return error_assertion if expected < 0 "assert_equal #{underscore_format(expected)}, Grains.square(#{input})" end private def error_assertion "assert_raises(ArgumentError) { Grains.square(#{input}) }" end end class GrainsCase::TotalMethod < GrainsCase def workload "assert_equal #{underscore_format(expected)}, Grains.total" end end GrainsCases = proc do |data| data = JSON.parse(data) cases = data['square']['cases'].map.with_index do |row, i| GrainsCase::SquareMethod.new(row.merge('index' => i)) end cases << GrainsCase::TotalMethod.new( data['total'].merge('index' => cases.size) ) end
Version data entries
90 entries across 90 versions & 1 rubygems