Implement function composition.
[hope.git] / test / hope_fun_SUITE.erl
1 -module(hope_fun_SUITE).
2
3 %% Callbacks
4 -export(
5 [ all/0
6 , groups/0
7 ]).
8
9 %% Test cases
10 -export(
11 [ t_specs/1
12 , t_id/1
13 , t_curry/1
14 , t_compose/1
15 ]).
16
17
18 -define(GROUP, hope_fun).
19
20
21 %% ============================================================================
22 %% Common Test callbacks
23 %% ============================================================================
24
25 all() ->
26 [ {group, ?GROUP}
27 ].
28
29 groups() ->
30 Tests =
31 [ t_specs
32 , t_id
33 , t_curry
34 , t_compose
35 ],
36 Properties = [parallel],
37 [ {?GROUP, Properties, Tests}
38 ].
39
40
41 %% =============================================================================
42 %% Test cases
43 %% =============================================================================
44
45 t_specs(_) ->
46 [] = proper:check_specs(hope_fun).
47
48 t_id(_Cfg) ->
49 X = foo,
50 X = hope_fun:id(X).
51
52 t_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).
68
69 t_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.046942 seconds and 4 git commands to generate.