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.12 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.11 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.10 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.9 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.8 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.7 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.6 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.5 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.4 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.3 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.2 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.1 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.1.0 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.6 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.5 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.4 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.3 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.2 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.1 tracks/crystal/generator/src/generators/flatten_array.cr
trackler-2.2.0.0 tracks/crystal/generator/src/generators/flatten_array.cr