aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data/basic_lists.erl
blob: d229467b84099aad7d7662b3f107b38945efb539 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.