-
Notifications
You must be signed in to change notification settings - Fork 25
/
engine_fuzz_test.go
68 lines (59 loc) · 1.54 KB
/
engine_fuzz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2022 Gregory Petrosyan <gregory.petrosyan@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package rapid_test
import (
"testing"
. "pgregory.net/rapid"
)
func checkInt(t *T) {
answer := Int().Draw(t, "answer")
if answer == 42 {
t.Fatalf("fuzzing works")
}
}
func checkSlice(t *T) {
slice := SliceOfN(Int(), 5, 5).Draw(t, "slice")
if slice[0] < slice[1] && slice[1] < slice[2] && slice[2] < slice[3] && slice[3] < slice[4] {
t.Fatalf("fuzzing works")
}
}
func checkString(t *T) {
hello := String().Draw(t, "hello")
if hello == "world" {
t.Fatalf("fuzzing works")
}
}
func checkStuckStateMachine(t *T) {
die := 0
t.Repeat(map[string]func(*T){
"roll": func(t *T) {
if die == 6 {
t.Skip("game over")
}
die = IntRange(1, 6).Draw(t, "die")
},
})
}
func TestRapidInt(t *testing.T) {
t.Skip()
Check(t, checkInt)
}
func TestRapidSlice(t *testing.T) {
t.Skip()
Check(t, checkSlice)
}
func TestRapidString(t *testing.T) {
t.Skip()
Check(t, checkString)
}
func TestRapidStuckStateMachine(t *testing.T) {
t.Skip()
Check(t, checkStuckStateMachine)
}
func FuzzInt(f *testing.F) { f.Fuzz(MakeFuzz(checkInt)) }
func FuzzSlice(f *testing.F) { f.Fuzz(MakeFuzz(checkSlice)) }
func FuzzString(f *testing.F) { f.Fuzz(MakeFuzz(checkString)) }
func FuzzStuckStateMachine(f *testing.F) { f.Fuzz(MakeFuzz(checkStuckStateMachine)) }