Sha256: db52515473688b7b4a74734f9c881863b80584fc4a9a87e26d73978fddd3dbb2

Contents?: true

Size: 1.21 KB

Versions: 102

Compression:

Stored size: 1.21 KB

Contents

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

class PascalsTriangleGenerator < ExerciseGenerator
  def exercise_name
    "pascals-triangle"
  end

  def test_cases
    JSON.parse(data)["rows"]["cases"].map do |test_case|
      PascalsTriangleTestCase.new(test_case) unless test_case["count"]?.nil?
    end.compact
  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 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

102 entries across 102 versions & 1 rubygems

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