source: project/wiki/eggref/4/test-generative @ 30592

Last change on this file since 30592 was 30592, checked in by certainty, 7 years ago

test-generative: fixed typo

File size: 3.1 KB
Line 
1== test-generative
2[[toc:]]
3
4=== Requirements
5[[/egg/test|test]]
6
7
8=== Repository
9[[https://bitbucket.org/certainty/test-generative/overview]]
10
11
12=== Authors
13[[/users/david-krentzlin|David Krentzlin]]
14
15
16=== Introduction
17
18This egg integrates [[http://www.cse.chalmers.se/~rjmh/QuickCheck/|quickcheck-like]] on top of our very excellent [[/egg/test|test egg]].
19
20It allows you to throw a bunch of random inputs at your '''pure''' code and use the well known test macros to verify its behavior.
21This way you don't have to learn a new testing API but still get the benefits of random testing for your pure code.
22
23This library is not meant to replace traditional manual unit tests but shall serve as an additional way to test your code.
24
25
26=== Examples
27==== data-generators
28<enscript highlight=scheme>
29(use test test-generative)
30
31(test-generative ((the-number (lambda () (random 100))))
32   (test-assert "it's numeric"  (number? the-number))
33   (test-assert "it's positive" (positive? the-number))
34   (test-assert "it's smaller that 50" (< the-number 50)))
35</enscript>
36
37Which outputs something like:
38
39<enscript highlight=raw>
40it's numeric ......................................................... [ PASS]
41it's positive ........................................................ [ PASS]
42it's smaller that 50 ................................................. [ FAIL]
43    assertion failed
44    (< the-number 50)
45    iteration: 4
46    seeds: (68)
47</enscript>
48
49As you can see, the last assertion failed after the 4th iteration with the value 68 which is obviously not smaller than 50.
50
51=== API
52
53<parameter>current-test-generative-iterations</parameter>
54The number of iterations each test shall use. This means that this amout of random inputs will be chosen to exercise your test code.
55This also means that your test code will be run at least that amount of times. That's why you probably want to avoid side-effecting code with these kinds of tests.
56
57<syntax>(test-generative ((binding gen) ...) body ...)</syntax>
58
59This allows you to declare a set of generators specified by '''gen''' and refer to them by names that are specified as '''binding'''s
60in your test code. It will exercise the code at most '''current-test-generative-iterations''' + 1 amount of times with your random data and stop as soon as one of your tests fails.
61If a test has failed it shows the iteration in which it failed and the seed-values that have been used in that iteration.
62
63=== See also
64If you want to use predefined generators for a lot of common types, have a look at [[/egg/data-generators|data-generators]]
65
66
67=== License
68 This program is free software: you can redistribute it and/or modify
69 it under the terms of the GNU General Public License as published by
70 the Free Software Foundation, either version 3 of the License, or (at
71 your option) any later version.
72
73 This program is distributed in the hope that it will be useful, but
74 WITHOUT ANY WARRANTY; without even the implied warranty of
75 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
76 General Public License for more details.
77
78 A full copy of the GPL license can be found at
79 <http://www.gnu.org/licenses/>.
Note: See TracBrowser for help on using the repository browser.