2014-12-09 18:01:46 -05:00
|
|
|
package atlas
|
2014-12-09 18:00:03 -05:00
|
|
|
|
|
|
|
import (
|
2015-06-13 12:58:13 -04:00
|
|
|
"path/filepath"
|
2014-12-09 18:00:03 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLongestCommonPrefix(t *testing.T) {
|
2015-06-13 12:58:13 -04:00
|
|
|
sep := string(filepath.Separator)
|
2014-12-09 18:00:03 -05:00
|
|
|
cases := []struct {
|
2015-06-09 00:34:20 -04:00
|
|
|
Input []string
|
2014-12-09 18:00:03 -05:00
|
|
|
Output string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
[]string{"foo", "bar"},
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo", "foobar"},
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
2015-06-13 12:58:13 -04:00
|
|
|
[]string{"foo" + sep, "foo" + sep + "bar"},
|
|
|
|
"foo" + sep,
|
2014-12-09 18:00:03 -05:00
|
|
|
},
|
|
|
|
{
|
2015-06-13 12:58:13 -04:00
|
|
|
[]string{sep + "foo" + sep, sep + "bar"},
|
|
|
|
sep,
|
2014-12-09 18:00:03 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
actual := longestCommonPrefix(tc.Input)
|
|
|
|
if actual != tc.Output {
|
|
|
|
t.Fatalf("bad: %#v\n\n%#v", actual, tc.Input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|