Sha256: 1347def5c6df4c5b5fe280737ffea9e8d3898eb199a3b2ccc1cb03386370718e
Contents?: true
Size: 1.13 KB
Versions: 185
Compression:
Stored size: 1.13 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).each do |k, v| v.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 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
185 entries across 185 versions & 1 rubygems