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