-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcoin_change_test.rb
57 lines (50 loc) · 1.46 KB
/
coin_change_test.rb
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
require_relative "../../test_helper"
require_relative "coin_change"
describe CoinChange do
describe "edge cases" do
it "should print an empty string given an empty array" do
expected = ""
subject = -> { CoinChange.run([], 1, [], 0, 0) }
expect(subject).must_output expected
end
end
describe "base cases" do
it "should print single item given an array of length 1" do
expected = print_results [1]
subject = -> { CoinChange.run([1], 1, [], 0, 0) }
expect(subject).must_output expected
end
it "should print an empty string when target is negative" do
expected = ""
subject = -> { CoinChange.run([], -1, [], 0, 0) }
expect(subject).must_output expected
end
end
describe "regular cases" do
it "should print combinations when target == largest coin" do
arr = [1, 2, 5]
target = 5
expected = print_results(
[1, 1, 1, 1, 1],
[1, 1, 1, 2],
[1, 2, 2],
[5]
)
subject = -> { CoinChange.run(arr, target, [], 0, 0) }
expect(subject).must_output expected
end
it "should print combinations when target >= largest coin" do
arr = [1, 2, 5]
target = 6
expected = print_results(
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 2],
[1, 1, 2, 2],
[1, 5],
[2, 2, 2]
)
subject = -> { CoinChange.run(arr, target, [], 0, 0) }
expect(subject).must_output expected
end
end
end