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.139 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.138 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.137 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.136 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.135 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.134 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.133 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.132 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.131 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.130 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.129 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.128 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.127 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.126 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.125 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.124 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.123 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.122 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.121 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb
trackler-2.2.1.120 tracks/ruby/exercises/sieve/.meta/generator/sieve_case.rb