Sha256: 2ef65717ac2ba8915b56371be5136aa26374c61f0f210abf9433bfcd5af0f31f
Contents?: true
Size: 1.33 KB
Versions: 86
Compression:
Stored size: 1.33 KB
Contents
require "../exercise_generator" require "../exercise_test_case" class PascalsTriangleGenerator < ExerciseGenerator def exercise_name "pascals-triangle" end def test_cases test_cases = [] of JSON::Any JSON.parse(data)["cases"].each do |group| group.each do |a, b| test_cases.concat(b) if a.as_s == "cases" end end test_cases.map do |test_case| PascalsTriangleTestCase.new(test_case) end end end class PascalsTriangleTestCase < ExerciseTestCase private getter description : JSON::Any private getter count : JSON::Any private getter expected : JSON::Any def initialize(test_case) @description = test_case["description"] @count = test_case["count"] @expected = fix_empty_array(test_case["expected"]) end def workload if !error? "PascalsTriangle.rows(#{count}).should eq(#{expected})" else <<-WL expect_raises(ArgumentError) do PascalsTriangle.rows(#{count}) end WL end end def test_name if !error? "will return the first #{count} row(s)" else "will raise an Argument error for #{description}" end end private def error? expected == -1 end private def fix_empty_array(json) if json.to_s.match(/\[\]/) JSON.parse("[] of Int32".to_json) else json end end end
Version data entries
86 entries across 86 versions & 1 rubygems