1
exercism fetch elixir dominoes

dominoes_test.exs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("dominoes.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true

defmodule DominoesTest do
  use ExUnit.Case

  test "empty input = empty output" do
    assert Dominoes.chain?([]) == true
  end

  @tag :pending
  test "singleton input = singleton output" do
    assert Dominoes.chain?([{1, 1}]) == true
  end

  @tag :pending
  test "singleton that can't be chained" do
    assert Dominoes.chain?([{1, 2}]) == false
  end

  @tag :pending
  test "three elements" do
    assert Dominoes.chain?([{1, 2}, {3, 1}, {2, 3}]) == true
  end

  @tag :pending
  test "can reverse dominoes" do
    assert Dominoes.chain?([{1, 2}, {1, 3}, {2, 3}]) == true
  end

  @tag :pending
  test "can't be chained" do
    assert Dominoes.chain?([{1, 2}, {4, 1}, {2, 3}]) == false
  end

  @tag :pending
  test "disconnected - double loop" do
    assert Dominoes.chain?([{1, 2}, {2, 1}, {3, 4}, {4, 3}]) == false
  end

  @tag :pending
  test "disconnected - single isolated" do
    assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {4, 4}]) == false
  end

  @tag :pending
  test "need backtrack" do
    assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {2, 4}, {2, 4}]) == true # a variation in which we have to turn but no duplicates
  end

  @tag :pending
  test "separate loops" do
    assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {1, 1}, {2, 2}, {3, 3}]) == true
  end

  @tag :pending
  test "nine elements" do
    assert Dominoes.chain?([{1, 2}, {5, 3}, {3, 1}, {1, 2}, {2, 4}, {1, 6}, {2, 3}, {3, 4}, {5, 6}]) == true
 end


  @tag :pending
  test "disconnected - simple" do
    refute Dominoes.chain?([{1, 1}, {2, 2}])
  end

  @tag :pending
  test "first and last not matching" do
    assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 4}]) == false
  end

  @tag :pending
  test "wrong starting order" do
    assert Dominoes.chain?([{2, 1}, {2, 3}, {3, 1}]) == true
  end
end