Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
e1b0eab3
Z
zendata
项目概览
易企天创
/
zendata
8 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e1b0eab3
编写于
9月 18, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generate random values in field section level, not just after get the limit values
上级
9a905f3d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
93 addition
and
77 deletion
+93
-77
src/gen/charVal.go
src/gen/charVal.go
+38
-37
src/gen/floatVal.go
src/gen/floatVal.go
+42
-33
src/gen/generator.go
src/gen/generator.go
+1
-1
src/gen/intVal.go
src/gen/intVal.go
+1
-1
src/gen/list.go
src/gen/list.go
+11
-5
未找到文件。
src/gen/charVal.go
浏览文件 @
e1b0eab3
package
gen
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
)
//func GenerateByteItems(start byte, end byte, step interface{}
, rand bool, repeat int) []interface{} {
//
if !rand {
// return GenerateByteItemsByStep(start, end, step.(int)
, repeat)
// } else
{
// return GenerateByteItemsRand(start, end, step.(int)
, repeat)
//
}
//
}
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
int
,
rand
bool
,
repeat
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateByteItemsByStep
(
start
,
end
,
step
,
repeat
)
}
else
{
return
GenerateByteItemsRand
(
start
,
end
,
step
,
repeat
)
}
}
func
GenerateByteItemsByStep
(
start
byte
,
end
byte
,
step
int
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
...
...
@@ -39,33 +40,33 @@ func GenerateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
return
arr
}
//func GenerateByteItemsRand(start byte, end byte, step int, repeat int) []interface{} {
// arr := make([]interface{}, 0)
//
// countInRound := int(int(end) - int(start)) / step
// total := 0
// 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)
//
// total++
// if total > constant.MaxNumb {
// break
// }
// }
//
// if total > constant.MaxNumb {
// break
// }
// i++
// }
//
// return arr
//}
\ No newline at end of file
func
GenerateByteItemsRand
(
start
byte
,
end
byte
,
step
int
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
countInRound
:=
(
int
(
end
)
-
int
(
start
))
/
step
total
:=
0
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
)
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
if
total
>
constant
.
MaxNumb
{
break
}
i
++
}
return
arr
}
\ No newline at end of file
src/gen/floatVal.go
浏览文件 @
e1b0eab3
package
gen
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
"strconv"
"strings"
)
func
GenerateFloatItemsByStep
(
start
float64
,
end
float64
,
step
interface
{},
repeat
int
)
[]
interface
{}
{
func
GenerateFloatItems
(
start
float64
,
end
float64
,
step
interface
{},
rand
bool
,
repeat
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateFloatItemsByStep
(
start
,
end
,
step
.
(
float64
),
repeat
)
}
else
{
return
GenerateFloatItemsRand
(
start
,
end
,
step
.
(
float64
),
repeat
)
}
}
func
GenerateFloatItemsByStep
(
start
float64
,
end
float64
,
step
float64
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
total
:=
0
for
i
:=
0
;
true
;
{
val
:=
start
+
float64
(
i
)
*
step
.
(
float64
)
if
(
val
>
end
&&
step
.
(
float64
)
>
0
)
||
(
val
<
end
&&
step
.
(
float64
)
<
0
)
{
val
:=
start
+
float64
(
i
)
*
step
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
...
...
@@ -34,36 +43,36 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
return
arr
}
//
func GenerateFloatItemsRand(start float64, end float64, step float64, repeat int) []interface{} {
//
arr := make([]interface{}, 0)
//
//
countInRound := (end - start) / step
//
total := 0
//
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)
//
//
total++
//
if total > constant.MaxNumb {
//
break
//
}
//
}
//
//
if total > constant.MaxNumb {
//
break
//
}
//
i++
//
}
//
//
return arr
//
}
func
GenerateFloatItemsRand
(
start
float64
,
end
float64
,
step
float64
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
countInRound
:=
(
end
-
start
)
/
step
total
:=
0
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
)
total
++
if
total
>
constant
.
MaxNumb
{
break
}
}
if
total
>
constant
.
MaxNumb
{
break
}
i
++
}
return
arr
}
func
GetPrecision
(
base
float64
,
step
interface
{})
(
precision
int
,
newStep
float64
)
{
val
:=
base
...
...
src/gen/generator.go
浏览文件 @
e1b0eab3
...
...
@@ -206,7 +206,7 @@ func GenerateFieldValuesForDef(field *model.DefField) []string {
values
=
append
(
values
,
val
)
count
++
isRandomAndLoopEnd
:=
!
vari
.
ResLoading
&&
// ignore rand in res
isRandomAndLoopEnd
:=
!
vari
.
ResLoading
&&
// ignore rand in res
ource
!
(
*
field
)
.
ReferToAnotherYaml
&&
(
*
field
)
.
IsRand
&&
(
*
field
)
.
LoopIndex
==
(
*
field
)
.
LoopEnd
// isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values)
if
count
>=
vari
.
Total
||
count
>=
len
(
fieldWithValues
.
Values
)
||
isRandomAndLoopEnd
{
...
...
src/gen/intVal.go
浏览文件 @
e1b0eab3
...
...
@@ -18,7 +18,7 @@ func GenerateIntItemsByStep(start int64, end int64, step int, repeat int) []inte
total
:=
0
for
i
:=
0
;
true
;
{
val
:=
start
+
int64
(
i
*
step
)
val
:=
start
+
int64
(
i
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
}
...
...
src/gen/list.go
浏览文件 @
e1b0eab3
...
...
@@ -2,6 +2,7 @@ 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"
"github.com/easysoft/zendata/src/utils/vari"
"strconv"
...
...
@@ -171,7 +172,12 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
}
for
i
:=
0
;
i
<
len
(
elemArr
);
{
val
:=
elemArr
[
i
]
idx
:=
i
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
idx
=
commonUtils
.
RandNum
(
len
(
elemArr
))
// should set random here too
}
val
:=
elemArr
[
idx
]
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
val
)
...
...
@@ -216,17 +222,17 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
items
=
GenerateIntItems
ByStep
(
startInt
,
endInt
,
step
.
(
int
)
,
repeat
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
.
(
int
),
rand
,
repeat
)
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
items
=
GenerateFloatItems
ByStep
(
startFloat
,
endFloat
,
step
.
(
float64
)
,
repeat
)
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
,
rand
,
repeat
)
}
else
if
dataType
==
"char"
{
items
=
GenerateByteItems
ByStep
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
)
,
repeat
)
items
=
GenerateByteItems
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
),
rand
,
repeat
)
}
else
if
dataType
==
"string"
{
if
repeat
==
0
{
repeat
=
1
}
...
...
@@ -235,7 +241,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
}
}
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
// for ranges and instances, random
if
field
.
Path
==
""
&&
stepStr
==
"r"
{
// for ranges and instances, random
again
items
=
randomInterfaces
(
items
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录