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

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

test-generative: added missing word

File size: 3.2 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]] testing 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<enscript highlight=scheme>
28(use test test-generative)
29
30(test-generative ((the-number (lambda () (random 100))))
31   (test-assert "it's numeric"  (number? the-number))
32   (test-assert "it's positive" (positive? the-number))
33   (test-assert "it's smaller that 50" (< the-number 50)))
34</enscript>
35
36Which outputs something like:
37
38<enscript highlight=raw>
39it's numeric ......................................................... [ PASS]
40it's positive ........................................................ [ PASS]
41it's smaller that 50 ................................................. [ FAIL]
42    assertion failed
43    (< the-number 50)
44    iteration: 4
45    seeds: ((the-number 68))
46</enscript>
47
48As you can see, the last assertion failed after the 4th iteration with the value 68 which is obviously not smaller than 50.
49
50=== API
51
52<parameter>current-test-generative-iterations</parameter>
53The number of iterations each test shall use. This means that this amout of random inputs will be chosen to exercise your test code.
54This 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. The current default is '''100''.
55
56<syntax>(test-generative ((binding gen) ...) body ...)</syntax>
57
58This allows you to declare a set of generators specified by '''gen''' and refer to them by names that are specified as '''binding'''s
59in 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.
60If a test has failed it shows the iteration in which it failed and the seed-values that have been used in that iteration.
61
62'''What is a generator?:'''
63A generator is just a thunk that is expected to return the data upon invokation.
64
65
66=== See also
67If you want to use predefined generators for a lot of common types, have a look at [[/egg/data-generators|data-generators]]
68
69
70=== License
71 This program is free software: you can redistribute it and/or modify
72 it under the terms of the GNU General Public License as published by
73 the Free Software Foundation, either version 3 of the License, or (at
74 your option) any later version.
75
76 This program is distributed in the hope that it will be useful, but
77 WITHOUT ANY WARRANTY; without even the implied warranty of
78 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
79 General Public License for more details.
80
81 A full copy of the GPL license can be found at
82 <http://www.gnu.org/licenses/>.
Note: See TracBrowser for help on using the repository browser.