Added password protection.
3 -include_lib("eunit/include/eunit.hrl"). 7 {withdraw, From, Amount} when Balance < Amount -> 8 From ! {error, underflow}, 10 {withdraw, From, Amount} -> 11 account(From ! Balance - Amount);
12 {deposit, From, Amount} -> 13 account(From ! Balance + Amount);
15 From ! {error, unknown_request}, 19 make_account(Balance, Password) ->
20 Pid = spawn(?MODULE, account, [Balance]),
21 fun(Action, P) when Password =:= P ->
23 Pid ! {Action, self(), Amount}, 33 throw(incorrect_password)
38 A = make_account(100, secret_password),
39 [?_assertMatch(60, (A(withdraw, secret_password))(40)),
40 ?_assertMatch(80, (A(deposit, secret_password))(20)),
41 ?_assertMatch(underflow, catch((A(withdraw, secret_password))(100))),
42 ?_assertMatch(unknown_request, catch((A(robe, secret_password))(20))),
43 ?_assertMatch(incorrect_password, catch((A(withdraw, wrong_password))(20)))].