diff --git a/pkg/elem/rand_range.go b/pkg/elem/rand_range.go index 89d0d96..0eff147 100644 --- a/pkg/elem/rand_range.go +++ b/pkg/elem/rand_range.go @@ -50,8 +50,24 @@ var randRangeCfg = &builtinConfig{ } data := i.(map[string]interface{}) - max := data["max"].(int) - min := data["min"].(int) + maxF, ok := data["max"].(float64) + var ( + max int + min int + ) + if !ok { + // has to be int at this point + max = data["max"].(int) + } else { + max = int(maxF) + } + minF, ok := data["min"].(float64) + if !ok { + // has to be int at this point + min = data["max"].(int) + } else { + min = int(minF) + } // This generates values for the following interval [min, max] e.g. {min <= x <= max} out.Push(min + rand.Intn(max-min+1)) } diff --git a/pkg/elem/rand_range_test.go b/pkg/elem/rand_range_test.go index 42a9703..a66fc8e 100644 --- a/pkg/elem/rand_range_test.go +++ b/pkg/elem/rand_range_test.go @@ -39,15 +39,13 @@ func Test_Rand_Range(t *testing.T) { o.Main().In().Push(map[string]interface{}{"min": 0, "max": 0}) a.PortPushes(0, o.Main().Out()) - // this breaks type conversion o = buildRandOperator(t) o.Main().In().Push(map[string]interface{}{"min": 0.0, "max": 0}) - a.PortPushes(nil, o.Main().Out()) + a.PortPushes(0, o.Main().Out()) - // this breaks type conversion o = buildRandOperator(t) o.Main().In().Push(map[string]interface{}{"min": "0.0", "max": 0}) - a.PortPushes(nil, o.Main().Out()) + a.PortPushes(0, o.Main().Out()) } func Test_Rand_Range_Negative_Values(t *testing.T) { a := assertions.New(t)