Sha256: 18944cccae20ef8a6232bce6fe2074213eb30f5c4548899f28d6390cc5989608

Contents?: true

Size: 1.97 KB

Versions: 159

Compression:

Stored size: 1.97 KB

Contents

require 'minitest/autorun'
require_relative 'dominoes'

# Common test data version: <%= canonical_data_version %> <%= abbreviated_commit_hash %>
class DominoesTest < Minitest::Test
<% test_cases.each_with_index do |test_case, idx| %>
  def <%= test_case.name %>
    <%= test_case.skipped(idx) %>
    <%= test_case.workload %>
  end

<% end %>
<%= IO.read(EXERCISM_RUBY_LIB + '/bookkeeping.md') %>
  def test_bookkeeping
    skip
    assert_equal <%= version %>, BookKeeping::VERSION
  end

  # It's infeasible to use example-based tests for this exercise,
  # because the list of acceptable answers for a given input can be quite large.
  # Instead, we verify certain properties of a correct chain.

  def assert_correct_chain(input_dominoes, output_chain)
    refute_nil output_chain, "There should be a chain for #{input_dominoes}"
    assert_same_dominoes(input_dominoes, output_chain)
    return if output_chain.empty?
    assert_consecutive_dominoes_match(output_chain)
    assert_dominoes_at_end_match(output_chain)
  end

  def assert_same_dominoes(input_dominoes, output_chain)
    input_normal = input_dominoes.map(&:sort).sort
    output_normal = output_chain.map(&:sort).sort
    assert_equal input_normal, output_normal,
      'Dominoes used in the output must be the same as the ones given in the input'
  end

  def assert_consecutive_dominoes_match(chain)
    chain.each_cons(2).with_index { |(d1, d2), i|
      assert_equal d1.last, d2.first,
        "In chain #{chain}, right end of domino #{i} (#{d1}) and left end of domino #{i + 1} (#{d2}) must match"
    }
  end

  def assert_dominoes_at_end_match(chain)
    first_domino = chain.first
    last_domino = chain.last
    assert_equal first_domino.first, last_domino.last,
      "In chain #{chain}, left end of first domino (#{first_domino}) and right end of last domino (#{last_domino}) must match"
  end

  def refute_correct_chain(input_dominoes, output_chain)
    assert_nil output_chain, "There should be no chain for #{input_dominoes}"
  end
end

Version data entries

159 entries across 159 versions & 1 rubygems

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