Skip to content

Commit

Permalink
Bumping rev to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ngerakines committed May 12, 2009
1 parent adf7d66 commit 78a05ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
LIBDIR=`erl -eval 'io:format("~s~n", [code:lib_dir()])' -s init stop -noshell`
VERSION=0.1
VERSION=0.2

all:
mkdir -p ebin/
Expand Down
85 changes: 46 additions & 39 deletions t/protobuffs_eqc.erl
@@ -1,7 +1,7 @@
%%% File : protobuffs_eqc.erl
%%% Author : <thomas@QUVIQ-THOMAS>
%%% Description : QuickCheck specification used in class for
%%% protobuffs-0.1
%%% protobuffs-0.2
%%% Created : 27 Apr 2009 by <thomas@QUVIQ-THOMAS>
-module(protobuffs_eqc).

Expand All @@ -10,34 +10,36 @@
-compile(export_all).

-define(Mach_Eps, 1.1920928955078125e-7).
-define(NotYetImplemented(Cond,Prop),?IMPLIES(not (Cond),Prop)).
-define(NotYetImplemented(Cond,Prop), ?IMPLIES(not (Cond),Prop)).

%% eqc_gen:sample(protobuffs_eqc:field_num()).
%% eqc:quickcheck(protobuffs_eqc:prop_encode_decode2()).

%%%%%%%%%%%%%%% Properties %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

prop_encode_decode2() ->
?FORALL({FieldNum,Data,Type},fault_rate(5,10,protobuff_data()),
case catch protobuffs:encode(FieldNum,Data,Type) of
{'EXIT', _} ->
not in_range(Data,Type);
Bin ->
{{N, RData}, <<>>} = protobuffs:decode(list_to_binary(Bin), Type),
in_range(Data,Type) andalso
FieldNum=:=N andalso
(compare(Data,RData) orelse foreign_type(Type,Data,RData))
end).
?FORALL({FieldNum,Data,Type}, fault_rate(5,10,protobuff_data()),
case catch protobuffs:encode(FieldNum,Data,Type) of
{'EXIT', _} ->
not in_range(Data,Type);
Bin ->
{{N, RData}, <<>>} = protobuffs:decode(list_to_binary(Bin), Type),
in_range(Data,Type) andalso
FieldNum =:= N andalso
(compare(Data,RData) orelse foreign_type(Type,Data,RData))
end
).

prop_encode_decode() ->
?FORALL({FieldNum,Data,Type},protobuff_data(),
collect(Type,
begin
{{N, RData}, <<>>} = protobuffs:decode(list_to_binary(protobuffs:encode(FieldNum, Data, Type)), Type),
FieldNum=:=N andalso
(compare(Data,RData) orelse foreign_type(Type,Data,RData))
end
)).
?FORALL({FieldNum,Data,Type}, protobuff_data(),
collect(Type,
begin
{{N, RData}, <<>>} = protobuffs:decode(list_to_binary(protobuffs:encode(FieldNum, Data, Type)), Type),
FieldNum =:= N andalso
(compare(Data, RData) orelse foreign_type(Type, Data, RData))
end
)
).

foreign_type(bool,false,0) ->
true;
Expand All @@ -48,13 +50,14 @@ foreign_type(_,_,_) ->

prop_varint() ->
?FORALL(Base,oneof([32,64]),
?FORALL(I,int(Base),
?NotYetImplemented(I<0,
?FORALL(I,int(Base),
begin
{Bits,Data} = decompose(protobuffs:encode_varint(I)),
right_bits(Bits) andalso
concatenate(Data) == I
end))).
{Bits,Data} = decompose(protobuffs:encode_varint(I)),
right_bits(Bits) andalso
concatenate(Data) == I
end
)
).

%% Bits are in reverse order: First bit should be zero, rest should be 1
right_bits([0|Rest]) ->
Expand All @@ -64,24 +67,28 @@ right_bits([0|Rest]) ->

protobuff_data() ->
fault({field_num(), int(80), oneof([int32,uint32,int64,uint64,sint32,sint64])},
oneof([{field_num(), int(32),int32},
{field_num(), uint(32),uint32},
{field_num(), int(64),int64},
{field_num(), uint(64),uint64},
{field_num(), bool(),bool},
{field_num(), sint(32),sint32},
{field_num(), sint(64),sint64},
{field_num(), real(),float},
{field_num(), real(),double}])).
oneof([
{field_num(), int(32),int32},
{field_num(), uint(32),uint32},
{field_num(), int(64),int64},
{field_num(), uint(64),uint64},
{field_num(), bool(),bool},
{field_num(), sint(32),sint32},
{field_num(), sint(64),sint64},
{field_num(), real(),float},
{field_num(), real(),double}
])
).

field_num() ->
?SUCHTHAT(N,nat(),N>0).

int(Base) ->
?LET(I,uint(Base),
begin
<< N:Base/signed >> = <<I:Base>>, N
end).
begin
<< N:Base/signed >> = <<I:Base>>, N
end
).

uint(Base) ->
oneof([ choose(0,exp(B)) || B<-lists:seq(1,Base)]).
Expand Down Expand Up @@ -132,7 +139,7 @@ compare(Float1, Float2) when is_float(Float1), is_float(Float2) ->
(abs(Float1 - Float2) =< ?Mach_Eps);
compare(A,A) -> true;
compare(_,_) -> false.

fitbits(Float,32) when is_float(Float) -> true;
fitbits(Float,64) when is_float(Float) -> true;
fitbits(Int,Bits) ->
Expand Down

0 comments on commit 78a05ca

Please sign in to comment.