From 6c2283837c6beca5b291245b85303d7bbcf09fbd Mon Sep 17 00:00:00 2001 From: ykadowak Date: Tue, 19 Sep 2023 05:20:11 +0000 Subject: [PATCH] remove internal/slices pkg --- internal/slices/slices.go | 33 ---------- internal/slices/slices_test.go | 112 --------------------------------- 2 files changed, 145 deletions(-) delete mode 100644 internal/slices/slices.go delete mode 100644 internal/slices/slices_test.go diff --git a/internal/slices/slices.go b/internal/slices/slices.go deleted file mode 100644 index 05e5ec757c..0000000000 --- a/internal/slices/slices.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2019-2023 vdaas.org vald team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package slices - -import ( - "slices" -) - -func RemoveDuplicates[E comparable](x []E, less func(left, right E) int) []E { - if len(x) < 2 { - return x - } - slices.SortStableFunc(x, less) - up := 0 // uniqPointer - for i := 1; i < len(x); i++ { - if x[up] != x[i] { - up++ - x[up] = x[i] - } - } - return x[:up+1] -} diff --git a/internal/slices/slices_test.go b/internal/slices/slices_test.go deleted file mode 100644 index 93adc795bc..0000000000 --- a/internal/slices/slices_test.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2019-2023 vdaas.org vald team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package slices - -import ( - "reflect" - "testing" - - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestRemoveDuplicates(t *testing.T) { - type args struct { - x []int - less func(left, right int) int - } - type want struct { - want []int - } - type test struct { - name string - args args - want want - checkFunc func(want, []int) error - beforeFunc func(*testing.T, args) - afterFunc func(*testing.T, args) - } - defaultCheckFunc := func(w want, got []int) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - x:nil, - less:nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - beforeFunc: func(t *testing.T, args args) { - t.Helper() - }, - afterFunc: func(t *testing.T, args args) { - t.Helper() - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - x:nil, - less:nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - beforeFunc: func(t *testing.T, args args) { - t.Helper() - }, - afterFunc: func(t *testing.T, args args) { - t.Helper() - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(tt, test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(tt, test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - got := RemoveDuplicates(test.args.x, test.args.less) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -// NOT IMPLEMENTED BELOW