-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathtesting_quick.htm
283 lines (144 loc) · 13.7 KB
/
testing_quick.htm
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html lang="en">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../assets/site.css" rel="stylesheet">
<title>testing/quick</title>
<meta name="twitter:title" content="Package quick">
<meta property="og:title" content="Package quick">
<meta name="description" content="Package quick implements utility functions to help with black box testing.">
<meta name="twitter:description" content="Package quick implements utility functions to help with black box testing.">
<meta property="og:description" content="Package quick implements utility functions to help with black box testing.">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@golang">
</head>
<body>
<div class="container">
<h2 id="pkg-overview">package quick</h2>
<p><code>import "testing/quick"</code>
<p>
Package quick implements utility functions to help with black box testing.
</p>
<p>
The testing/quick package is frozen and is not accepting new features.</p>
<h3 id="pkg-index" class="section-header">Index <a class="permalink" href="#pkg-index">¶</a></h3>
<ul class="list-unstyled">
<li><a href="#Check">func Check(f interface{}, config *Config) error</a></li><li><a href="#CheckEqual">func CheckEqual(f, g interface{}, config *Config) error</a></li><li><a href="#Value">func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)</a></li>
<li><a href="#CheckEqualError">type CheckEqualError</a></li>
<ul>
<li><a href="#CheckEqualError.Error">func (s *CheckEqualError) Error() string</a></li>
</ul>
<li><a href="#CheckError">type CheckError</a></li>
<ul>
<li><a href="#CheckError.Error">func (s *CheckError) Error() string</a></li>
</ul>
<li><a href="#Config">type Config</a></li>
<li><a href="#Generator">type Generator</a></li>
<li><a href="#SetupError">type SetupError</a></li>
<ul>
<li><a href="#SetupError.Error">func (s SetupError) Error() string</a></li>
</ul>
</ul>
<span id="pkg-examples"></span>
<h4 id="pkg-files">
<a href="https://github.com/golang/go/blob/master/src/testing/quick/">Package Files</a>
<a class="permalink" href="#pkg-files">¶</a>
</h4>
<p><a href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go">quick.go</a> </p>
<h3 id="Check" data-kind="f">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L258">Check</a> <a class="permalink" href="#Check">¶</a> <a class="uses" title="List Function Callers" href="https://sourcegraph.com/-/godoc/refs?def=Check&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L258">❖</a><pre>func Check(f interface{}, config *<a href="#Config">Config</a>) <a href="/builtin#error">error</a></pre></div><p>
Check looks for an input to f, any function that returns bool,
such that f returns false. It calls f repeatedly, with arbitrary
values for each argument. If f returns false on a given input,
Check returns that input as a *CheckError.
For example:
</p>
<pre>func TestOddMultipleOfThree(t *testing.T) {
f := func(x int) bool {
y := OddMultipleOfThree(x)
return y%2 == 1 && y%3 == 0
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}
</pre>
<h3 id="CheckEqual" data-kind="f">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L297">CheckEqual</a> <a class="permalink" href="#CheckEqual">¶</a> <a class="uses" title="List Function Callers" href="https://sourcegraph.com/-/godoc/refs?def=CheckEqual&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L297">❖</a><pre>func CheckEqual(f, g interface{}, config *<a href="#Config">Config</a>) <a href="/builtin#error">error</a></pre></div><p>
CheckEqual looks for an input on which f and g return different results.
It calls f and g repeatedly with arbitrary values for each argument.
If f and g return different answers, CheckEqual returns a *CheckEqualError
describing the input and the outputs.
</p>
<h3 id="Value" data-kind="f">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L56">Value</a> <a class="permalink" href="#Value">¶</a> <a class="uses" title="List Function Callers" href="https://sourcegraph.com/-/godoc/refs?def=Value&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L56">❖</a><pre>func Value(t <a href="/reflect">reflect</a>.<a href="/reflect#Type">Type</a>, rand *<a href="/math/rand">rand</a>.<a href="/math/rand#Rand">Rand</a>) (value <a href="/reflect">reflect</a>.<a href="/reflect#Value">Value</a>, ok <a href="/builtin#bool">bool</a>)</pre></div><p>
Value returns an arbitrary value of the given type.
If the type implements the Generator interface, that will be used.
Note: To create arbitrary values for structs, all the fields must be exported.
</p>
<h3 id="CheckEqualError" data-kind="t">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L233">CheckEqualError</a> <a class="permalink" href="#CheckEqualError">¶</a> <a class="uses" title="List Uses of This Type" href="https://sourcegraph.com/-/godoc/refs?def=CheckEqualError&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="decl" data-kind="d"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L233">❖</a><pre>type CheckEqualError struct {
<a href="#CheckError">CheckError</a>
<span id="CheckEqualError.Out1">Out1</span> []interface{}
<span id="CheckEqualError.Out2">Out2</span> []interface{}
}</pre></div><p>
A CheckEqualError is the result CheckEqual finding an error.
</p>
<h4 id="CheckEqualError.Error" data-kind="m">func (*CheckEqualError) <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L239">Error</a> <a class="permalink" href="#CheckEqualError.Error">¶</a> <a class="uses" title="List Method Callers" href="https://sourcegraph.com/-/godoc/refs?def=CheckEqualError%2FError&pkg=testing%2Fquick&repo=">Uses</a></h4>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L239">❖</a><pre>func (s *<a href="#CheckEqualError">CheckEqualError</a>) Error() <a href="/builtin#string">string</a></pre></div>
<h3 id="CheckError" data-kind="t">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L223">CheckError</a> <a class="permalink" href="#CheckError">¶</a> <a class="uses" title="List Uses of This Type" href="https://sourcegraph.com/-/godoc/refs?def=CheckError&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="decl" data-kind="d"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L223">❖</a><pre>type CheckError struct {
<span id="CheckError.Count">Count</span> <a href="/builtin#int">int</a>
<span id="CheckError.In">In</span> []interface{}
}</pre></div><p>
A CheckError is the result of Check finding an error.
</p>
<h4 id="CheckError.Error" data-kind="m">func (*CheckError) <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L228">Error</a> <a class="permalink" href="#CheckError.Error">¶</a> <a class="uses" title="List Method Callers" href="https://sourcegraph.com/-/godoc/refs?def=CheckError%2FError&pkg=testing%2Fquick&repo=">Uses</a></h4>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L228">❖</a><pre>func (s *<a href="#CheckError">CheckError</a>) Error() <a href="/builtin#string">string</a></pre></div>
<h3 id="Config" data-kind="t">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L174">Config</a> <a class="permalink" href="#Config">¶</a> <a class="uses" title="List Uses of This Type" href="https://sourcegraph.com/-/godoc/refs?def=Config&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="decl" data-kind="d"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L174">❖</a><pre>type Config struct {
<span class="com">// MaxCount sets the maximum number of iterations. If zero,
// MaxCountScale is used.</span>
<span id="Config.MaxCount">MaxCount</span> <a href="/builtin#int">int</a>
<span class="com">// MaxCountScale is a non-negative scale factor applied to the default
// maximum. If zero, the default is unchanged.</span>
<span id="Config.MaxCountScale">MaxCountScale</span> <a href="/builtin#float64">float64</a>
<span class="com">// If non-nil, rand is a source of random numbers. Otherwise a default
// pseudo-random source will be used.</span>
<span id="Config.Rand">Rand</span> *<a href="/math/rand">rand</a>.<a href="/math/rand#Rand">Rand</a>
<span class="com">// If non-nil, the Values function generates a slice of arbitrary
// reflect.Values that are congruent with the arguments to the function
// being tested. Otherwise, the top-level Value function is used
// to generate them.</span>
<span id="Config.Values">Values</span> func([]<a href="/reflect">reflect</a>.<a href="/reflect#Value">Value</a>, *<a href="/math/rand">rand</a>.<a href="/math/rand#Rand">Rand</a>)
}</pre></div><p>
A Config structure contains options for running a test.
</p>
<h3 id="Generator" data-kind="t">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L22">Generator</a> <a class="permalink" href="#Generator">¶</a> <a class="uses" title="List Uses of This Type" href="https://sourcegraph.com/-/godoc/refs?def=Generator&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="decl" data-kind="m"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L22">❖</a><pre>type Generator interface {
<span class="com">// Generate returns a random instance of the type on which it is a
// method using the size as a size hint.</span>
<span id="Generator.Generate">Generate</span>(rand *<a href="/math/rand">rand</a>.<a href="/math/rand#Rand">Rand</a>, size <a href="/builtin#int">int</a>) <a href="/reflect">reflect</a>.<a href="/reflect#Value">Value</a>
}</pre></div><p>
A Generator can generate random values of its own type.
</p>
<h3 id="SetupError" data-kind="t">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L218">SetupError</a> <a class="permalink" href="#SetupError">¶</a> <a class="uses" title="List Uses of This Type" href="https://sourcegraph.com/-/godoc/refs?def=SetupError&pkg=testing%2Fquick&repo=">Uses</a></h3>
<div class="decl" data-kind="d"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L218">❖</a><pre>type SetupError <a href="/builtin#string">string</a></pre></div><p>
A SetupError is the result of an error in the way that check is being
used, independent of the functions being tested.
</p>
<h4 id="SetupError.Error" data-kind="m">func (SetupError) <a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L220">Error</a> <a class="permalink" href="#SetupError.Error">¶</a> <a class="uses" title="List Method Callers" href="https://sourcegraph.com/-/godoc/refs?def=SetupError%2FError&pkg=testing%2Fquick&repo=">Uses</a></h4>
<div class="funcdecl decl"><a title="View Source" href="https://github.com/golang/go/blob/master/src/testing/quick/quick.go#L220">❖</a><pre>func (s <a href="#SetupError">SetupError</a>) Error() <a href="/builtin#string">string</a></pre></div>
<div id="x-footer" class="clearfix">
<div class="container">
<a href="http://studygolang.com/" target="_blank">Go语言中文网</a>
<span class="text-muted">|</span> <a href="http://golang.org/" target="_blank">Go Language</a>
<span class="pull-right"><a href="#">Back to top</a></span>
</div>
</div>
<script src="../assets/jquery-2.0.3.min.js"></script>
<script src="../assets/bootstrap.min.js"></script>
<script src="../assets/site.js"></script>
</body>
</html>