Sha256: 7effd03b2a2c223bf978776d066fb9e829edf8755aca97c8492a789f2ec32ab8

Contents?: true

Size: 715 Bytes

Versions: 233

Compression:

Stored size: 715 Bytes

Contents

require 'generator/exercise_case'

class SieveCase < Generator::ExerciseCase
  OPEN_ARRAY = "[\n\s\s\s\s\s\s".freeze
  CLOSE_ARRAY = "\n\s\s\s\s]".freeze
  NEW_ARRAY_ROW = ",\n\s\s\s\s\s\s".freeze
  ARRAY_ELEMENTS_PER_ROW = 17.freeze

  def workload
    indent_lines([
      "expected = #{expected_string}",
      "assert_equal expected, Sieve.new(#{limit}).primes"
    ], 4)
  end

  private

  def expected_string
    return expected unless needs_indentation?

    array_rows = expected.each_slice(ARRAY_ELEMENTS_PER_ROW).map { |elements| elements.join(', ') }
    "#{OPEN_ARRAY}#{array_rows.join(NEW_ARRAY_ROW)}#{CLOSE_ARRAY}"
  end

  def needs_indentation?
    expected.size > ARRAY_ELEMENTS_PER_ROW
  end
end

Version data entries

233 entries across 233 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.179 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.178 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.177 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.176 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.175 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.174 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.173 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.172 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.171 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.170 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.169 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.167 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.166 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.165 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.164 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.163 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.162 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.161 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.160 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb