From 78a05caedb21c860d49e5dcd73d7ca3ea2e4f913 Mon Sep 17 00:00:00 2001 From: Nick Gerakines Date: Tue, 12 May 2009 12:50:32 -0700 Subject: [PATCH] Bumping rev to 0.2 --- Makefile | 2 +- t/protobuffs_eqc.erl | 85 ++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 50c56f2b..de9ec45e 100644 --- a/Makefile +++ b/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/ diff --git a/t/protobuffs_eqc.erl b/t/protobuffs_eqc.erl index 9a22f310..b2b5d854 100644 --- a/t/protobuffs_eqc.erl +++ b/t/protobuffs_eqc.erl @@ -1,7 +1,7 @@ %%% File : protobuffs_eqc.erl %%% Author : %%% Description : QuickCheck specification used in class for -%%% protobuffs-0.1 +%%% protobuffs-0.2 %%% Created : 27 Apr 2009 by -module(protobuffs_eqc). @@ -10,7 +10,7 @@ -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()). @@ -18,26 +18,28 @@ %%%%%%%%%%%%%%% 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; @@ -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]) -> @@ -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 >> = <>, N - end). + begin + << N:Base/signed >> = <>, N + end + ). uint(Base) -> oneof([ choose(0,exp(B)) || B<-lists:seq(1,Base)]). @@ -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) ->