|
| 1 | +package dynamic_programming_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/anirudhology/leetcode-go/problems/dynamic_programming" |
| 7 | +) |
| 8 | + |
| 9 | +func TestNumDecodings(t *testing.T) { |
| 10 | + // Test case for null string |
| 11 | + if result := dynamic_programming.DecodeWays(""); result != 0 { |
| 12 | + t.Errorf("Expected 0, got %d", result) |
| 13 | + } |
| 14 | + |
| 15 | + // Test case for string with a single character |
| 16 | + if result := dynamic_programming.DecodeWays("1"); result != 1 { |
| 17 | + t.Errorf("Expected 1, got %d", result) |
| 18 | + } |
| 19 | + |
| 20 | + // Test case for string with multiple characters |
| 21 | + if result := dynamic_programming.DecodeWays("12"); result != 2 { |
| 22 | + t.Errorf("Expected 2, got %d", result) |
| 23 | + } |
| 24 | + |
| 25 | + // Test case for string with leading zeros |
| 26 | + if result := dynamic_programming.DecodeWays("012"); result != 0 { |
| 27 | + t.Errorf("Expected 0, got %d", result) |
| 28 | + } |
| 29 | + |
| 30 | + // Test case for string with multiple decoding possibilities |
| 31 | + if result := dynamic_programming.DecodeWays("226"); result != 3 { |
| 32 | + t.Errorf("Expected 3, got %d", result) |
| 33 | + } |
| 34 | + |
| 35 | + // Test case for string with no valid decodings |
| 36 | + if result := dynamic_programming.DecodeWays("30"); result != 0 { |
| 37 | + t.Errorf("Expected 0, got %d", result) |
| 38 | + } |
| 39 | + |
| 40 | + // Test case for string with multiple valid decodings |
| 41 | + if result := dynamic_programming.DecodeWays("11106"); result != 2 { |
| 42 | + t.Errorf("Expected 2, got %d", result) |
| 43 | + } |
| 44 | +} |
0 commit comments