Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
e1b0eab3
Z
zendata
项目概览
LinuxSuRen
/
zendata
与 Fork 源项目一致
Fork自
易企天创 / zendata
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
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
package
gen
import
(
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
constant
"github.com/easysoft/zendata/src/utils/const"
)
)
//func GenerateByteItems(start byte, end byte, step interface{}
, rand bool, repeat int) []interface{} {
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
int
,
rand
bool
,
repeat
int
)
[]
interface
{}
{
//
if !rand {
if
!
rand
{
// return GenerateByteItemsByStep(start, end, step.(int)
, repeat)
return
GenerateByteItemsByStep
(
start
,
end
,
step
,
repeat
)
// } else
{
}
else
{
// return GenerateByteItemsRand(start, end, step.(int)
, repeat)
return
GenerateByteItemsRand
(
start
,
end
,
step
,
repeat
)
//
}
}
//
}
}
func
GenerateByteItemsByStep
(
start
byte
,
end
byte
,
step
int
,
repeat
int
)
[]
interface
{}
{
func
GenerateByteItemsByStep
(
start
byte
,
end
byte
,
step
int
,
repeat
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
arr
:=
make
([]
interface
{},
0
)
...
@@ -39,33 +40,33 @@ func GenerateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
...
@@ -39,33 +40,33 @@ func GenerateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
return
arr
return
arr
}
}
//func GenerateByteItemsRand(start byte, end byte, step int, repeat int) []interface{} {
func
GenerateByteItemsRand
(
start
byte
,
end
byte
,
step
int
,
repeat
int
)
[]
interface
{}
{
// arr := make([]interface{}, 0)
arr
:=
make
([]
interface
{},
0
)
//
// countInRound := int(int(end) - int(start)) / step
countInRound
:=
(
int
(
end
)
-
int
(
start
))
/
step
// total := 0
total
:=
0
// for i := 0; i < countInRound; {
for
i
:=
0
;
i
<
countInRound
;
{
// rand := commonUtils.RandNum(countInRound)
rand
:=
commonUtils
.
RandNum
(
countInRound
)
// if step < 0 {
if
step
<
0
{
// rand = rand * -1
rand
=
rand
*
-
1
// }
}
//
// val := start + byte(rand)
val
:=
start
+
byte
(
rand
)
//
// for round := 0; round < repeat; round++ {
for
round
:=
0
;
round
<
repeat
;
round
++
{
// arr = append(arr, val)
arr
=
append
(
arr
,
val
)
//
// total++
total
++
// if total > constant.MaxNumb {
if
total
>
constant
.
MaxNumb
{
// break
break
// }
}
// }
}
//
// if total > constant.MaxNumb {
if
total
>
constant
.
MaxNumb
{
// break
break
// }
}
// i++
i
++
// }
}
//
// return arr
return
arr
//}
}
\ No newline at end of file
\ No newline at end of file
src/gen/floatVal.go
浏览文件 @
e1b0eab3
package
gen
package
gen
import
(
import
(
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
constant
"github.com/easysoft/zendata/src/utils/const"
"strconv"
"strconv"
"strings"
"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
)
arr
:=
make
([]
interface
{},
0
)
total
:=
0
total
:=
0
for
i
:=
0
;
true
;
{
for
i
:=
0
;
true
;
{
val
:=
start
+
float64
(
i
)
*
step
.
(
float64
)
val
:=
start
+
float64
(
i
)
*
step
if
(
val
>
end
&&
step
.
(
float64
)
>
0
)
||
(
val
<
end
&&
step
.
(
float64
)
<
0
)
{
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
break
}
}
...
@@ -34,36 +43,36 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
...
@@ -34,36 +43,36 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
return
arr
return
arr
}
}
//
func GenerateFloatItemsRand(start float64, end float64, step float64, repeat int) []interface{} {
func
GenerateFloatItemsRand
(
start
float64
,
end
float64
,
step
float64
,
repeat
int
)
[]
interface
{}
{
//
arr := make([]interface{}, 0)
arr
:=
make
([]
interface
{},
0
)
//
//
countInRound := (end - start) / step
countInRound
:=
(
end
-
start
)
/
step
//
total := 0
total
:=
0
//
for i := float64(0); i < countInRound; {
for
i
:=
float64
(
0
);
i
<
countInRound
;
{
//
rand := commonUtils.RandNum64(int64(countInRound))
rand
:=
commonUtils
.
RandNum64
(
int64
(
countInRound
))
//
if step < 0 {
if
step
<
0
{
//
rand = rand * -1
rand
=
rand
*
-
1
//
}
}
//
//
val := start + float64(rand) * step
val
:=
start
+
float64
(
rand
)
*
step
//
//
for round := 0; round < repeat; round++ {
for
round
:=
0
;
round
<
repeat
;
round
++
{
//
arr = append(arr, val)
arr
=
append
(
arr
,
val
)
//
//
total++
total
++
//
if total > constant.MaxNumb {
if
total
>
constant
.
MaxNumb
{
//
break
break
//
}
}
//
}
}
//
//
if total > constant.MaxNumb {
if
total
>
constant
.
MaxNumb
{
//
break
break
//
}
}
//
i++
i
++
//
}
}
//
//
return arr
return
arr
//
}
}
func
GetPrecision
(
base
float64
,
step
interface
{})
(
precision
int
,
newStep
float64
)
{
func
GetPrecision
(
base
float64
,
step
interface
{})
(
precision
int
,
newStep
float64
)
{
val
:=
base
val
:=
base
...
...
src/gen/generator.go
浏览文件 @
e1b0eab3
...
@@ -206,7 +206,7 @@ func GenerateFieldValuesForDef(field *model.DefField) []string {
...
@@ -206,7 +206,7 @@ func GenerateFieldValuesForDef(field *model.DefField) []string {
values
=
append
(
values
,
val
)
values
=
append
(
values
,
val
)
count
++
count
++
isRandomAndLoopEnd
:=
!
vari
.
ResLoading
&&
// ignore rand in res
isRandomAndLoopEnd
:=
!
vari
.
ResLoading
&&
// ignore rand in res
ource
!
(
*
field
)
.
ReferToAnotherYaml
&&
(
*
field
)
.
IsRand
&&
(
*
field
)
.
LoopIndex
==
(
*
field
)
.
LoopEnd
!
(
*
field
)
.
ReferToAnotherYaml
&&
(
*
field
)
.
IsRand
&&
(
*
field
)
.
LoopIndex
==
(
*
field
)
.
LoopEnd
// isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values)
// isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values)
if
count
>=
vari
.
Total
||
count
>=
len
(
fieldWithValues
.
Values
)
||
isRandomAndLoopEnd
{
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
...
@@ -18,7 +18,7 @@ func GenerateIntItemsByStep(start int64, end int64, step int, repeat int) []inte
total
:=
0
total
:=
0
for
i
:=
0
;
true
;
{
for
i
:=
0
;
true
;
{
val
:=
start
+
int64
(
i
*
step
)
val
:=
start
+
int64
(
i
*
step
)
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
if
(
val
>
end
&&
step
>
0
)
||
(
val
<
end
&&
step
<
0
)
{
break
break
}
}
...
...
src/gen/list.go
浏览文件 @
e1b0eab3
...
@@ -2,6 +2,7 @@ package gen
...
@@ -2,6 +2,7 @@ package gen
import
(
import
(
"github.com/easysoft/zendata/src/model"
"github.com/easysoft/zendata/src/model"
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
constant
"github.com/easysoft/zendata/src/utils/const"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/easysoft/zendata/src/utils/vari"
"strconv"
"strconv"
...
@@ -171,7 +172,12 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
...
@@ -171,7 +172,12 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
}
}
for
i
:=
0
;
i
<
len
(
elemArr
);
{
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
++
{
for
round
:=
0
;
round
<
repeat
;
round
++
{
items
=
append
(
items
,
val
)
items
=
append
(
items
,
val
)
...
@@ -216,17 +222,17 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
...
@@ -216,17 +222,17 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
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"
{
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
field
.
Precision
=
precision
items
=
GenerateFloatItems
ByStep
(
startFloat
,
endFloat
,
step
.
(
float64
)
,
repeat
)
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
,
rand
,
repeat
)
}
else
if
dataType
==
"char"
{
}
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"
{
}
else
if
dataType
==
"string"
{
if
repeat
==
0
{
repeat
=
1
}
if
repeat
==
0
{
repeat
=
1
}
...
@@ -235,7 +241,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
...
@@ -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
)
items
=
randomInterfaces
(
items
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录