diff --git a/util/rev_sec.go b/util/rev_sec.go deleted file mode 100644 index 281159d..0000000 --- a/util/rev_sec.go +++ /dev/null @@ -1,52 +0,0 @@ -package util - -import ( - "sort" - "strings" -) - -type ReverseSecSlice struct { - sort.StringSlice -} - -func NewReverseSecSlice(a []string) *ReverseSecSlice { - return &ReverseSecSlice{sort.StringSlice(a)} -} - -func (p *ReverseSecSlice) Sort() *ReverseSecSlice { - sort.Sort(p) - return p -} -func (p *ReverseSecSlice) Uniq() []string { - olds := []string(p.StringSlice) - - last := "" - strs := make([]string, 0, len(olds)) - for _, str := range olds { - if str != last { - strs = append(strs, str) - } - last = str - } - return strs -} - -func (p *ReverseSecSlice) Less(i, j int) bool { - secsI := strings.Split(p.StringSlice[i], ".") - secsJ := strings.Split(p.StringSlice[j], ".") - - lenI := len(secsI) - 1 - lenJ := len(secsJ) - 1 - length := lenI - if lenI > lenJ { - length = lenJ - } - - for idx := 0; idx <= length; idx++ { - if secsI[lenI-idx] == secsJ[lenJ-idx] { - continue - } - return secsI[lenI-idx] < secsJ[lenJ-idx] - } - return lenI < lenJ -} diff --git a/util/rev_sec_test.go b/util/rev_sec_test.go deleted file mode 100644 index 5946250..0000000 --- a/util/rev_sec_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package util - -import ( - "sort" - "testing" -) - -func TestReverseSecSlice_Less(t *testing.T) { - type fields struct { - StringSlice sort.StringSlice - } - type args struct { - i int - j int - } - slice := fields{sort.StringSlice([]string{ - "a.b.c", - "a.b.c", - "d.b.c", - "d.a.b.c", - "", - "", - })} - tests := []struct { - name string - fields fields - args args - want bool - }{{ - name: "equal", - fields: slice, - args: args{0, 1}, - want: false, - }, { - name: "less", - fields: slice, - args: args{0, 2}, - want: true, - }, { - name: "length", - fields: slice, - args: args{0, 3}, - want: true, - }, { - name: "single_empty", - fields: slice, - args: args{0, 4}, - want: false, - }, { - name: "all_empty", - fields: slice, - args: args{4, 5}, - want: false, - }} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - p := &ReverseSecSlice{ - StringSlice: tt.fields.StringSlice, - } - if got := p.Less(tt.args.i, tt.args.j); got != tt.want { - t.Errorf("ReverseSecSlice.Less() = %v, want %v", got, tt.want) - } - }) - } -}