You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/09/20 15:17:37 UTC

[GitHub] [incubator-kvrocks] tanruixiang commented on a diff in pull request #903: Move TCL test unit/type/hash to Go case

tanruixiang commented on code in PR #903:
URL: https://github.com/apache/incubator-kvrocks/pull/903#discussion_r975502627


##########
tests/gocase/unit/type/hash/hash_test.go:
##########
@@ -0,0 +1,697 @@
+/*
+ * 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 quit

Review Comment:
   ```suggestion
   package hash
   ```



##########
tests/gocase/unit/type/hash/hash_test.go:
##########
@@ -0,0 +1,697 @@
+/*
+ * 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 quit
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"math/rand"
+	"regexp"
+	"sort"
+	"strconv"
+	"strings"
+	"testing"
+	"time"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/stretchr/testify/require"
+)
+
+type StringType uint64
+
+const (
+	Binary StringType = iota
+	Alpha
+	Compr
+)
+
+func randString(min int, max int, stringType StringType) string {
+	l := min + rand.Intn(max-min+1)
+	var minval int
+	var maxval int
+	output := ""
+	switch stringType {
+	case Binary:
+		minval = 0
+		maxval = 255
+	case Alpha:
+		minval = 48
+		maxval = 122
+	case Compr:
+		minval = 48
+		maxval = 52
+	}
+	for i := 0; i < l; i++ {
+		output += fmt.Sprintf("%c", minval+rand.Intn(maxval-minval+1))
+	}
+	return output
+}
+
+func randomInt(max int) int {
+	return rand.Intn(max)
+}
+
+func randomSignedInt(max int) int {
+	i := randomInt(max)
+	if rand.Float64() > 0.5 {
+		i = -i
+	}
+	return i
+}

Review Comment:
   You can get these from `random.go`



##########
tests/gocase/unit/type/hash/hash_test.go:
##########
@@ -0,0 +1,697 @@
+/*
+ * 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 quit
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"math/rand"
+	"regexp"
+	"sort"
+	"strconv"
+	"strings"
+	"testing"
+	"time"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/stretchr/testify/require"
+)
+
+type StringType uint64
+
+const (
+	Binary StringType = iota
+	Alpha
+	Compr
+)
+
+func randString(min int, max int, stringType StringType) string {
+	l := min + rand.Intn(max-min+1)
+	var minval int
+	var maxval int
+	output := ""
+	switch stringType {
+	case Binary:
+		minval = 0
+		maxval = 255
+	case Alpha:
+		minval = 48
+		maxval = 122
+	case Compr:
+		minval = 48
+		maxval = 52
+	}
+	for i := 0; i < l; i++ {
+		output += fmt.Sprintf("%c", minval+rand.Intn(maxval-minval+1))
+	}
+	return output
+}
+
+func randomInt(max int) int {
+	return rand.Intn(max)
+}
+
+func randomSignedInt(max int) int {
+	i := randomInt(max)
+	if rand.Float64() > 0.5 {
+		i = -i
+	}
+	return i
+}
+
+func getKeys(hash map[string]string) []string {
+	var r []string
+	for key := range hash {
+		r = append(r, key)
+	}
+	return r
+}
+
+func getVals(hash map[string]string) []string {
+	var r []string
+	for _, val := range hash {
+		r = append(r, val)
+	}
+	return r
+}
+
+func getAllSorted(hash map[string]string) map[string]string {
+	keys := getKeys(hash)
+	sort.Strings(keys)
+	r := make(map[string]string)
+	for _, key := range keys {
+		r[key] = hash[key]
+	}
+	return r
+}
+
+func randomValue() string {
+	r0 := rand.Intn(4)
+	switch r0 {
+	case 0:
+		return strconv.Itoa(randomSignedInt(1000))
+	case 1:
+		r1 := rand.Intn(2)
+		switch r1 {
+		case 0:
+			return strconv.Itoa(randomSignedInt(2000000000))
+		case 1:
+			return strconv.Itoa(randomSignedInt(4000000000))
+		}
+	case 2:
+		return strconv.Itoa(randomSignedInt(1000000000000))
+	case 3:
+		r2 := rand.Intn(3)
+		switch r2 {
+		case 0:
+			return randString(0, 256, Alpha)
+		case 1:
+			return randString(0, 256, Compr)
+		case 2:
+			return randString(0, 256, Binary)
+		}
+	}
+	return ""
+}

Review Comment:
   You can get these from `random.go`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org