DEV Community

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

Posted on • Updated on

Building the tests when the first player wins

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:
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
Enter fullscreen mode Exit fullscreen mode
  • When the first player chooses paper and the second player chooses the stone:
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
Enter fullscreen mode Exit fullscreen mode
  • When the first player chooses stone and the second player chooses the scissor:
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
Enter fullscreen mode Exit fullscreen mode

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

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)