% $Id$ -module(higherorder_tests). -export([main/0]). -import(higherorder,[foreach/2, foldr/3, map/2, applyList/2, applyList2/2, member/2, foldl/3, reverse/1, minimum/1]). -import(testing,[dotests/2,eqTest/3]). main() -> dotests("higherorder_tests $Revision: 1.2 $",tests()). tests() -> foreach(fun(S) -> io:format("Testing ~p~n",[S]) end, [foreach]), [eqTest(foldr(fun(E,Res) -> [E|Res] end,[],[1,2,3]), "==", [1,2,3]), eqTest(map(fun(E) -> E*E end, [1,2,3,4,5]), "==", [1,4,9,16,25]), eqTest(map(fun(E) -> error("shouldn't see this",[E]) end, []), "==", []), eqTest(applyList([fun(X) -> X end, fun math:cos/1], 3), "==", [3, math:cos(3)]), eqTest(applyList2([fun(X) -> X end, fun math:cos/1], 3), "==", [3, math:cos(3)]), eqTest(member(a, [far, away, in, a, land, long, ago]), "==", true), eqTest(foldl(fun(_E,Acc) -> 1+Acc end, 0, [1,2,3]), "==", 3), eqTest(reverse([a, man, a, plan, a, canal, panama]), "==", [panama, canal, a, plan, a, man, a]), eqTest(minimum([1,3,2,1,0,5,99,0,78]), "==", 0) ].