forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interleaving_string_test.go
44 lines (38 loc) · 1.23 KB
/
interleaving_string_test.go
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
package dp
import (
"testing"
)
/*
TestIsInterleavingString tests solution(s) with the following signature and problem description:
IsInterleavingString(a, b, input string) bool
Given three strings a,b, and input, return true if input is made by interleaving a and b such that
it contains all their characters while maintaining their order.
Example:
"a", "bcd", "abcd" would return true.
"a", "bdc", "abd" would return false, because c is missing.
"a", "bdc", "abc" would return false, because d is missing.
*/
func TestIsInterleavingString(t *testing.T) {
tests := []struct {
a, b, input string
isInterleavingString bool
}{
{"a", "b", "ab", true},
{"abc", "def", "abcdef", true},
{"ac", "bdef", "abcdef", true},
{"abe", "cdf", "abcdef", true},
{"abd", "cef", "abcdef", true},
{"a", "bdc", "abdc", true},
{"a", "bdc", "abd", false},
{"a", "bdc", "abc", false},
{"bdc", "a", "abc", false},
{"bcd", "a", "abcd", true},
{"abcd", "a", "aabcd", true},
{"aaac", "aaab", "aaaaaabc", true},
}
for i, test := range tests {
if got := IsInterleavingString(test.a, test.b, test.input); test.isInterleavingString != got {
t.Fatalf("Failed test case #%d. Want %t got %t", i, test.isInterleavingString, got)
}
}
}