Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game_test() ->
- {"Rock and paper play best of 3, first round tie",
- fun() ->
- {ok, BrokerRef } = rps:start(),
- spawn(fun() -> rock_bot(BrokerRef, rock_bot) end),
- spawn(fun() -> paper_bot(BrokerRef, paper_bot) end)
- end}.
- rock_bot(BrokerRef, BotName) ->
- {ok, _, Coordinator} = rps:queue_up(BrokerRef, BotName, 3),
- Res = rps:move(Coordinator, rock), % tie round
- ?assertMatch(tie, Res),
- Res = rps:move(Coordinator, rock),
- ?assertMatch(round_lost, Res),
- Res2 = rps:move(Coordinator, rock),
- ?assertMatch({game_over, 0, 2}, Res2).
- paper_bot(BrokerRef, BotName) ->
- {ok, _, Coordinator} = rps:queue_up(BrokerRef, BotName, 3),
- Res = rps:move(Coordinator, rock), %tie round
- ?assertMatch(tie, Res),
- Res = rps:move(Coordinator, paper),
- ?assertMatch(round_won, Res),
- Res2 = rps:move(Coordinator, paper),
- ?assertMatch({game_over, 2, 0}, Res2),
- Stats = rps:statistics(BrokerRef),
- ?assertMatch({ok, 2, 0, 0}, Stats).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement