Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. game_test() ->
  2. {"Rock and paper play best of 3, first round tie",
  3. fun() ->
  4. {ok, BrokerRef } = rps:start(),
  5. spawn(fun() -> rock_bot(BrokerRef, rock_bot) end),
  6. spawn(fun() -> paper_bot(BrokerRef, paper_bot) end)
  7. end}.
  8.  
  9. rock_bot(BrokerRef, BotName) ->
  10. {ok, _, Coordinator} = rps:queue_up(BrokerRef, BotName, 3),
  11. Res = rps:move(Coordinator, rock), % tie round
  12. ?assertMatch(tie, Res),
  13. Res = rps:move(Coordinator, rock),
  14. ?assertMatch(round_lost, Res),
  15. Res2 = rps:move(Coordinator, rock),
  16. ?assertMatch({game_over, 0, 2}, Res2).
  17.  
  18. paper_bot(BrokerRef, BotName) ->
  19. {ok, _, Coordinator} = rps:queue_up(BrokerRef, BotName, 3),
  20. Res = rps:move(Coordinator, rock), %tie round
  21. ?assertMatch(tie, Res),
  22. Res = rps:move(Coordinator, paper),
  23. ?assertMatch(round_won, Res),
  24. Res2 = rps:move(Coordinator, paper),
  25. ?assertMatch({game_over, 2, 0}, Res2),
  26. Stats = rps:statistics(BrokerRef),
  27. ?assertMatch({ok, 2, 0, 0}, Stats).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement