Sha256: cf0e15e87a9376818773958ac7487238053545d4904d57f8c74fa52280bace8b

Contents?: true

Size: 1.95 KB

Versions: 48

Compression:

Stored size: 1.95 KB

Contents

#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'dominoes'

# Test data version: <%= sha1 %>
class DominoesTest < Minitest::Test
<% test_cases.each do |test_case| %>
  def <%= test_case.test_name %>
    <%= test_case.skipped %>
    <%= test_case.workload %>
  end

<% end %>
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
  def test_bookkeeping
    skip
    assert_equal <%= version.next %>, 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

48 entries across 48 versions & 1 rubygems

Version Path
trackler-2.0.6.11 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.10 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.9 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.8 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.7 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.6 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.5 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.4 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.3 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.2 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.1 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.6.0 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.18 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.17 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.16 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.15 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.14 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.13 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.12 tracks/ruby/exercises/dominoes/example.tt
trackler-2.0.5.11 tracks/ruby/exercises/dominoes/example.tt