Building the tests when the first player wins
Tags: elixir, algorithms, webdev, tutorial
Published: 2022-08-30 04:12:00

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

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

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

```Elixir
defmodule GameTest do
  use ExUnit.Case

  @stone 1
  @paper 2
  @scissor 3

# ...

  describe "Game.play/2 when first player wins" do
    test "when first player chooses scissor and second player chooses paper" do
      first_player_choice = @scissor
      second_player_choise = @paper

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end
  end
end
```

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

```Elixir
defmodule GameTest do
  use ExUnit.Case

  @stone 1
  @paper 2
  @scissor 3

# ...

  describe "Game.play/2 when first player wins" do
    # ...
    test "when first player chooses paper and second player chooses stone" do
      first_player_choice = @paper
      second_player_choise = @stone

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end
  end
end
```

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

```Elixir
defmodule GameTest do
  use ExUnit.Case

  @stone 1
  @paper 2
  @scissor 3

# ...

  describe "Game.play/2 when first player wins" do
    # ...
    test "when first player chooses stone and second player chooses scissor" do
      first_player_choice = @stone
      second_player_choise = @scissor

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end
  end
end
```

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

```Elixir
defmodule GameTest do
  use ExUnit.Case

  @stone 1
  @paper 2
  @scissor 3

# ...

  describe "Game.play/2 when first player wins" do
    test "when first player chooses scissor and second player chooses paper" do
      first_player_choice = @scissor
      second_player_choise = @paper

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end

    test "when first player chooses paper and second player chooses stone" do
      first_player_choice = @paper
      second_player_choise = @stone

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end

    test "when first player chooses stone and second player chooses scissor" do
      first_player_choice = @stone
      second_player_choise = @scissor

      assert {:ok, match} = Game.play(first_player_choice, second_player_choise)

      assert match == "First player win!!!"
    end
  end
end
```

In the next post, we'll code our module Game following the tests when the First Player wins.

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