Sha256: adc58fa57eab8ed05afb569a280a6cf7d5a347d7d8ff1976be12016aa90cec70

Contents?: true

Size: 995 Bytes

Versions: 156

Compression:

Stored size: 995 Bytes

Contents

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

class DifferenceOfSquaresGenerator < ExerciseGenerator
  def exercise_name
    "difference-of-squares"
  end

  def test_cases
    ["square_of_sum", "sum_of_squares", "difference_of_squares"]
      .reduce(Array(ExerciseTestCase).new) do |cases, type|
      cases + JSON.parse(data)[type]["cases"].map do |test_case|
        DifferenceOfSquaresTestCase.new(test_case, type)
      end
    end
  end
end

class DifferenceOfSquaresTestCase < ExerciseTestCase
  private getter number : JSON::Any
  private getter description : JSON::Any
  private getter expected : JSON::Any?
  private getter type : String

  def initialize(test_case, type)
    @type = type
    @number = test_case["number"]
    @description = test_case["description"]
    @expected = test_case["expected"]?
  end

  def workload
    "Squares.#{type}(#{number}).should eq(#{expected})"
  end

  def test_name
    "calculates #{description} is #{expected}"
  end
end

Version data entries

156 entries across 156 versions & 1 rubygems

Version Path
trackler-2.2.1.147 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.146 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.145 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.144 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.143 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.142 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.141 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.140 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.139 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.138 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.137 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.136 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.135 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.134 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.133 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.132 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.131 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.130 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.129 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.128 tracks/crystal/generator/src/generators/difference_of_squares.cr