Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Implement fuzzing of complex types (#37)
Browse files Browse the repository at this point in the history
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 <mguerreiro@users.noreply.github.com>
  • Loading branch information
punkeel and mguerreiro committed Feb 3, 2020
1 parent 967ac50 commit 2257016
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2257016

Please sign in to comment.