|
| 1 | +import make_change from require 'change' |
| 2 | + |
| 3 | +describe 'change', -> |
| 4 | + it 'change for 1 cent', -> |
| 5 | + result = make_change 1, {1, 5, 10, 25} |
| 6 | + expected = {1} |
| 7 | + assert.are.same expected, result |
| 8 | + |
| 9 | + pending 'single coin change', -> |
| 10 | + result = make_change 25, {1, 5, 10, 25, 100} |
| 11 | + expected = {25} |
| 12 | + assert.are.same expected, result |
| 13 | + |
| 14 | + pending 'multiple coin change', -> |
| 15 | + result = make_change 15, {1, 5, 10, 25, 100} |
| 16 | + expected = {5, 10} |
| 17 | + assert.are.same expected, result |
| 18 | + |
| 19 | + pending 'change with Lilliputian Coins', -> |
| 20 | + result = make_change 23, {1, 4, 15, 20, 50} |
| 21 | + expected = {4, 4, 15} |
| 22 | + assert.are.same expected, result |
| 23 | + |
| 24 | + pending 'change with Lower Elbonia Coins', -> |
| 25 | + result = make_change 63, {1, 5, 10, 21, 25} |
| 26 | + expected = {21, 21, 21} |
| 27 | + assert.are.same expected, result |
| 28 | + |
| 29 | + pending 'large target values', -> |
| 30 | + result = make_change 999, {1, 2, 5, 10, 20, 50, 100} |
| 31 | + expected = {2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100} |
| 32 | + assert.are.same expected, result |
| 33 | + |
| 34 | + pending 'possible change without unit coins available', -> |
| 35 | + result = make_change 21, {2, 5, 10, 20, 50} |
| 36 | + expected = {2, 2, 2, 5, 10} |
| 37 | + assert.are.same expected, result |
| 38 | + |
| 39 | + pending 'another possible change without unit coins available', -> |
| 40 | + result = make_change 27, {4, 5} |
| 41 | + expected = {4, 4, 4, 5, 5, 5} |
| 42 | + assert.are.same expected, result |
| 43 | + |
| 44 | + pending 'a greedy approach is not optimal', -> |
| 45 | + result = make_change 20, {1, 10, 11} |
| 46 | + expected = {10, 10} |
| 47 | + assert.are.same expected, result |
| 48 | + |
| 49 | + pending 'no coins make 0 change', -> |
| 50 | + result = make_change 0, {1, 5, 10, 21, 25} |
| 51 | + expected = {} |
| 52 | + assert.are.same expected, result |
| 53 | + |
| 54 | + pending 'error testing for change smaller than the smallest of coins', -> |
| 55 | + f = -> make_change 3, {5, 10} |
| 56 | + assert.has.error f, "can't make target with given coins" |
| 57 | + |
| 58 | + pending 'error if no combination can add up to target', -> |
| 59 | + f = -> make_change 94, {5, 10} |
| 60 | + assert.has.error f, "can't make target with given coins" |
| 61 | + |
| 62 | + pending 'cannot find negative change values', -> |
| 63 | + f = -> make_change -5, {1, 2, 5} |
| 64 | + assert.has.error f, "target can't be negative" |
0 commit comments