From f4780d184dddbe3233fed77dac7ddeb74c4f5b02 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 19 Aug 2014 11:41:51 +0200 Subject: [PATCH] hope_list:unique_preserve_order/1 property test --- .gitignore | 1 + Makefile | 14 ++++++++++++++ rebar.config | 5 +++++ test/hope_list_SUITE.erl | 21 +++++++++++++-------- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 76b3746..34f27b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ebin/ logs/ test/*.beam +/deps/proper/ diff --git a/Makefile b/Makefile index 34c0fe9..3d80498 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,14 @@ fresh-build \ compile \ clean \ + deps \ + deps-get \ + deps-update \ dialyze \ test ci: \ + deps \ compile \ test @@ -20,6 +24,16 @@ compile: clean: @rebar clean +deps: \ + deps-get \ + deps-update + +deps-get: + @rebar get-deps + +deps-update: + @rebar update-deps + dialyze: @dialyzer ebin diff --git a/rebar.config b/rebar.config index a760517..986fa40 100644 --- a/rebar.config +++ b/rebar.config @@ -1 +1,6 @@ +%%% -*- mode: erlang -*- {clean_files, ["test/*.beam"]}. + +{deps, + [{proper, ".*", {git, "https://github.com/manopapad/proper.git", {tag, "v1.1"}}}] +}. diff --git a/test/hope_list_SUITE.erl b/test/hope_list_SUITE.erl index 751157d..819c4fc 100644 --- a/test/hope_list_SUITE.erl +++ b/test/hope_list_SUITE.erl @@ -1,5 +1,7 @@ -module(hope_list_SUITE). +-include_lib("proper/include/proper.hrl"). + %% Callbacks -export( [ all/0 @@ -14,6 +16,8 @@ -define(GROUP , hope_list). +-define(PROPTEST(A), true = proper:quickcheck(A())). + %% ============================================================================ %% Common Test callbacks @@ -35,11 +39,12 @@ groups() -> %% ============================================================================= t_unique_preserve_order(_Cfg) -> - ListAGiven = [a, a, g, b, f, c, a, d, a, e, f, d], - ListBGiven = "australia", - ListAExpected = [a, g, b, f, c, d, e], - ListBExpected = "austrli", - ListAComputed = hope_list:unique_preserve_order(ListAGiven), - ListBComputed = hope_list:unique_preserve_order(ListBGiven), - ListAComputed = ListAExpected, - ListBComputed = ListBExpected. + ?PROPTEST(prop_unique_preserve_order). + +prop_unique_preserve_order() -> + ?FORALL(L, list(), + begin + Duplicates = L -- lists:usort(L), + hope_list:unique_preserve_order(L) == + lists:reverse(lists:reverse(L) -- Duplicates) + end). -- 2.20.1