diff options
author | Hans Nilsson <hans@erlang.org> | 2019-12-16 16:41:28 +0100 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2020-01-07 13:03:56 +0100 |
commit | eb52758f7fc76dd967f261d66c55c81c10a612de (patch) | |
tree | 0b93482a3bba0847e212e29912c3378254db0115 /lib/common_test/test | |
parent | fe7c44eb8a92bb30ba7ca5b1e23bfaaf4acff221 (diff) | |
download | erlang-eb52758f7fc76dd967f261d66c55c81c10a612de.tar.gz |
common_test: ct_property_test test case
Diffstat (limited to 'lib/common_test/test')
-rw-r--r-- | lib/common_test/test/Makefile | 3 | ||||
-rw-r--r-- | lib/common_test/test/ct_property_test_SUITE.erl | 24 | ||||
-rw-r--r-- | lib/common_test/test/property_test/ct_prop.erl | 28 |
3 files changed, 54 insertions, 1 deletions
diff --git a/lib/common_test/test/Makefile b/lib/common_test/test/Makefile index e510b74d6a..fae7ce0eb5 100644 --- a/lib/common_test/test/Makefile +++ b/lib/common_test/test/Makefile @@ -76,7 +76,8 @@ MODULES= \ ct_unicode_SUITE \ ct_auto_clean_SUITE \ ct_util_SUITE \ - ct_tc_repeat_SUITE + ct_tc_repeat_SUITE \ + ct_property_test_SUITE ERL_FILES= $(MODULES:%=%.erl) HRL_FILES= test_server_test_lib.hrl diff --git a/lib/common_test/test/ct_property_test_SUITE.erl b/lib/common_test/test/ct_property_test_SUITE.erl new file mode 100644 index 0000000000..1f8c9e08cf --- /dev/null +++ b/lib/common_test/test/ct_property_test_SUITE.erl @@ -0,0 +1,24 @@ +-module(ct_property_test_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +all() -> [prop_sort + ]. + +%%% First prepare Config and compile the property tests for the found tool: +init_per_suite(Config) -> + ct_property_test:init_per_suite(Config). + +end_per_suite(Config) -> + Config. + +%%%================================================================ +%%% Test suites +%%% +prop_sort(Config) -> + ct_property_test:quickcheck( + ct_prop:prop_sort(), + Config + ). diff --git a/lib/common_test/test/property_test/ct_prop.erl b/lib/common_test/test/property_test/ct_prop.erl new file mode 100644 index 0000000000..559c33da74 --- /dev/null +++ b/lib/common_test/test/property_test/ct_prop.erl @@ -0,0 +1,28 @@ +-module(ct_prop). +-export([prop_sort/0]). + +-include_lib("common_test/include/ct_property_test.hrl"). + +prop_sort() -> + ?FORALL(UnSorted, list(), + is_sorted(lists:sort(UnSorted)) + ). + + +is_sorted([]) -> + true; +is_sorted([_]) -> + true; +is_sorted(Sorted) -> + try + lists:foldl(fun chk_sorted_pair/2, hd(Sorted), tl(Sorted)) + of + _ -> + true + catch + throw:false -> + false + end. + +chk_sorted_pair(A, B) when A>=B -> A; +chk_sorted_pair(_, _) -> throw(false). |