提交 dc113f05 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

close #task7498,7499

上级 3e9f3bcd
title: 测试文件
desc:
author: zentao
version: 1.0
fields:
- field: test1
range: [1-9]:3{2}
postfix: "\t"
- field: test2
range: Z-A:R{2}
postfix: "\t"
- field: test3
range: 1-9.0{2}
postfix: "\t"
- field: test4
range: user-1{3}
postfix: "\t"
- field: test5
range: [user-2,user3,user4,user6]:R{2}
postfix: "\t"
......@@ -4,9 +4,6 @@ author: zentao
version: 1.0
fields:
- field: test
range: 9-1:-2{2}
- field: field_use_instance # 引用default.xml里的嵌套字段
prefix: "[" # 复写前缀
postfix: "]" # 特殊字符加引号,否则无法解析
......
package gen
import (
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"math/rand"
)
func GenerateByteItems(start byte, end byte, step interface{}, rand bool, repeat int) []interface{} {
......@@ -17,17 +17,16 @@ func GenerateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
arr := make([]interface{}, 0)
total := 0
for round := 0; round < repeat; round++ {
for i := 0; true; {
val := start + byte(int(i)*step)
if val > end {
break
}
for i := 0; true; {
val := start + byte(int(i)*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
i++
total++
total++
if total > constant.MaxNumb {
break
}
......@@ -36,26 +35,28 @@ func GenerateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
if total > constant.MaxNumb {
break
}
i++
}
return arr
}
func GenerateByteItemsRand(start byte, end byte, step int, repeat int) []interface{} {
arr := make([]interface{}, 0)
countInRound := int(end - start) / step + 1
countInRound := int(int(end) - int(start)) / step
total := 0
for round := 0; round < repeat; round++ {
for i := 0; i < countInRound; {
ran := rand.Intn(countInRound)
val := start + byte(ran)
for i := 0; i < countInRound; {
rand := commonUtils.RandNum(countInRound)
if step < 0 {
rand = rand * -1
}
val := start + byte(rand)
for round := 0; round < repeat; round++ {
arr = append(arr, val)
i++
total++
total++
if total > constant.MaxNumb {
break
}
......@@ -64,6 +65,7 @@ func GenerateByteItemsRand(start byte, end byte, step int, repeat int) []interfa
if total > constant.MaxNumb {
break
}
i++
}
return arr
......
package gen
import (
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"math/rand"
"strconv"
"strings"
)
......@@ -19,18 +19,17 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
arr := make([]interface{}, 0)
total := 0
for round := 0; round < repeat; round++ {
for i := 0; true; {
gap := float64(i) * step.(float64)
val := start + gap
if val > end {
break
}
for i := 0; true; {
val := start + float64(i) * step.(float64)
if (val > end && step.(float64) > 0) || (val < end && step.(float64) < 0) {
break
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
i++
total++
total++
if total > constant.MaxNumb {
break
}
......@@ -38,6 +37,7 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
if total > constant.MaxNumb {
break
}
i++
}
return arr
......@@ -47,16 +47,19 @@ func GenerateFloatItemsRand(start float64, end float64, step float64, repeat int
arr := make([]interface{}, 0)
countInRound := (end - start) / step
total := 0
for round := 0; round < repeat; round++ {
for i := float64(0); i < countInRound; {
val := start + float64(rand.Int63n(int64(countInRound)))*step
for i := float64(0); i < countInRound; {
rand := commonUtils.RandNum64(int64(countInRound))
if step < 0 {
rand = rand * -1
}
val := start + float64(rand) * step
for round := 0; round < repeat; round++ {
arr = append(arr, val)
i++
total++
total++
if total > constant.MaxNumb {
break
}
......@@ -65,6 +68,7 @@ func GenerateFloatItemsRand(start float64, end float64, step float64, repeat int
if total > constant.MaxNumb {
break
}
i++
}
return arr
......
package gen
import (
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"math/rand"
)
func GenerateIntItems(start int64, end int64, step interface{}, rand bool, limit int) []interface{} {
......@@ -44,15 +44,18 @@ func GenerateIntItemsByStep(start int64, end int64, step int, repeat int) []inte
func GenerateIntItemsRand(start int64, end int64, step int, repeat int) []interface{} {
arr := make([]interface{}, 0)
countInRound := (end - start) / int64(step) + 1
countInRound := (end - start) / int64(step)
total := 0
for round := 0; round < repeat; round++ {
for i := int64(0); i < countInRound; {
val := start + rand.Int63n(countInRound)
for i := int64(0); i < countInRound; {
rand := commonUtils.RandNum64(countInRound)
if step < 0 {
rand = rand * -1
}
val := start + rand
for round := 0; round < repeat; round++ {
arr = append(arr, val)
i++
total++
if total > constant.MaxNumb {
......@@ -63,6 +66,7 @@ func GenerateIntItemsRand(start int64, end int64, step int, repeat int) []interf
if total > constant.MaxNumb {
break
}
i++
}
return arr
......
......@@ -2,8 +2,8 @@ package gen
import (
"github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"math/rand"
"strconv"
"strings"
)
......@@ -94,7 +94,7 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
float1, errFloat1 := strconv.ParseFloat(startStr, 64)
float2, errFloat2 := strconv.ParseFloat(endStr, 64)
var errFloat3 error
if strings.ToLower(stepStr) != "r" {
if strings.ToLower(stepStr) != "" && strings.ToLower(stepStr) != "r" {
_, errFloat3 = strconv.ParseFloat(stepStr, 64)
}
if errFloat1 == nil && errFloat2 == nil && errFloat3 == nil { // is float
......@@ -110,8 +110,8 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
precision := getPrecision(float1, step)
if (float1 > float2 && step.(int) > 0) || (float1 < float2 && step.(int) < 0) {
step = -1 * step.(int)
if (float1 > float2 && step.(float64) > 0) || (float1 < float2 && step.(float64) < 0) {
step = -1 * step.(float64)
}
return "float", step, precision, rand
......@@ -145,18 +145,17 @@ func GenerateValuesFromLiteral(desc string, stepStr string, repeat int) []interf
total := 0
for i := 0; i < len(elemArr); {
for round := 0; round < repeat; round++ {
val := ""
if stepStr == "r" {
val = elemArr[rand.Intn(len(elemArr))]
} else {
val = elemArr[i]
}
val := ""
if stepStr == "r" {
val = elemArr[commonUtils.RandNum(len(elemArr))]
} else {
val = elemArr[i]
}
for round := 0; round < repeat; round++ {
items = append(items, val)
i += step
total++
total++
if total > constant.MaxNumb {
break
}
......@@ -165,6 +164,7 @@ func GenerateValuesFromLiteral(desc string, stepStr string, repeat int) []interf
if total >= constant.MaxNumb {
break
}
i += step
}
return items
......
......@@ -73,6 +73,8 @@ func ParseRangeItem(item string) (entry string, step string, repeat int) {
step = strings.ToLower(sectionArr[1])
}
if repeat == 0 { repeat = 1 }
if step == "" { step = "1" }
return entry, step, repeat
}
......@@ -107,7 +109,14 @@ func isBoundaryStr(str string) bool {
right := strings.TrimSpace(arr[1])
if len(left) != 1 || len(right) != 1 {
return false
leftRune := []rune(string(left[0]))[0]
rightRune := []rune(string(right[0]))[0]
if unicode.IsNumber(leftRune) && unicode.IsNumber(rightRune) {
return true
} else {
return false
}
} else {
leftRune := []rune(string(left[0]))[0]
rightRune := []rune(string(right[0]))[0]
......
......@@ -5,6 +5,7 @@ import (
"github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/emirpasic/gods/maps"
"math/rand"
"net"
"os"
"path"
......@@ -13,6 +14,7 @@ import (
"regexp"
"runtime"
"strings"
"time"
)
func Base(pathStr string) string {
......@@ -191,4 +193,19 @@ func GetIpType(IP net.IP) string {
}
}
return ""
}
func RandNum(length int) int {
randSeeds := time.Now().Unix() + int64(rand.Intn(100000000))
rand.Seed(randSeeds)
seedInt := rand.Intn(length)
return seedInt
}
func RandNum64(length int64) int64 {
randSeeds := time.Now().Unix() + int64(rand.Intn(100000000))
rand.Seed(randSeeds)
seedInt := rand.Int63n(length)
return seedInt
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册