DEV Community

Cover image for Building the tests when the second player wins
Diego Novais
Diego Novais

Posted on

Building the tests when the second player wins

The second player wins when his item chosen is the most powerful.

  • When the second player chooses scissors and the first player chooses the paper:
defmodule GameTest do use ExUnit.Case @stone 1 @paper 2 @scissor 3 # ... describe "Game.play/2 when second player wins" do test "when second player chooses scissor and first player chooses paper" do first_player_choice = @paper second_player_choise = @scissor assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end end end 
Enter fullscreen mode Exit fullscreen mode
  • When the second player chooses paper and the first player chooses the stone:
defmodule GameTest do use ExUnit.Case @stone 1 @paper 2 @scissor 3 # ... describe "Game.play/2 when second player wins" do #... test "when second player chooses paper and first player chooses stone" do first_player_choice = @stone second_player_choise = @paper assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end end end 
Enter fullscreen mode Exit fullscreen mode
  • When the second player chooses stone and the first player chooses the scissor:
defmodule GameTest do use ExUnit.Case @stone 1 @paper 2 @scissor 3 # ... describe "Game.play/2 when second player wins" do #... test "when second player chooses stone and first player chooses scissor" do first_player_choice = @scissor second_player_choise = @stone assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end end end 
Enter fullscreen mode Exit fullscreen mode

Let's look at the code of the tests when the game's result is "Second player win!!!".

defmodule GameTest do use ExUnit.Case @stone 1 @paper 2 @scissor 3 # ... describe "Game.play/2 when second player wins" do test "when second player chooses scissors and first player chooses paper" do first_player_choice = @paper second_player_choise = @scissor assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end test "when second player chooses paper and first player chooses stone" do first_player_choice = @stone second_player_choise = @paper assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end test "when second player chooses stone and first player chooses scissors" do first_player_choice = @scissor second_player_choise = @stone assert {:ok, match} = Game.play(first_player_choice, second_player_choise) assert match == "Second player win!!!" end end end 
Enter fullscreen mode Exit fullscreen mode

In the next post (soon), we'll code our module Game following the tests when the Second Player wins.

Contacts

Email: contato@diegonovais.com.br
Linkedin: https://www.linkedin.com/in/diegonovais/
Twitter: https://twitter.com/diegonovaistech

Top comments (0)