diff options
author | Björn Gustavsson <[email protected]> | 2016-03-10 09:57:37 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-03-10 09:57:37 +0100 |
commit | e42208ce5d5e76056f9c199d52512275c98b50c1 (patch) | |
tree | 016d43ebe0fa7f0fb7dd2bcab9398dc418a4b665 /lib/stdlib/test/rand_SUITE.erl | |
parent | 104cca3be8852070cb3c6d5b12ea74fe1591ba9b (diff) | |
parent | 25e64aaf1df1ea5c712075a9236367de4cc81359 (diff) | |
download | otp-e42208ce5d5e76056f9c199d52512275c98b50c1.tar.gz otp-e42208ce5d5e76056f9c199d52512275c98b50c1.tar.bz2 otp-e42208ce5d5e76056f9c199d52512275c98b50c1.zip |
Merge branch 'bjorn/stdlib/modernize-tests'
* bjorn/stdlib/modernize-tests:
Eliminate use of ?config() macro
Remove ?line macros
Replace "%" with "%%" at the beginning of a line
Eliminate 'suite' and 'doc' clauses
gen_server_SUITE: Eliminate use of test_server:timecall/3
Use 'test_server' instead of ?t macro
Eliminate use of test_server:messages_get/0
sys_SUITE: Replace test_server:capture*/0 with ct:capture*/0
sys_SUITE: Mend test cases that didn't test what they should
Replace calls to test_server:sleep/1 with ct:sleep/1 or timer:sleep/1
Eliminate use of test_server:do_times()
Replace use of test_server:format/2 with io:format/2
Eliminate use of test_server:fail/0,1
Modernize use of timetraps
Diffstat (limited to 'lib/stdlib/test/rand_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/rand_SUITE.erl | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/lib/stdlib/test/rand_SUITE.erl b/lib/stdlib/test/rand_SUITE.erl index ab260da950..6830101e96 100644 --- a/lib/stdlib/test/rand_SUITE.erl +++ b/lib/stdlib/test/rand_SUITE.erl @@ -35,19 +35,17 @@ -include_lib("common_test/include/ct.hrl"). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(3)). -define(LOOP, 1000000). init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,3}}]. all() -> [seed, interval_int, interval_float, @@ -85,16 +83,13 @@ algs() -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -seed(doc) -> - ["Test that seed and seed_s and export_seed/0 is working."]; -seed(suite) -> - []; +%% Test that seed and seed_s and export_seed/0 is working. seed(Config) when is_list(Config) -> Algs = algs(), Test = fun(Alg) -> try seed_1(Alg) catch _:Reason -> - test_server:fail({Alg, Reason, erlang:get_stacktrace()}) + ct:fail({Alg, Reason, erlang:get_stacktrace()}) end end, [Test(Alg) || Alg <- Algs], @@ -139,10 +134,7 @@ seed_1(Alg) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -api_eq(doc) -> - ["Check that both api's are consistent with each other."]; -api_eq(suite) -> - []; +%% Check that both APIs are consistent with each other. api_eq(_Config) -> Algs = algs(), Small = fun(Alg) -> @@ -188,10 +180,7 @@ api_eq_1(S00) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -interval_int(doc) -> - ["Check that uniform/1 returns values within the proper interval."]; -interval_int(suite) -> - []; +%% Check that uniform/1 returns values within the proper interval. interval_int(Config) when is_list(Config) -> Algs = algs(), Small = fun(Alg) -> @@ -225,10 +214,7 @@ interval_int_1(N, Top, Max) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -interval_float(doc) -> - ["Check that uniform/0 returns values within the proper interval."]; -interval_float(suite) -> - []; +%% Check that uniform/0 returns values within the proper interval. interval_float(Config) when is_list(Config) -> Algs = algs(), Test = fun(Alg) -> @@ -252,8 +238,7 @@ interval_float_1(N) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -reference(doc) -> ["Check if exs64 algorithm generates the proper sequence."]; -reference(suite) -> []; +%% Check if exs64 algorithm generates the proper sequence. reference(Config) when is_list(Config) -> [reference_1(Alg) || Alg <- algs()], ok. @@ -267,7 +252,6 @@ reference_1(Alg) -> io:format("Failed: ~p~n",[Alg]), io:format("Length ~p ~p~n",[length(Refval), length(Testval)]), io:format("Head ~p ~p~n",[hd(Refval), hd(Testval)]), - %% test_server:fail({Alg, Refval -- Testval}), ok end. @@ -330,9 +314,9 @@ basic_uniform_1(0, {#{type:=Alg}, _}, Sum, A) -> %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(0.5 - AverN) < 0.005 orelse test_server:fail({average, Alg, AverN}), - abs(?LOOP div 100 - Min) < 1000 orelse test_server:fail({min, Alg, Min}), - abs(?LOOP div 100 - Max) < 1000 orelse test_server:fail({max, Alg, Max}), + abs(0.5 - AverN) < 0.005 orelse ct:fail({average, Alg, AverN}), + abs(?LOOP div 100 - Min) < 1000 orelse ct:fail({min, Alg, Min}), + abs(?LOOP div 100 - Max) < 1000 orelse ct:fail({max, Alg, Max}), ok. basic_uniform_2(N, S0, Sum, A0) when N > 0 -> @@ -349,9 +333,9 @@ basic_uniform_2(0, {#{type:=Alg}, _}, Sum, A) -> %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(50.5 - AverN) < 0.5 orelse test_server:fail({average, Alg, AverN}), - abs(?LOOP div 100 - Min) < 1000 orelse test_server:fail({min, Alg, Min}), - abs(?LOOP div 100 - Max) < 1000 orelse test_server:fail({max, Alg, Max}), + abs(50.5 - AverN) < 0.5 orelse ct:fail({average, Alg, AverN}), + abs(?LOOP div 100 - Min) < 1000 orelse ct:fail({min, Alg, Min}), + abs(?LOOP div 100 - Max) < 1000 orelse ct:fail({max, Alg, Max}), ok. basic_normal_1(N, S0, Sum, Sq) when N > 0 -> @@ -363,14 +347,13 @@ basic_normal_1(0, {#{type:=Alg}, _}, Sum, SumSq) -> io:format("~.10w: Average: ~7.4f StdDev ~6.4f~n", [Alg, Mean, StdDev]), %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(Mean) < 0.005 orelse test_server:fail({average, Alg, Mean}), - abs(StdDev - 1.0) < 0.005 orelse test_server:fail({stddev, Alg, StdDev}), + abs(Mean) < 0.005 orelse ct:fail({average, Alg, Mean}), + abs(StdDev - 1.0) < 0.005 orelse ct:fail({stddev, Alg, StdDev}), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -plugin(doc) -> ["Test that the user can write algorithms"]; -plugin(suite) -> []; +%% Test that the user can write algorithms. plugin(Config) when is_list(Config) -> _ = lists:foldl(fun(_, S0) -> {V1, S1} = rand:uniform_s(10000, S0), |