Sha256: 7dfe18521930049d46795626bb8dc094dff89ffe8f4aa166548b324fac40d69e

Contents?: true

Size: 993 Bytes

Versions: 182

Compression:

Stored size: 993 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

182 entries across 182 versions & 1 rubygems

Version Path
trackler-2.1.0.53 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.52 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.51 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.50 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.49 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.48 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.47 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.46 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.45 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.44 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.43 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.42 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.41 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.40 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.39 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.38 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.37 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.36 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.34 tracks/crystal/src/generator/exercises/difference_of_squares.cr
trackler-2.1.0.33 tracks/crystal/src/generator/exercises/difference_of_squares.cr