forked from PaesslerAG/gval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_test.go
129 lines (120 loc) · 1.41 KB
/
random_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package gval
// Courtesy of abrander
// ref: https://gist.github.com/abrander/fa05ae9b181b48ffe7afb12c961b6e90
import (
"fmt"
"math/rand"
"testing"
"time"
)
var (
hello = "hello"
empty struct{}
empty2 *string
empty3 *int
values = []interface{}{
-1,
0,
12,
13,
"",
"hello",
&hello,
nil,
"nil",
empty,
empty2,
true,
false,
time.Now(),
rune('r'),
int64(34),
time.Duration(0),
"true",
"false",
"\ntrue\n",
"\nfalse\n",
"12",
"nil",
"arg1",
"arg2",
int(12),
int32(12),
int64(12),
complex(1.0, 1.0),
[]byte{0, 0, 0},
[]int{0, 0, 0},
[]string{},
"[]",
"{}",
"\"\"",
"\"12\"",
"\"hello\"",
".*",
"==",
"!=",
">",
">=",
"<",
"<=",
"=~",
"!~",
"in",
"&&",
"||",
"^",
"&",
"|",
">>",
"<<",
"+",
"-",
"*",
"/",
"%",
"**",
"-",
"!",
"~",
"?",
":",
"??",
"+",
"-",
"*",
"/",
"%",
"**",
"&",
"|",
"^",
">>",
"<<",
",",
"(",
")",
"[",
"]",
"\n",
"\000",
}
panics = 0
)
const (
SEED = 1487873697990155515
)
func BenchmarkRandom(bench *testing.B) {
rand.Seed(SEED)
for i := 0; i < bench.N; i++ {
num := rand.Intn(3) + 2
expression := ""
for n := 0; n < num; n++ {
expression += fmt.Sprintf(" %s", getRandom(values))
}
Evaluate(expression, nil)
}
}
func getRandom(haystack []interface{}) interface{} {
i := rand.Intn(len(haystack))
return haystack[i]
}