79 lines
1.0 KiB
Go
79 lines
1.0 KiB
Go
package match
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLongestCommonPrefix(t *testing.T) {
|
|
tt := []struct {
|
|
a string
|
|
b string
|
|
expectedPrefix string
|
|
}{
|
|
{
|
|
"hello",
|
|
"helloooo",
|
|
"hello",
|
|
},
|
|
{
|
|
"oh no",
|
|
"",
|
|
"",
|
|
},
|
|
{
|
|
"",
|
|
"oh no",
|
|
"",
|
|
},
|
|
{
|
|
"Brooklyn 99",
|
|
"Brooklyn Nine-Nine",
|
|
"Brooklyn ",
|
|
},
|
|
}
|
|
|
|
for _, test := range tt {
|
|
prefix := getLongestCommonPrefix(test.a, test.b)
|
|
assert.Equal(t, test.expectedPrefix, prefix)
|
|
}
|
|
}
|
|
|
|
func TestIsPrefixMeaningful(t *testing.T) {
|
|
tt := []struct {
|
|
prefix string
|
|
expected bool
|
|
}{
|
|
{
|
|
prefix: "Brooklyn",
|
|
expected: true,
|
|
},
|
|
{
|
|
prefix: "b",
|
|
expected: false,
|
|
},
|
|
{
|
|
prefix: "The",
|
|
expected: false,
|
|
},
|
|
{
|
|
prefix: "The-",
|
|
expected: false,
|
|
},
|
|
{
|
|
prefix: "The Runner",
|
|
expected: true,
|
|
},
|
|
{
|
|
prefix: "The R",
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, test := range tt {
|
|
isMeaningful := isPrefixMeaningful(test.prefix)
|
|
assert.Equal(t, test.expected, isMeaningful)
|
|
}
|
|
}
|