List Generators
From Erlang Community
(Difference between revisions)
| Revision as of 12:56, 9 September 2008 (edit) Adam (Talk | contribs) ← Previous diff |
Revision as of 13:16, 9 September 2008 (edit) (undo) Adam (Talk | contribs) Next diff → |
||
| Line 22: | Line 22: | ||
| <code> | <code> | ||
| + | -import(lists, [seq/2]). | ||
| + | |||
| %%% Alphanumeric characters ([a-zA-Z0-9]). | %%% Alphanumeric characters ([a-zA-Z0-9]). | ||
| alnum() -> oneof(seq($a, $z) ++ seq($A, $Z) ++ seq($0, $9)). | alnum() -> oneof(seq($a, $z) ++ seq($A, $Z) ++ seq($0, $9)). | ||
Revision as of 13:16, 9 September 2008
Authors
(This is a living page, please add your own list based generators here!)
Non-empty list
If you want to generate lists which can never be empty, it's fairly simple to wrap the standard list() generator in QuickCheck:
nelist(G) ->
?LET({E, L}, {G, list(G)},
[E|L]).
|
Regexp POSIX Character Classes
Generators for all the POSIX character classes in regexp. Note: some of them do not generate printable strings in Erlang.
-import(lists, [seq/2]).
%%% Alphanumeric characters ([a-zA-Z0-9]).
alnum() -> oneof(seq($a, $z) ++ seq($A, $Z) ++ seq($0, $9)).
%%% Alphabetic characters ([a-zA-Z]).
alpha() -> oneof(seq($a, $z) ++ seq($A, $Z)).
%%% ASCII characters ([\x00-\x7F]).
ascii() -> oneof(seq(0, 127)).
%%% Space and tab ([ \t]).
blank() -> oneof([$ , $\t]).
%%% Control characters ([\x00-\x1F\x7F]).
cntrl() -> oneof(seq(0, 31) ++ [127]).
%%% Digits ([0-9]).
digit() -> oneof(seq($0, $9)).
%%% Visible characters (i.e. anything except spaces, control
%%% characters, etc.) ([\x21-\x7E]).
graph() -> oneof(seq(33, 126)).
%%% Lowercase letters ([a-z]).
lower() -> oneof(seq($a, $z)).
%%% Visible characters and spaces (i.e. anything except control
%%% characters, etc.) ([\x20-\x7E]).
print() -> oneof(seq(32, 126)).
%%% Punctuation and symbols ([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]).
punct() -> oneof("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}\~").
%%% All whitespace characters, including line breaks ([ \t\r\n\v\f]).
space() -> oneof([$ , $\t, $\r, $\n, $\v, $\f]).
%%% Uppercase letters ([A-Z]).
upper() -> oneof(seq($A, $Z)).
%%% Word characters (letters, numbers and underscores) ([A-Za-z0-9_]).
word() -> oneof(seq($a, $z) ++ seq($A, $Z) ++ seq($0, $9) ++ "_").
%%% Hexadecimal digits ([A-Fa-f0-9]).
xdigit() -> oneof(seq($A, $F) ++ seq($a, $f) ++ seq($0, $9)).
|

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

