From 225701601be54702d114845d7a272fba34aac808 Mon Sep 17 00:00:00 2001 From: Maxime Guerreiro Date: Mon, 3 Feb 2020 17:07:27 +0000 Subject: [PATCH] Implement fuzzing of complex types (#37) From builtin.go: The complex built-in function constructs a complex value from two floating-point values. The real and imaginary parts must be of the same size, either float32 or float64 (or assignable to them), and the return value will be the corresponding complex type (complex64 for float32, complex128 for float64). Co-authored-by: Maxime Guerreiro --- fuzz.go | 4 ++-- fuzz_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fuzz.go b/fuzz.go index da0a5f9..3c1ba51 100644 --- a/fuzz.go +++ b/fuzz.go @@ -450,10 +450,10 @@ var fillFuncMap = map[reflect.Kind]func(reflect.Value, *rand.Rand){ v.SetFloat(r.Float64()) }, reflect.Complex64: func(v reflect.Value, r *rand.Rand) { - panic("unimplemented") + v.SetComplex(complex128(complex(r.Float32(), r.Float32()))) }, reflect.Complex128: func(v reflect.Value, r *rand.Rand) { - panic("unimplemented") + v.SetComplex(complex(r.Float64(), r.Float64())) }, reflect.String: func(v reflect.Value, r *rand.Rand) { v.SetString(randString(r)) diff --git a/fuzz_test.go b/fuzz_test.go index 86ad2fa..b98ba63 100644 --- a/fuzz_test.go +++ b/fuzz_test.go @@ -39,6 +39,8 @@ func TestFuzz_basic(t *testing.T) { S string B bool T time.Time + C64 complex64 + C128 complex128 }{} failed := map[string]int{} @@ -87,6 +89,12 @@ func TestFuzz_basic(t *testing.T) { if n, v := "t", obj.T; v.IsZero() { failed[n] = failed[n] + 1 } + if n, v := "c64", obj.C64; v == 0 { + failed[n] = failed[n] + 1 + } + if n, v := "c128", obj.C128; v == 0 { + failed[n] = failed[n] + 1 + } } checkFailed(t, failed) }