34 lines
565 B
Go
34 lines
565 B
Go
package leetcode
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestLongestCommonPrefix(t *testing.T) {
|
|
qsts := []question{
|
|
question{
|
|
Q: []string{},
|
|
A: "",
|
|
},
|
|
question{
|
|
Q: []string{"abc"},
|
|
A: "abc",
|
|
},
|
|
question{
|
|
A: "fl",
|
|
Q: []string{"flower", "flow", "flight"},
|
|
},
|
|
question{
|
|
A: "",
|
|
Q: []string{"dog", "racecar", "car"},
|
|
},
|
|
}
|
|
for _, q := range qsts {
|
|
qst := q.Q.([]string)
|
|
res := q.A.(string)
|
|
if r := longestCommonPrefix(qst); r != res {
|
|
t.Fatalf("quest is: %+v, except result is: %v, but exec result is: %v", qst, res, r)
|
|
}
|
|
}
|
|
}
|