Building the tests when the second player wins
Tags: elixir, algorithms, webdev, tutorial
Published: 2022-08-31 15:34:56

---
series: Rock, Paper, and Scissors with Elixir
---

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**:

```Elixir
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
```

- When the second player chooses **paper** and the first player chooses the **stone**:

```Elixir
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
```

- When the second player chooses **stone** and the first player chooses the **scissor**:

```Elixir
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
```

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

```Elixir
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
```

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