• Stars
    star
    284
  • Rank 140,852 (Top 3 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created about 14 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Trifork QuickCheck

Welcome to Triq -- Trifork QuickCheck for Erlang

Build Status

Triq (pronounced "Trick Check") is a free alternative to QuviQ eqc. Triq's API is modelled closely after eqc, so I recommend their tutorials and slides for an introduction to QuickCheck. Notice that QuviQ eqc has many features not found in triq, but it is open source licensed under the Apache license. For instance, eqc has features for reporting, management, probably a much better shrinking mechanism, cool C integration, and professional support.

Installation

To use triq, you download the latest version from here, and untar it into your erlang lib directory (typically /usr/local/lib/erlang/lib):

prompt$ cd /usr/local/lib/erlang/lib
propmt$ tar xvzf triq-0.1.0.tgz
...

And you're all set.

Or, checkout the triq source code and soft link / copy into your Erlang lib directory:

prompt$ git clone git://github.com/krestenkrab/triq.git
prompt$ cd triq
prompt$ ln -s . /usr/local/lib/erlang/lib/triq-0.1.0

Next, to use triq, include the header file:

-include_lib("triq/include/triq.hrl").

And you're ready to write property tests. An example property could be:

prop_append() ->
    ?FORALL({Xs,Ys},{list(int()),list(int())},
            lists:reverse(Xs++Ys)
            ==
            lists:reverse(Ys) ++ lists:reverse(Xs)).

To test this property, run triq:check/1, thus:

1> triq:check(prop_append()).
......................................................................
..............................
Ran 100 tests
true
2>

If the test fails, it will try to shrink the result; here is an example:

prop_delete() ->
    ?FORALL(L,list(int()),
        ?IMPLIES(L /= [],
            ?FORALL(I,elements(L),
                ?WHENFAIL(io:format("L=~p, I=~p~n", [L,I]),
                          not lists:member(I,lists:delete(I,L)))))).

Which runs like this:

1> triq:check(triq_tests:prop_delete()).
x....Failed!
L=[4,5,5], I=5

Failed after 5 tests with false
Simplified:
        L = [0,0]
        I = 0
false
2>

You can get the values used for the failing test with counterexample, and reuse the same test values with check/2:

3> A = triq:counterexample(triq_tests:xprop_delete()).
x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFailed!
L=[3,2,1,1,1], I=1

Failed after 101 tests with false
Simplified:
	L = [0,0]
	I = 0
[[0,0],0]
4> A.
[[0,0],0]
5> triq:check(triq_tests:xprop_delete(), A).
Failed!
L=[0,0], I=0

Failed after 1 tests with false
Simplified:
	L = [0,0]
	I = 0
false
6>

Modules compiled with the triq.hrl header, auto-export all functions named prop_*, and have a function added called check/0 which runs triq:check/1 on all the properties in the module.

1> mymodule:check().

A handy addition that I use is to also add an eunit test, which tests it:

property_test() -> true == check().

Which can then automatically be run using your favourite eunit runner.

Good luck!

More Repositories

1

hanoidb

Erlang LSM BTree Storage
Erlang
298
star
2

erlubi

Ubigraph Erlang Client (and Process Visualizer)
Erlang
189
star
3

emmap

Erlang Memory Map
C++
77
star
4

bitcask-java

Implementation of Basho's bitcask in Java
Java
70
star
5

riak_link_index

Simple Indexer for Riak based on Links
Erlang
27
star
6

riak-java-pb-client

No longer in use; all functionality is now merged into Basho's riak-java-client
Java
26
star
7

kilim-erjang

CLONE OF: Kilim - a message-passing framework for Java that provides ultra-lightweight threads
Java
15
star
8

jvm-verifier

A Verifier for JVM byte code that you can run off-line with detailed error reporting. Great for compiler writers. Useless for everyone else.
Java
15
star
9

riak_btree_backend

Backend for Riak/KV based on couch_btree
Erlang
12
star
10

vbisect

variable-sized binary ordered dictionary
Erlang
11
star
11

bets

Erlang Berkeley DB Interface
C
11
star
12

hotruby

A JVM-based Ruby VM
Ruby
10
star
13

eplc

Erlang Process-Local Cache
Erlang
7
star
14

mdb

OpenLDAP MDB: Memory-Mapped Database
C
7
star
15

riak_webhook

Simple postcommit web hook for Riak
Erlang
5
star
16

erlang_cbor

Erlang implementation of Concise Binary Object Representation (CBOR), RFC 7049
Erlang
4
star
17

erjang

Erjang, moved to Trifork (organization) account
4
star
18

deltazip

Zip adaptation for archiving
3
star
19

dart

Java
3
star
20

basket

HTML5 Local Storage Abstraction [ IndexedDB, WebSQL, localStorage, IE UserData ]
3
star
21

fractal_btree

Project Renamed
2
star
22

eio

Erlang Flavored I/O for C++
Shell
2
star
23

mdns-responder

C
2
star
24

Pencil

C++
2
star
25

riak-java-client-api

An attempt at a new api for the Riak Java Client
Java
2
star
26

leveldb

Mirror of LevelDB
C++
1
star