Changeset 25382 in project


Ignore:
Timestamp:
10/19/11 22:20:28 (9 years ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [129.174.190.17]: Added examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/cluckcheck

    r25381 r25382  
    1919Generate a random integer.
    2020
     21        > (use (prefix cluckcheck cluckcheck:))
     22        > (cluckcheck:gen-int)
     23        180
     24
    2125<procedure>(gen-bool)</procedure>
    2226
    2327Generate a random boolean.
     28
     29        > (use (prefix cluckcheck cluckcheck:))
     30        > (cluckcheck:gen-bool)
     31        #t
    2432
    2533<procedure>(gen-char)</procedure>
     
    2735Generate a random character.
    2836
     37        > (use (prefix cluckcheck cluckcheck:))
     38        > (cluckcheck:gen-char)
     39        #\g
     40
    2941<procedure>(gen-list gen)</procedure>
    3042
    3143Generate a random list populated by gen.
     44
     45        > (use (prefix cluckcheck cluckcheck:))
     46        > (cluckcheck:gen-list cluckcheck:gen-int)
     47        (103 24 45 253 227 28 92 45 235 193 212 27 9 195 224 228 103 255)
    3248
    3349gen-list can be combined with other generators, including custom generators, to create generators for complex data structures. See gen-string.
     
    3753Generate a random string. gen-string is a wrapper around (gen-list gen-char).
    3854
     55        > (use (prefix cluckcheck cluckcheck:))
     56        > (cluckcheck:gen-string)
     57        "\x05&o@\by\x00J &\x00\v\x1691\x05\x19\x14z\r<VxU\x1b\x06~(wE\x05\x03LB&T\x1fLl-\x15\x06"
     58
    3959<procedure>(for-all property gen1 gen2 gen3...)</procedure>
    4060
    4161Tests a property function with values generated by the generator functions. If the property returns false, testing halts and the offending input values are printed to the screen.
     62
     63        > (use (prefix cluckcheck cluckcheck:))
     64        > (define (is-even n)
     65                (= 0 (modulo n 2)))
     66        > (cluckcheck:for-all is-even cluckcheck:gen-int)
     67        *** Failed!
     68        (57)
     69
     70For more examples, see [[https://github.com/mcandre/cluckcheck/blob/master/example.scm|example.scm]].
Note: See TracChangeset for help on using the changeset viewer.