|
| 1 | +package dynamic_programming_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/anirudhology/leetcode-go/problems/dynamic_programming" |
| 7 | +) |
| 8 | + |
| 9 | +func TestCoinChange(t *testing.T) { |
| 10 | + // Test case for null coins array |
| 11 | + if result := dynamic_programming.CoinChange(nil, 5); result != -1 { |
| 12 | + t.Errorf("Expected -1, got %d", result) |
| 13 | + } |
| 14 | + |
| 15 | + // Test case for empty coins array |
| 16 | + if result := dynamic_programming.CoinChange([]int{}, 5); result != -1 { |
| 17 | + t.Errorf("Expected -1, got %d", result) |
| 18 | + } |
| 19 | + |
| 20 | + // Test case for negative amount |
| 21 | + if result := dynamic_programming.CoinChange([]int{1, 2, 5}, -5); result != -1 { |
| 22 | + t.Errorf("Expected -1, got %d", result) |
| 23 | + } |
| 24 | + |
| 25 | + // Test case for amount 0 |
| 26 | + if result := dynamic_programming.CoinChange([]int{1, 2, 5}, 0); result != 0 { |
| 27 | + t.Errorf("Expected 0, got %d", result) |
| 28 | + } |
| 29 | + |
| 30 | + // Test case for amount that can't be reached |
| 31 | + if result := dynamic_programming.CoinChange([]int{2}, 3); result != -1 { |
| 32 | + t.Errorf("Expected -1, got %d", result) |
| 33 | + } |
| 34 | + |
| 35 | + // Test case for amount with exact coin matches |
| 36 | + if result := dynamic_programming.CoinChange([]int{1, 2, 5}, 5); result != 1 { |
| 37 | + t.Errorf("Expected 1, got %d", result) |
| 38 | + } |
| 39 | + |
| 40 | + // Test case for amount with no exact match but can be reached |
| 41 | + if result := dynamic_programming.CoinChange([]int{1, 2, 5}, 11); result != 3 { |
| 42 | + t.Errorf("Expected 3, got %d", result) |
| 43 | + } |
| 44 | + |
| 45 | + // Test case for large amount |
| 46 | + if result := dynamic_programming.CoinChange([]int{1, 2, 5}, 100); result != 20 { |
| 47 | + t.Errorf("Expected 20, got %d", result) |
| 48 | + } |
| 49 | +} |
0 commit comments