Sha256: ffdb4f2de91b529c1cc1dc499b82d5e7b2f3a207c88e9437a83d72943f4c3764
Contents?: true
Size: 1.15 KB
Versions: 86
Compression:
Stored size: 1.15 KB
Contents
require "../exercise_generator" require "../exercise_test_case" class ForthGenerator < ExerciseGenerator def exercise_name "forth" 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| ForthTestCase.new(test_case) end end end class ForthTestCase < ExerciseTestCase private getter input : JSON::Any | String private getter description : JSON::Any private getter expected : JSON::Any? def initialize(test_case) @input = test_case["input"].as_a.join @description = test_case["description"] @expected = fix_empty_array(test_case["expected"]?) end def workload if expected "Forth.evaluate(#{input.inspect}).should eq(#{expected})" else <<-WL expect_raises(Exception) do Forth.evaluate(#{input.inspect}) end WL end end def test_name description 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