-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathlongest_substring_test.go
41 lines (33 loc) · 1.01 KB
/
longest_substring_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
package strings
import "testing"
/*
TestLongestSubstrings tests solution(s) with the following signature and problem description:
func LongestSubstringOfTwoChars(input string) string
Given a string return the longest substring of two unique characters.
For example given "aabbc", return "aabb" because it's the longest substring that has two unique
characters "a" and "b".
Other substrings of "aabc" include:
* "aabbc", contains more than 2 unique characters.
* "bbc", shorter than "aabb".
*/
func TestLongestSubstrings(t *testing.T) {
tests := []struct {
input string
longestSubstring string
}{
{"", ""},
{"a", ""}, // No occurrence of sequence of two characters
{"ab", "ab"},
{"abcc", "bcc"},
{"aabbc", "aabb"},
{"ada", "ada"},
{"dafff", "afff"},
{"abbdeeeddfffha", "deeedd"},
}
for i, test := range tests {
got := LongestSubstringOfTwoChars(test.input)
if got != test.longestSubstring {
t.Fatalf("Failed test case #%d. Want %q got %q", i, test.longestSubstring, got)
}
}
}