Skip to content

Commit cde06a0

Browse files
author
Nicolás Andrés Gallinal
committed
Add samples and bump version to 0.3.0 with compositional shrinker
1 parent 1ba052e commit cde06a0

File tree

7 files changed

+88
-49
lines changed

7 files changed

+88
-49
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.3.0 (2019-06-04)
2+
3+
* Implement compositiona shrinker
4+
* Add more examples on how to use it
5+
16
# v0.2.3 (2019-05-09)
27

38
* Fix issue #4

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ Describe properties of your predicates and let `library(quickheck)` generate tes
1616
reverse(L, R),
1717
reverse(R, L).
1818

19+
prop_silly_list(L:list(integer)) :-
20+
length(L, Len),
21+
Len =:= 3. % nonsense!
22+
1923
?- quickcheck(prop_reverse_twice/1).
2024
100 tests OK
2125
true.
2226

27+
?- quickcheck(prop_silly_list/1).
28+
Shrinking to depth 1
29+
Failed test prop_silly_list([]:list(integer))
30+
false.
31+
32+
2333
## Installation
2434

2535
To install as a package:

examples/composite.pl

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
:- use_module(library(quickcheck)).
2+
% this is the way of creating new arbitraries
3+
% defining a composite that will receive a list of primary arbitraries.
4+
:- multifile quickcheck:composite/3.
5+
quickcheck:composite(tuple(integer, string), [I:integer, S:string], X) :-
6+
X = (I,S).
7+
8+
% composites can also be defined using a single arbitrary
9+
% without need to passing a list
10+
quickcheck:composite(even, I:integer, X) :-
11+
X is 2 * I.
12+
13+
quickcheck:composite(odd, I:integer, X) :-
14+
X is 2 * I + 1.
15+
16+
% once we define a composite, we may need to define
17+
% a has_type/2 in case we are going to make use of
18+
% the predicate is_of_type(+Composite, @Term).
19+
% in the case where the composite body is 'invertible'
20+
% (ie: tuple(integer, string)) there is no need to
21+
% because quickcheck will run it 'backwards'
22+
% but in cases such as odd where the body is not 'invertible'
23+
% (meaning I cannot be a variable, so it can be run 'backwards')
24+
% a custom definition must be given.
25+
:- multifile quickcheck:has_type/2.
26+
quickcheck:has_type(odd, X) :-
27+
integer(X),
28+
1 is X mod 2.
29+
30+
prop_tuple(T:tuple(integer, string)) :-
31+
T = (_, S),
32+
string_length(S, L),
33+
L < 4.
34+
35+
prop_odd_plus_even(O:odd, E:even) :-
36+
Sum is O + E,
37+
is_of_type(odd, Sum),
38+
Sum < 4.
39+
40+
:- begin_tests(composite).
41+
42+
test('nonsense, tuples cannot have large string', [forall(between(1, 10, _))]) :-
43+
catch(quickcheck(prop_tuple/1), error(counter_example, [(_, String):tuple(integer, string)]), true),
44+
string_length(String, Len),
45+
Len >= 4.
46+
47+
test('even numbers plus odd numbers gives odd', [forall(between(1, 10, _))]) :-
48+
catch(quickcheck(prop_odd_plus_even/2), error(counter_example, [O:odd, E:even]), true),
49+
S is O + E,
50+
S >= 4.
51+
52+
:- end_tests(composite).

examples/plunit.pl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:- use_module(library(quickcheck)).
2+
3+
prop_reverse_twice(L:list) :-
4+
reverse(L, R),
5+
reverse(R, L).
6+
7+
prop_silly_list(L:list(integer)) :-
8+
length(L, Len),
9+
Len =:= 3. % nonsense!
10+
11+
:- begin_tests(list).
12+
13+
test('reverse twice') :-
14+
quickcheck(prop_reverse_twice/1).
15+
16+
test('silly list', [fail]) :-
17+
quickcheck(prop_silly_list/1).
18+
19+
:- end_tests(list).
File renamed without changes.

examples/tutorial.pl

-47
This file was deleted.

pack.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name(quickcheck).
22
title('QuickCheck randomized testing').
33

4-
version('0.2.3').
5-
download('https://github.com/nicoabie/quickcheck/archive/v0.2.3.zip').
4+
version('0.3.0').
5+
download('https://github.com/nicoabie/quickcheck/archive/v0.3.0.zip').
66

77
author('Michael Hendricks','[email protected]').
88
packager('Nico Gallinal','[email protected]').

0 commit comments

Comments
 (0)