Skip to content

Commit 5ee493b

Browse files
committed
add counter reset for double type
1 parent 4fbeb8a commit 5ee493b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/genlib/generator_interface.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,18 @@ func bindDoubleWithReturn(fieldCfg ConfigField, field Field, fieldMap map[string
11201120
return err
11211121
}
11221122

1123+
if err := fieldCfg.ValidateCounterResetStrategy(); err != nil {
1124+
return err
1125+
}
1126+
1127+
if err := fieldCfg.ValidateCounterResetAfterN(); err != nil {
1128+
return err
1129+
}
1130+
1131+
if err := fieldCfg.ValidateCounterResetProbabilistic(); err != nil {
1132+
return err
1133+
}
1134+
11231135
if len(fieldCfg.Enum) > 0 {
11241136
var emitF emitF
11251137
idx := customRand.Intn(len(fieldCfg.Enum))
@@ -1157,6 +1169,26 @@ func bindDoubleWithReturn(fieldCfg ConfigField, field Field, fieldMap map[string
11571169
dummyFloat = fuzzyFloatCounter(previous, fieldCfg.Fuzziness)
11581170
}
11591171

1172+
if fieldCfg.CounterReset != nil {
1173+
switch fieldCfg.CounterReset.Strategy {
1174+
case config.CounterResetStrategyRandom:
1175+
// 50% chance to reset
1176+
if customRand.Intn(2) == 0 {
1177+
dummyFloat = 0
1178+
}
1179+
case config.CounterResetStrategyProbabilistic:
1180+
// Probability% chance to reset
1181+
if customRand.Intn(100) < int(*fieldCfg.CounterReset.Probability) {
1182+
dummyFloat = 0
1183+
}
1184+
case config.CounterResetStrategyAfterN:
1185+
// Reset after N
1186+
if state.counter%*fieldCfg.CounterReset.ResetAfterN == 0 {
1187+
dummyFloat = 0
1188+
}
1189+
}
1190+
}
1191+
11601192
state.prevCache[field.Name] = dummyFloat
11611193
return dummyFloat
11621194
}

0 commit comments

Comments
 (0)