1
exercism fetch elixir change

change_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
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("change.exs", __DIR__)
end

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

defmodule ChangeTest do
  use ExUnit.Case

  # @tag :pending
  test "single coin change" do
    coins = [1, 5, 10, 25, 100]
    expected = [25]
    assert Change.generate(coins, 25) == {:ok, expected}
  end

  @tag :pending
  test "multiple coin change" do
    coins = [1, 5, 10, 25, 100]
    expected = [5, 10]
    assert Change.generate(coins, 15) == {:ok, expected}
  end

  @tag :pending
  test "change with Lilliputian Coins" do
    coins = [1, 4, 15, 20, 50]
    expected = [4, 4, 15]
    assert Change.generate(coins, 23) == {:ok, expected}
  end

  @tag :pending
  test "change with Lower Elbonia Coins" do
    coins = [1, 5, 10, 21, 25]
    expected = [21, 21, 21]
    assert Change.generate(coins, 63) == {:ok, expected}
  end

  @tag :pending
  test "large target values" do
    coins = [1, 2, 5, 10, 20, 50, 100]
    expected = [2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100]
    assert Change.generate(coins, 999) == {:ok, expected}
  end

  @tag :pending
  test "possible change without unit coins available" do
    coins = [2, 5, 10, 20, 50]
    expected = [2, 2, 2, 5, 10]
    assert Change.generate(coins, 21) == {:ok, expected}
  end

  @tag :pending
  test "no coins make 0 change" do
    coins = [1, 5, 10, 21, 25]
    expected = []
    assert Change.generate(coins, 0) == {:ok, expected}
  end

  @tag :pending
  test "error testing for change smaller than the smallest of coins" do
    coins = [5, 10]
    assert Change.generate(coins, 3) == {:error, "cannot change"}
  end

  @tag :pending
  test "error if no combination can add up to target" do
    coins = [5, 10]
    assert Change.generate(coins, 94) == {:error, "cannot change"}
  end

  @tag :pending
  test "cannot find negative change values" do
    coins = [1, 2, 5]
    assert Change.generate(coins, -5) == {:error, "cannot change"}
  end
end