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.127 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.126 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.125 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.124 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.123 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.122 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.121 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.120 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.119 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.118 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.117 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.116 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.115 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.114 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.113 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.111 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.110 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.109 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.108 tracks/crystal/generator/src/generators/difference_of_squares.cr
trackler-2.2.1.107 tracks/crystal/generator/src/generators/difference_of_squares.cr