Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jlouis
Created August 18, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlouis/52b68d9d4150af3bd00c to your computer and use it in GitHub Desktop.
Save jlouis/52b68d9d4150af3bd00c to your computer and use it in GitHub Desktop.
-module(integer_coding).
-compile(export_all).
-include_lib("eqc/include/eqc.hrl").
power(_N, 0) -> 1;
power(N, P) -> N * power(N, P-1).
perturb() ->
elements([0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]).
sign() ->
elements([1, -1]).
nat_power() ->
frequency([{1, elements([27, 28, 29, 31, 32, 33, 59, 60, 61, 63, 64, 65])},
{1, nat()}]).
interesting_int() ->
?LET({K, Sign, Perturb}, {nat_power(), sign(), perturb()},
power(2, K)*Sign + Perturb).
prop_binary_iso() ->
?FORALL(K, interesting_int(),
begin
I = binary_to_integer(integer_to_binary(K)),
I == K
end).
prop_list_iso() ->
?FORALL(K, interesting_int(),
begin
I = list_to_integer(integer_to_list(K)),
I == K
end).
all() ->
eqc:module({numtests, 3000}, ?MODULE).
t() ->
eqc:quickcheck(eqc:testing_time(300, prop_binary_iso())).
[...]
Produces:
8> integer_coding:all().
prop_list_iso: .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Failed! After 1498 tests.
-576460752303423488
prop_binary_iso: ...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Failed! After 588 tests.
-576460752303423488
[prop_list_iso,prop_binary_iso]
9>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment