Permalink
Browse files

QuickCheck tests.

  • Loading branch information...
jlouis committed Feb 18, 2011
1 parent 37cc383 commit 7033e5daf6f1154da10282cee84d766b703c5fc3
Showing with 29 additions and 10 deletions.
  1. +29 −10 src/bench_map.erl
View
@@ -1,6 +1,6 @@
-module(bench_map).
--export([run/0, run_prof/0, runs/1]).
+-export([run/0, run_prof/0, runs/1, list_shuffle/1]).
-ifdef(TEST).
-include_lib("eqc/include/eqc.hrl").
@@ -36,7 +36,11 @@ runs(F) ->
words() ->
Words = "/usr/share/dict/words",
{ok, Content} = file:read_file(Words),
- [binary_to_list(W) || W <- binary:split(Content, <<"\n">>, [global])].
+ Wrds = [binary_to_list(W) || W <- binary:split(Content, <<"\n">>, [global])],
+ {_, Taken1} = lists:split(250, Wrds),
+ {Taken, _} = lists:split(250, Taken1),
+ Taken.
+
list_shuffle(L) ->
random:seed(), %% Reset Random function
@@ -72,13 +76,6 @@ test_gb_sets_words(Words, Set) ->
end,
Words).
-test_hamt_words(Words, Tree) ->
- lists:foreach(
- fun(Word) ->
- true = hamt:is_element(Word, Tree)
- end, Words),
- false = hamt:is_element(notthere, Tree).
-
test_patricia_words(Words, Tree) ->
lists:foreach(
fun(Word) ->
@@ -158,14 +155,36 @@ patricia_test() ->
end,
fun test_patricia_words/2).
+test_hamt_words(Words, Tree) ->
+ lists:foreach(
+ fun(Word) ->
+ true = hamt:is_element(Word, Tree)
+ end, Words).
+
hamt_test() ->
test_map(fun hamt:from_list/1,
fun test_hamt_words/2).
-ifdef(EUNIT).
-ifdef(EQC).
-
+prop_ins_fetch() ->
+ ?FORALL(L, non_empty(list(int())),
+ begin
+ H = hamt:from_list(L),
+ true = lists:all(
+ fun(X) -> X =:= true end,
+ [hamt:is_element(E, H) || E <- L]),
+ true = lists:all(
+ fun(X) -> X =:= true end,
+ [hamt:is_element(E, H) || E <- lists:reverse(L)]),
+ true = lists:all(
+ fun(X) -> X =:= true end,
+ [hamt:is_element(E, H) || E <- list_shuffle(L)])
+ end).
+
+hamt_ins_fetch_test() ->
+ ?assert(eqc:quickcheck(eqc:numtests(10000, prop_ins_fetch()))).
-endif.
-endif.

0 comments on commit 7033e5d

Please sign in to comment.