fix: orderedstring add performance improvements

This commit is contained in:
Qiu Jian
2020-07-07 01:30:36 +08:00
parent 8c7593d937
commit f0c3b96274
2 changed files with 84 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
package stringutils2
import (
"reflect"
"testing"
)
@@ -74,3 +75,63 @@ func TestMergeStrings(t *testing.T) {
t.Logf("B: %s", ss2)
t.Logf("%s", m)
}
func TestSortedStringsAppend(t *testing.T) {
cases := []struct {
in []string
ele []string
want SSortedStrings
}{
{
in: []string{"Alpha", "Bravo", "Go"},
ele: []string{"Go2"},
want: []string{"Alpha", "Bravo", "Go", "Go2"},
},
{
in: []string{"Alpha", "Bravo", "Go2"},
ele: []string{"Go"},
want: []string{"Alpha", "Bravo", "Go", "Go2"},
},
{
in: []string{"Alpha", "Bravo", "Go2"},
ele: []string{"Aaaa", "Go"},
want: []string{"Aaaa", "Alpha", "Bravo", "Go", "Go2"},
},
}
for _, c := range cases {
got := NewSortedStrings(c.in).Append(c.ele...)
if !reflect.DeepEqual(c.want, got) {
t.Errorf("want: %s got: %s", c.want, got)
}
}
}
func TestSortedStringsRemove(t *testing.T) {
cases := []struct {
in []string
ele []string
want SSortedStrings
}{
{
in: []string{"Alpha", "Bravo", "Go"},
ele: []string{"Go", "Go2"},
want: []string{"Alpha", "Bravo"},
},
{
in: []string{"Alpha", "Bravo", "Go2"},
ele: []string{"Go"},
want: []string{"Alpha", "Bravo", "Go2"},
},
{
in: []string{"Alpha", "Bravo", "Go", "Go2"},
ele: []string{"Aaaa", "Alpha"},
want: []string{"Bravo", "Go", "Go2"},
},
}
for _, c := range cases {
got := NewSortedStrings(c.in).Remove(c.ele...)
if !reflect.DeepEqual(c.want, got) {
t.Errorf("want: %s got: %s", c.want, got)
}
}
}