Permalink
Browse files

Fix various problems based on PropEr testing.

  • Loading branch information...
1 parent a818eae commit d84f4185b2825022eb39855f42fad5061900e8fa @okeuday committed Nov 12, 2011
Showing with 43 additions and 24 deletions.
  1. +1 −1 Makefile
  2. +7 −0 README.markdown
  3. +25 −2 src/pqueue.erl
  4. +9 −21 src/pqueue2.erl
  5. +1 −0 src/pqueue_proper.erl
View
@@ -1,5 +1,5 @@
all:
- rebar compile
+ PATH=.:${PATH} rebar compile
console:
erl -pa ebin
View
@@ -10,7 +10,14 @@ Author
Michael Truog (mjtruog [at] gmail (dot) com)
+Thanks
+------
+
+Jesper Louis andersen PropEr integration and testing
+Ulf Wiger Suggestions and Insight
+
License
-------
BSD
+
View
@@ -134,8 +134,31 @@ in(X, P, Q) ->
is_empty({empty, _, _, _, _, _, _, _}) ->
true;
-is_empty(_) ->
- false.
+is_empty({_,
+ {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14},
+ {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7},
+ {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1},
+ Q0,
+ {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6},
+ {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13},
+ {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) ->
+ queue:is_empty(Qn20) and queue:is_empty(Qn19) and queue:is_empty(Qn18) and
+ queue:is_empty(Qn17) and queue:is_empty(Qn16) and queue:is_empty(Qn15) and
+ queue:is_empty(Qn14) and
+ queue:is_empty(Qn13) and queue:is_empty(Qn12) and queue:is_empty(Qn11) and
+ queue:is_empty(Qn10) and queue:is_empty(Qn9) and queue:is_empty(Qn8) and
+ queue:is_empty(Qn7) and
+ queue:is_empty(Qn6) and queue:is_empty(Qn5) and queue:is_empty(Qn4) and
+ queue:is_empty(Qn3) and queue:is_empty(Qn2) and queue:is_empty(Qn1) and
+ queue:is_empty(Q0) and
+ queue:is_empty(Qp1) and queue:is_empty(Qp2) and queue:is_empty(Qp3) and
+ queue:is_empty(Qp4) and queue:is_empty(Qp5) and queue:is_empty(Qp6) and
+ queue:is_empty(Qp7) and queue:is_empty(Qp8) and queue:is_empty(Qp9) and
+ queue:is_empty(Qp10) and queue:is_empty(Qp11) and queue:is_empty(Qp12) and
+ queue:is_empty(Qp13) and
+ queue:is_empty(Qp14) and queue:is_empty(Qp15) and queue:is_empty(Qp16) and
+ queue:is_empty(Qp17) and queue:is_empty(Qp18) and queue:is_empty(Qp19) and
+ queue:is_empty(Qp20).
%%-------------------------------------------------------------------------
%% @doc
View
@@ -110,6 +110,8 @@ in(Value, P, H) ->
is_empty(empty) ->
true;
+is_empty({_, empty, empty, queue, Queue}) ->
+ queue:is_empty(Queue);
is_empty(_) ->
false.
@@ -441,25 +443,13 @@ test() ->
C1V2 = pqueue2:in(-10, -4, C1V1),
C1V3 = pqueue2:in(-29, C1V2),
C1V4 = pqueue2:in(11, C1V3),
- % new result, always merging larger priorities to the right
- %(i.e., merge differing priorities
- % {P1, HL1, merge(HR1, H2), T, D};
- % {P2, HL2, merge(HR2, H1), T, D};
- %)
- {-4,empty,
- {0,empty,empty,queue,{[11,-29,9],[-18]}},
- element,-10} = C1V4,
- % previous result, balancing larger priorities on extremities
- %(i.e., merge differing priorities
- % {P1, HL1, merge(HR1, H2), T, D};
- % {P2, merge(H1, HL2), HR2, T, D};
- %)
- %{-4,
- % {0,empty,empty,queue,{[11],[-29]}},
- % {0,empty,empty,queue,{[9],[-18]}},
- % element, -10} = C1V4,
5 = pqueue2:len(C1V4),
[-10, -18, 9, -29, 11] = pqueue2:to_list(C1V4),
+ % test case 2, based on proper testing
+ C2V0 = pqueue2:in(-4, -15, pqueue2:new()),
+ C2V1 = pqueue2:in(13, C2V0),
+ C2V2 = pqueue2:in(2, C2V1),
+ [-4, 13, 2] = to_list(C2V2),
ok.
%%%------------------------------------------------------------------------
@@ -475,14 +465,12 @@ merge({_, _, _, _, _} = H, empty) ->
merge({P1, HL1, HR1, T, D}, {P2, _, _, _, _} = H2) when P1 < P2 ->
{P1, HL1, merge(HR1, H2), T, D};
merge({P1, _, _, _, _} = H1, {P2, HL2, HR2, T, D}) when P1 > P2 ->
- {P2, HL2, merge(HR2, H1), T, D};
+ {P2, HL2, merge(H1, HR2), T, D};
merge({P, HL1, HR1, element, Value1}, {P, HL2, HR2, element, Value2}) ->
{P, merge(HL1, HR1), merge(HL2, HR2), queue,
queue:from_list([Value2, Value1])};
merge({P, HL1, HR1, queue, Queue}, {P, HL2, HR2, element, Value}) ->
{P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:in(Value, Queue)};
merge({P, HL1, HR1, element, Value}, {P, HL2, HR2, queue, Queue}) ->
- {P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:in(Value, Queue)}.%;
-%merge({P, HL1, HR1, queue, Queue1}, {P, HL2, HR2, queue, Queue2}) ->
-% {P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:join(Queue2, Queue1)}.
+ {P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:in(Value, Queue)}.
View
@@ -89,6 +89,7 @@ qc_pq() ->
proper:quickcheck(pqueue_proper:correct(pqueue)).
qc_pq2() ->
+ %proper:quickcheck(pqueue_proper:correct(pqueue2), [{numtests, 10000}]).
proper:quickcheck(pqueue_proper:correct(pqueue2)).
%% ----------------------------------------------------------------------

0 comments on commit d84f418

Please sign in to comment.