Implement function composition.
[hope.git] / test / hope_fun_SUITE.erl
CommitLineData
64617423
SK
1-module(hope_fun_SUITE).
2
3%% Callbacks
4-export(
5 [ all/0
6 , groups/0
7 ]).
8
9%% Test cases
10-export(
0b6ed617
SK
11 [ t_specs/1
12 , t_id/1
e033aade 13 , t_curry/1
0b6ed617 14 , t_compose/1
64617423
SK
15 ]).
16
17
18-define(GROUP, hope_fun).
19
20
21%% ============================================================================
22%% Common Test callbacks
23%% ============================================================================
24
25all() ->
26 [ {group, ?GROUP}
27 ].
28
29groups() ->
30 Tests =
0b6ed617
SK
31 [ t_specs
32 , t_id
e033aade 33 , t_curry
0b6ed617 34 , t_compose
64617423
SK
35 ],
36 Properties = [parallel],
37 [ {?GROUP, Properties, Tests}
38 ].
39
40
41%% =============================================================================
42%% Test cases
43%% =============================================================================
44
0b6ed617
SK
45t_specs(_) ->
46 [] = proper:check_specs(hope_fun).
47
64617423
SK
48t_id(_Cfg) ->
49 X = foo,
50 X = hope_fun:id(X).
e033aade
SK
51
52t_curry(_Cfg) ->
53 Single = fun (X) -> X end,
54 Double = fun (X, Y) -> {X, Y} end,
55 Triple = fun (X, Y, Z) -> {X, Y, Z} end,
56
57 F = hope_fun:curry(Single),
58 a = F(a),
59
60 G1 = hope_fun:curry(Double),
61 G = G1(a),
62 {a, b} = G(b),
63
64 H1 = hope_fun:curry(Triple),
65 H2 = H1(a),
66 H = H2(b),
67 {a, b, c} = H(c).
0b6ed617
SK
68
69t_compose(_Cfg) ->
70 A2B = fun (a) -> b end,
71 B2C = fun (b) -> c end,
72 C2D = fun (c) -> d end,
73 Fs = [C2D, B2C, A2B],
74 d = (hope_fun:compose ( Fs ))(a),
75 d = (hope_fun:compose_right ( Fs ))(a),
76 d = (hope_fun:compose_left (lists:reverse(Fs) ))(a).
This page took 0.028367 seconds and 4 git commands to generate.