Sha256: 2c2edc46188fb087b2139243bd6118998ae06eda4037145d94d36951d194ea9e

Contents?: true

Size: 891 Bytes

Versions: 102

Compression:

Stored size: 891 Bytes

Contents

require "../exercise_generator"
require "../exercise_test_case"

class FlattenArrayGenerator < ExerciseGenerator
  def exercise_name
    "flatten-array"
  end

  def test_cases
    JSON.parse(data)["cases"].map do |test_case|
      FlattenArrayTestCase.new(test_case)
    end
  end
end

class FlattenArrayTestCase < ExerciseTestCase
  private getter description : JSON::Any
  private getter input : JSON::Any
  private getter expected : JSON::Any

  def initialize(test_case)
    @description = test_case["description"]
    @input = test_case["input"]
    @expected = fix_empty_array(test_case["expected"])
  end

  def workload
    "FlattenArray.flatten(#{input}).should eq(#{expected})"
  end

  def test_name
    description
  end

  def fix_empty_array(input)
    if input.to_s.match(/\[\]/)
      json = "[] of Nil".to_json
      JSON.parse(json)
    else
      input
    end
  end
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
trackler-2.2.1.92 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.91 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.90 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.89 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.88 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.87 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.86 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.85 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.84 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.83 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.82 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.81 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.80 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.79 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.78 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.77 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.76 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.75 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.74 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.73 tracks/crystal/generator/src/generators/flatten_array.cr