-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfuzz-ints.go
56 lines (44 loc) · 1.38 KB
/
fuzz-ints.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
package testza
import (
"math"
"math/rand"
)
// FuzzIntFull returns a combination of every integer testset and some random integers (positive and negative).
func FuzzIntFull() (ints []int) {
for i := 0; i < 50; i++ {
ints = append(ints,
FuzzIntGenerateRandomPositive(1, i*1000)[0],
FuzzIntGenerateRandomNegative(1, i*1000*-1)[0],
)
}
return
}
// FuzzIntGenerateRandomRange generates random integers with a range of min to max.
func FuzzIntGenerateRandomRange(count, min, max int) (ints []int) {
for i := 0; i < count; i++ {
ints = append(ints, rand.Intn(max-min)+min)
}
return
}
// FuzzIntGenerateRandomPositive generates random positive integers with a maximum of max.
// If the maximum is 0, or below, the maximum will be set to math.MaxInt64.
func FuzzIntGenerateRandomPositive(count, max int) (ints []int) {
if max <= 0 {
max = math.MaxInt64
}
ints = append(ints, FuzzIntGenerateRandomRange(count, 1, max)...)
return
}
// FuzzIntGenerateRandomNegative generates random negative integers with a minimum of min.
// If the minimum is 0, or above, the maximum will be set to math.MinInt64.
func FuzzIntGenerateRandomNegative(count, min int) (ints []int) {
if min >= 0 {
min = math.MinInt64
}
min = int(math.Abs(float64(min)))
randomPositives := FuzzIntGenerateRandomPositive(count, min)
for _, p := range randomPositives {
ints = append(ints, p*-1)
}
return
}