Sha256: c9c17254a6fa0f845ad3213a47c697a5ceaa7d26d66996baff1c8da0ddd3921e

Contents?: true

Size: 864 Bytes

Versions: 90

Compression:

Stored size: 864 Bytes

Contents

require 'exercise_cases'

class ConnectCase < OpenStruct
  def name
    'test_%s' % description
                .gsub(/[() -]/, '_')
                .chomp('_')
                .downcase
  end

  def test_body
    [
      'board = [',
      '  ' + board.map(&method(:single_quote)).join(",\n      "),
      ']',
      'game = Board.new(board)',
      "assert_equal #{single_quote(expected)}, game.winner, " +
        single_quote(description)
    ]
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  def single_quote(string)
    string.inspect.tr('"', "'")
  end

  def ignore_method_length
    "# rubocop:disable MethodLength\n  " if board.length > 8
  end
end

ConnectCases = proc do |data|
  json = JSON.parse(data)
  cases = []
  json['cases'].each_with_index do |row, i|
    row['index'] = i
    cases << ConnectCase.new(row)
  end
  cases
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
trackler-2.0.6.21 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.20 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.19 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.18 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.17 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.16 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.15 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.14 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.13 tracks/ruby/lib/connect_cases.rb
trackler-2.0.6.12 tracks/ruby/lib/connect_cases.rb