This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 77b8b1f4 test: get rid of external dependency by implementing generic 
Min/Max functions (#2713)
77b8b1f4 is described below

commit 77b8b1f4e471d983cbca399870ac1d160c19e0ea
Author: Yaroslav <[email protected]>
AuthorDate: Wed Jan 8 13:15:54 2025 +0200

    test: get rid of external dependency by implementing generic Min/Max 
functions (#2713)
---
 .github/workflows/kvrocks.yaml           |   7 +--
 tests/gocase/go.mod                      |   2 -
 tests/gocase/go.sum                      |   4 --
 tests/gocase/unit/type/list/list_test.go |   3 +-
 tests/gocase/util/math.go                |  38 +++++++++++
 tests/gocase/util/math_test.go           | 105 +++++++++++++++++++++++++++++++
 6 files changed, 147 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/kvrocks.yaml b/.github/workflows/kvrocks.yaml
index cda39030..da2f1290 100644
--- a/.github/workflows/kvrocks.yaml
+++ b/.github/workflows/kvrocks.yaml
@@ -69,6 +69,9 @@ jobs:
     runs-on: ubuntu-22.04
     steps:
       - uses: actions/checkout@v4
+      - uses: apache/skywalking-eyes/[email protected]
+        with:
+          config: .github/config/licenserc.yml
       - uses: actions/setup-go@v5
         with:
           go-version-file: 'tests/gocase/go.mod'
@@ -77,9 +80,6 @@ jobs:
         run: |
           sudo apt update
           sudo apt install -y clang-format-14 clang-tidy-14
-      - uses: apache/skywalking-eyes/[email protected]
-        with:
-          config: .github/config/licenserc.yml
       - name: Check with clang-format
         id: check-format
         run: ./x.py check format --clang-format-path clang-format-14
@@ -89,7 +89,6 @@ jobs:
           ./x.py check tidy -j $(nproc) --clang-tidy-path clang-tidy-14 
--run-clang-tidy-path run-clang-tidy-14
       - name: Lint with golangci-lint
         run: ./x.py check golangci-lint
-
       - name: Prepare format patch
         if: always() && steps.check-format.outcome != 'success'
         run: |
diff --git a/tests/gocase/go.mod b/tests/gocase/go.mod
index 7f515c1f..192b2301 100644
--- a/tests/gocase/go.mod
+++ b/tests/gocase/go.mod
@@ -7,7 +7,6 @@ require (
        github.com/shirou/gopsutil/v4 v4.24.12
        github.com/stretchr/testify v1.10.0
        golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
-       modernc.org/mathutil v1.7.1
 )
 
 require (
@@ -19,7 +18,6 @@ require (
        github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // 
indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // 
indirect
-       github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // 
indirect
        github.com/tklauser/go-sysconf v0.3.14 // indirect
        github.com/tklauser/numcpus v0.9.0 // indirect
        github.com/yusufpapurcu/wmi v1.2.4 // indirect
diff --git a/tests/gocase/go.sum b/tests/gocase/go.sum
index 0b14a6ef..c46dca0b 100644
--- a/tests/gocase/go.sum
+++ b/tests/gocase/go.sum
@@ -23,8 +23,6 @@ github.com/power-devops/perfstat 
v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt
 github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod 
h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
 github.com/redis/go-redis/v9 v9.7.0 
h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
 github.com/redis/go-redis/v9 v9.7.0/go.mod 
h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
-github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec 
h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
-github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod 
h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 github.com/shirou/gopsutil/v4 v4.24.12 
h1:qvePBOk20e0IKA1QXrIIU+jmk+zEiYVVx06WjBRlZo4=
 github.com/shirou/gopsutil/v4 v4.24.12/go.mod 
h1:DCtMPAad2XceTeIAbGyVfycbYQNBGk2P8cvDi7/VN9o=
 github.com/stretchr/testify v1.10.0 
h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -48,5 +46,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 
h1:yhCVgyC4o1eVCa2tZl7eS0r+
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod 
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
-modernc.org/mathutil v1.7.1/go.mod 
h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
diff --git a/tests/gocase/unit/type/list/list_test.go 
b/tests/gocase/unit/type/list/list_test.go
index c3e0c550..ab835b94 100644
--- a/tests/gocase/unit/type/list/list_test.go
+++ b/tests/gocase/unit/type/list/list_test.go
@@ -31,7 +31,6 @@ import (
        "github.com/apache/kvrocks/tests/gocase/util"
        "github.com/redis/go-redis/v9"
        "github.com/stretchr/testify/require"
-       "modernc.org/mathutil"
 )
 
 // We need a value larger than list-max-ziplist-value to make sure
@@ -85,7 +84,7 @@ func testLTRIM(t *testing.T, configs 
util.KvrocksServerConfigs) {
                                lo := int64(rand.Float64() * float64(startLen))
                                hi := int64(float64(lo) + 
rand.Float64()*float64(startLen))
 
-                               myList = myList[lo:mathutil.Min(int(hi+1), 
len(myList))]
+                               myList = myList[lo:util.Min(int(hi+1), 
len(myList))]
                                require.NoError(t, rdb.LTrim(ctx, key, lo, 
hi).Err())
                                require.Equal(t, myList, rdb.LRange(ctx, key, 
0, -1).Val(), "failed trim")
 
diff --git a/tests/gocase/util/math.go b/tests/gocase/util/math.go
new file mode 100644
index 00000000..05123b1d
--- /dev/null
+++ b/tests/gocase/util/math.go
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://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 util
+
+import "cmp"
+
+// Min returns the smaller of two values.
+func Min[T cmp.Ordered](a, b T) T {
+       if a < b {
+               return a
+       }
+       return b
+}
+
+// Max returns the larger of two values.
+func Max[T cmp.Ordered](a, b T) T {
+       if a > b {
+               return a
+       }
+       return b
+}
diff --git a/tests/gocase/util/math_test.go b/tests/gocase/util/math_test.go
new file mode 100644
index 00000000..5c5a7ce9
--- /dev/null
+++ b/tests/gocase/util/math_test.go
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://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 util_test
+
+import (
+       "testing"
+
+       "github.com/apache/kvrocks/tests/gocase/util"
+       "github.com/stretchr/testify/assert"
+)
+
+func TestMin(t *testing.T) {
+       // Arrange
+       tests := []struct {
+               name           string
+               a              int
+               b              int
+               expectedResult int
+       }{
+               {
+                       name:           "a is smaller than b",
+                       a:              1,
+                       b:              2,
+                       expectedResult: 1,
+               },
+               {
+                       name:           "a is greater than b",
+                       a:              2,
+                       b:              1,
+                       expectedResult: 1,
+               },
+               {
+                       name:           "a is equal to b",
+                       a:              1,
+                       b:              1,
+                       expectedResult: 1,
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       // Act
+                       result := util.Min(tt.a, tt.b)
+
+                       //Assert
+                       assert.Equal(t, tt.expectedResult, result)
+               })
+       }
+}
+
+func TestMax(t *testing.T) {
+       // Arrange
+       tests := []struct {
+               name           string
+               a              int
+               b              int
+               expectedResult int
+       }{
+               {
+                       name:           "a is smaller than b",
+                       a:              1,
+                       b:              2,
+                       expectedResult: 2,
+               },
+               {
+                       name:           "a is greater than b",
+                       a:              2,
+                       b:              1,
+                       expectedResult: 2,
+               },
+               {
+                       name:           "a is equal to b",
+                       a:              1,
+                       b:              1,
+                       expectedResult: 1,
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       // Act
+                       result := util.Max(tt.a, tt.b)
+
+                       //Assert
+                       assert.Equal(t, tt.expectedResult, result)
+               })
+       }
+}

Reply via email to