You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
13 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>quick - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package quick</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "testing/quick"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package quick implements utility functions to help with black box testing.
  68. </p>
  69. </div>
  70. </div>
  71. <div id="pkg-index" class="toggleVisible">
  72. <div class="collapsed">
  73. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  74. </div>
  75. <div class="expanded">
  76. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  77. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  78. <div id="manual-nav">
  79. <dl>
  80. <dd><a href="index.html#Check">func Check(f interface{}, config *Config) (err error)</a></dd>
  81. <dd><a href="index.html#CheckEqual">func CheckEqual(f, g interface{}, config *Config) (err error)</a></dd>
  82. <dd><a href="index.html#Value">func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)</a></dd>
  83. <dd><a href="index.html#CheckEqualError">type CheckEqualError</a></dd>
  84. <dd>&nbsp; &nbsp; <a href="index.html#CheckEqualError.Error">func (s *CheckEqualError) Error() string</a></dd>
  85. <dd><a href="index.html#CheckError">type CheckError</a></dd>
  86. <dd>&nbsp; &nbsp; <a href="index.html#CheckError.Error">func (s *CheckError) Error() string</a></dd>
  87. <dd><a href="index.html#Config">type Config</a></dd>
  88. <dd><a href="index.html#Generator">type Generator</a></dd>
  89. <dd><a href="index.html#SetupError">type SetupError</a></dd>
  90. <dd>&nbsp; &nbsp; <a href="index.html#SetupError.Error">func (s SetupError) Error() string</a></dd>
  91. </dl>
  92. </div><!-- #manual-nav -->
  93. <h4>Package files</h4>
  94. <p>
  95. <span style="font-size:90%">
  96. <a href="http://localhost:6060/src/testing/quick/quick.go">quick.go</a>
  97. </span>
  98. </p>
  99. </div><!-- .expanded -->
  100. </div><!-- #pkg-index -->
  101. <div id="pkg-callgraph" class="toggle" style="display: none">
  102. <div class="collapsed">
  103. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  104. </div> <!-- .expanded -->
  105. <div class="expanded">
  106. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  107. <p>
  108. In the call graph viewer below, each node
  109. is a function belonging to this package
  110. and its children are the functions it
  111. calls&mdash;perhaps dynamically.
  112. </p>
  113. <p>
  114. The root nodes are the entry points of the
  115. package: functions that may be called from
  116. outside the package.
  117. There may be non-exported or anonymous
  118. functions among them if they are called
  119. dynamically from another package.
  120. </p>
  121. <p>
  122. Click a node to visit that function's source code.
  123. From there you can visit its callers by
  124. clicking its declaring <code>func</code>
  125. token.
  126. </p>
  127. <p>
  128. Functions may be omitted if they were
  129. determined to be unreachable in the
  130. particular programs or tests that were
  131. analyzed.
  132. </p>
  133. <!-- Zero means show all package entry points. -->
  134. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  135. </div>
  136. </div> <!-- #pkg-callgraph -->
  137. <h2 id="Check">func <a href="http://localhost:6060/src/testing/quick/quick.go?s=7371:7424#L246">Check</a></h2>
  138. <pre>func Check(f interface{}, config *<a href="index.html#Config">Config</a>) (err <a href="../../builtin/index.html#error">error</a>)</pre>
  139. <p>
  140. Check looks for an input to f, any function that returns bool,
  141. such that f returns false. It calls f repeatedly, with arbitrary
  142. values for each argument. If f returns false on a given input,
  143. Check returns that input as a *CheckError.
  144. For example:
  145. </p>
  146. <pre>func TestOddMultipleOfThree(t *testing.T) {
  147. f := func(x int) bool {
  148. y := OddMultipleOfThree(x)
  149. return y%2 == 1 &amp;&amp; y%3 == 0
  150. }
  151. if err := quick.Check(f, nil); err != nil {
  152. t.Error(err)
  153. }
  154. }
  155. </pre>
  156. <h2 id="CheckEqual">func <a href="http://localhost:6060/src/testing/quick/quick.go?s=8414:8475#L289">CheckEqual</a></h2>
  157. <pre>func CheckEqual(f, g interface{}, config *<a href="index.html#Config">Config</a>) (err <a href="../../builtin/index.html#error">error</a>)</pre>
  158. <p>
  159. CheckEqual looks for an input on which f and g return different results.
  160. It calls f and g repeatedly with arbitrary values for each argument.
  161. If f and g return different answers, CheckEqual returns a *CheckEqualError
  162. describing the input and the outputs.
  163. </p>
  164. <h2 id="Value">func <a href="http://localhost:6060/src/testing/quick/quick.go?s=1568:1642#L44">Value</a></h2>
  165. <pre>func Value(t <a href="../../reflect/index.html">reflect</a>.<a href="../../reflect/index.html#Type">Type</a>, rand *<a href="../../math/rand/index.html">rand</a>.<a href="../../math/rand/index.html#Rand">Rand</a>) (value <a href="../../reflect/index.html">reflect</a>.<a href="../../reflect/index.html#Value">Value</a>, ok <a href="../../builtin/index.html#bool">bool</a>)</pre>
  166. <p>
  167. Value returns an arbitrary value of the given type.
  168. If the type implements the Generator interface, that will be used.
  169. Note: To create arbitrary values for structs, all the fields must be exported.
  170. </p>
  171. <h2 id="CheckEqualError">type <a href="http://localhost:6060/src/testing/quick/quick.go?s=6605:6688#L221">CheckEqualError</a></h2>
  172. <pre>type CheckEqualError struct {
  173. <a href="index.html#CheckError">CheckError</a>
  174. Out1 []interface{}
  175. Out2 []interface{}
  176. }</pre>
  177. <p>
  178. A CheckEqualError is the result CheckEqual finding an error.
  179. </p>
  180. <h3 id="CheckEqualError.Error">func (*CheckEqualError) <a href="http://localhost:6060/src/testing/quick/quick.go?s=6690:6730#L227">Error</a></h3>
  181. <pre>func (s *<a href="index.html#CheckEqualError">CheckEqualError</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  182. <h2 id="CheckError">type <a href="http://localhost:6060/src/testing/quick/quick.go?s=6368:6426#L211">CheckError</a></h2>
  183. <pre>type CheckError struct {
  184. Count <a href="../../builtin/index.html#int">int</a>
  185. In []interface{}
  186. }</pre>
  187. <p>
  188. A CheckError is the result of Check finding an error.
  189. </p>
  190. <h3 id="CheckError.Error">func (*CheckError) <a href="http://localhost:6060/src/testing/quick/quick.go?s=6428:6463#L216">Error</a></h3>
  191. <pre>func (s *<a href="index.html#CheckError">CheckError</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  192. <h2 id="Config">type <a href="http://localhost:6060/src/testing/quick/quick.go?s=4904:5569#L162">Config</a></h2>
  193. <pre>type Config struct {
  194. <span class="comment">// MaxCount sets the maximum number of iterations. If zero,</span>
  195. <span class="comment">// MaxCountScale is used.</span>
  196. MaxCount <a href="../../builtin/index.html#int">int</a>
  197. <span class="comment">// MaxCountScale is a non-negative scale factor applied to the default</span>
  198. <span class="comment">// maximum. If zero, the default is unchanged.</span>
  199. MaxCountScale <a href="../../builtin/index.html#float64">float64</a>
  200. <span class="comment">// If non-nil, rand is a source of random numbers. Otherwise a default</span>
  201. <span class="comment">// pseudo-random source will be used.</span>
  202. Rand *<a href="../../math/rand/index.html">rand</a>.<a href="../../math/rand/index.html#Rand">Rand</a>
  203. <span class="comment">// If non-nil, the Values function generates a slice of arbitrary</span>
  204. <span class="comment">// reflect.Values that are congruent with the arguments to the function</span>
  205. <span class="comment">// being tested. Otherwise, the top-level Value function is used</span>
  206. <span class="comment">// to generate them.</span>
  207. Values func([]<a href="../../reflect/index.html">reflect</a>.<a href="../../reflect/index.html#Value">Value</a>, *<a href="../../math/rand/index.html">rand</a>.<a href="../../math/rand/index.html#Rand">Rand</a>)
  208. }</pre>
  209. <p>
  210. A Config structure contains options for running a test.
  211. </p>
  212. <h2 id="Generator">type <a href="http://localhost:6060/src/testing/quick/quick.go?s=490:679#L10">Generator</a></h2>
  213. <pre>type Generator interface {
  214. <span class="comment">// Generate returns a random instance of the type on which it is a</span>
  215. <span class="comment">// method using the size as a size hint.</span>
  216. Generate(rand *<a href="../../math/rand/index.html">rand</a>.<a href="../../math/rand/index.html#Rand">Rand</a>, size <a href="../../builtin/index.html#int">int</a>) <a href="../../reflect/index.html">reflect</a>.<a href="../../reflect/index.html#Value">Value</a>
  217. }</pre>
  218. <p>
  219. A Generator can generate random values of its own type.
  220. </p>
  221. <h2 id="SetupError">type <a href="http://localhost:6060/src/testing/quick/quick.go?s=6230:6252#L206">SetupError</a></h2>
  222. <pre>type SetupError <a href="../../builtin/index.html#string">string</a></pre>
  223. <p>
  224. A SetupError is the result of an error in the way that check is being
  225. used, independent of the functions being tested.
  226. </p>
  227. <h3 id="SetupError.Error">func (SetupError) <a href="http://localhost:6060/src/testing/quick/quick.go?s=6254:6288#L208">Error</a></h3>
  228. <pre>func (s <a href="index.html#SetupError">SetupError</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  229. <div id="footer">
  230. Build version go1.6.<br>
  231. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  232. the content of this page is licensed under the
  233. Creative Commons Attribution 3.0 License,
  234. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  235. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  236. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  237. </div>
  238. </div><!-- .container -->
  239. </div><!-- #page -->
  240. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  241. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  242. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  243. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  244. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  245. </body>
  246. </html>