diff options
author | Kostis Sagonas <[email protected]> | 2014-03-03 01:40:39 +0100 |
---|---|---|
committer | Kostis Sagonas <[email protected]> | 2015-12-16 22:08:32 +0100 |
commit | 9fd2f21c38944c8a605020d6662bb5935c5bbee2 (patch) | |
tree | 8f2dd4a13315d93e54eae79b2e1645fc439c1d58 /lib/hipe/test/basic_SUITE_data/basic_lists.erl | |
parent | 82a835d94be7ee5e98d101a29999fedaf6cd75fe (diff) | |
download | otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.tar.gz otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.tar.bz2 otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.zip |
First part of the basic test suite for the HiPE compiler
Diffstat (limited to 'lib/hipe/test/basic_SUITE_data/basic_lists.erl')
-rw-r--r-- | lib/hipe/test/basic_SUITE_data/basic_lists.erl | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_lists.erl b/lib/hipe/test/basic_SUITE_data/basic_lists.erl new file mode 100644 index 0000000000..d229467b84 --- /dev/null +++ b/lib/hipe/test/basic_SUITE_data/basic_lists.erl @@ -0,0 +1,41 @@ +%%% -*- erlang-indent-level: 2 -*- +%%%------------------------------------------------------------------- +%%% Author: Kostis Sagonas +%%% +%%% Contains tests that manipulate and pattern match against lists. +%%%------------------------------------------------------------------- +-module(basic_lists). + +-export([test/0]). + +test() -> + ok = test_length(), + ok = test_lists_and_strings(), + ok. + +%%-------------------------------------------------------------------- + +test_length() -> + Len = 42, + Lst = mklist(Len, []), + Len = iterate(100, Lst), + ok. + +mklist(0, L) -> L; +mklist(X, L) -> mklist(X-1, [X|L]). + +iterate(0, L) -> len(L, 0); +iterate(X, L) -> len(L, 0), iterate(X-1, L). + +len([_|X], L) -> len(X, L+1); +len([], L) -> L. + +%%-------------------------------------------------------------------- + +test_lists_and_strings() -> + LL = ["H'A", " H'B", " H'C"], + LL2 = lists:map(fun string:strip/1, LL), + HexFormat = fun(X, Acc) -> {string:substr(X, 3), Acc} end, + {LL3,_Ret} = lists:mapfoldl(HexFormat, 0, LL2), + ["A", "B", "C"] = lists:sublist(LL3, 42), + ok. |