<commit_before>require 'test_helper'

module Werewolf

  class GameTest < Minitest::Test

    def test_new_game_is_inactive
      assert !Game.new.active?
    end

    def test_new_game_has_no_players
      assert Game.new.players.empty?
    end

    def test_new_game_has_nil_active_roles
      assert Game.new.active_roles.nil?
    end

    def test_new_game_is_on_day_0
      assert_equal 0, Game.new.day_number
    end

    def test_new_game_time_period_is_nil
      assert Game.new.time_period.nil?
    end

    def test_join_adds_players_to_set
      game = Game.new
      player1 = Player.new('seth')
      player2 = Player.new('wesley')

      game.join(player1)
      game.join(player2)

      expected = Set.new [player1, player2]
      assert_equal expected, game.players
    end

    def test_raise_if_same_player_name_added_twice
      game = Game.new
      username = 'seth'
      game.join(Player.new(username))

      err = assert_raises(AlreadyJoinedError) {
        game.join(Player.new(username))
      }
      assert_match /already joined/, err.message
      assert_equal username, err.username
    end

    def test_join_raises_if_game_is_active
      game = Game.new
      game.stubs(:active?).returns(true)
      assert_raises(ActiveGameError) {
        game.join(Player.new('seth'))
      }
    end

    def test_game_can_be_started
      game = Game.new
      game.join(Player.new('seth'))
      game.start
    end

    def test_game_cannot_be_started_twice
      game = Game.new
      game.join(Player.new('seth'))
      game.start

      err = assert_raises(RuntimeError) {
        game.start
      }
      assert_match /Game is already active/, err.message
    end

    def test_game_needs_at_least_one_player_to_start
      game = Game.new
      err = assert_raises(RuntimeError) {
        game.start
      }
      assert_match /Game can't start until there is at least 1 player/, err.message
    end

    def test_once_started_game_is_active
      game = Game.new
      game.join(Player.new('seth'))
      game.start
      assert game.active?
    end

    def test_slack_formatting_players
      game = Game.new
      player1 = Player.new('seth')
      player2 = Player.new('wesley')
      player3 = Player.new('plough')

      game.join(player1)
      game.join(player2)
      game.join(player3)

      expected = "Players:  <@seth>, <@wesley>, <@plough>"
      assert_equal expected, game.format_players
    end

    def test_slack_formatting_players_when_no_players
      game = Game.new
      expected = "Zero players.  Type 'wolfbot join' to join the game."
      assert_equal expected, game.format_players
    end

    def test_slack_format_status_new_game
      game = Game.new
      assert_match /No game running/, game.format_status
      assert_match game.format_players, game.format_status
    end

    def test_slack_format_status_newly_active_game
      game = Game.new
      game.join(Player.new('seth'))
      game.start
      assert_match /Game is active/, game.format_status
      assert_match game.format_players, game.format_status
    end

    def test_roles_are_assigned_at_game_start
      game = Game.new
      game.join(Player.new('seth'))
      game.expects(:assign_roles)

      game.start
    end

    def test_all_players_have_roles_once_game_starts
      game = Game.new
      game.join(Player.new('seth'))
      game.join(Player.new('tom'))
      game.join(Player.new('bill'))
      game.start

      game.players.each do |player|
        assert player.role
      end
    end

    def test_starting_assigns_roles
      # TODO
    end

    def test_instance_method_returns_new_instance
      assert_equal Game, Game.instance.class
    end

    def test_instance_method_returns_same_instance_when_called_twice
      x = Game.instance
      y = Game.instance
      assert_equal x, y<commit_msg>remove test placeholder<commit_after>require 'test_helper'

module Werewolf

  class GameTest < Minitest::Test

    def test_new_game_is_inactive
      assert !Game.new.active?
    end

    def test_new_game_has_no_players
      assert Game.new.players.empty?
    end

    def test_new_game_has_nil_active_roles
      assert Game.new.active_roles.nil?
    end

    def test_new_game_is_on_day_0
      assert_equal 0, Game.new.day_number
    end

    def test_new_game_time_period_is_nil
      assert Game.new.time_period.nil?
    end

    def test_join_adds_players_to_set
      game = Game.new
      player1 = Player.new('seth')
      player2 = Player.new('wesley')

      game.join(player1)
      game.join(player2)

      expected = Set.new [player1, player2]
      assert_equal expected, game.players
    end

    def test_raise_if_same_player_name_added_twice
      game = Game.new
      username = 'seth'
      game.join(Player.new(username))

      err = assert_raises(AlreadyJoinedError) {
        game.join(Player.new(username))
      }
      assert_match /already joined/, err.message
      assert_equal username, err.username
    end

    def test_join_raises_if_game_is_active
      game = Game.new
      game.stubs(:active?).returns(true)
      assert_raises(ActiveGameError) {
        game.join(Player.new('seth'))
      }
    end

    def test_game_can_be_started
      game = Game.new
      game.join(Player.new('seth'))
      game.start
    end

    def test_game_cannot_be_started_twice
      game = Game.new
      game.join(Player.new('seth'))
      game.start

      err = assert_raises(RuntimeError) {
        game.start
      }
      assert_match /Game is already active/, err.message
    end

    def test_game_needs_at_least_one_player_to_start
      game = Game.new
      err = assert_raises(RuntimeError) {
        game.start
      }
      assert_match /Game can't start until there is at least 1 player/, err.message
    end

    def test_once_started_game_is_active
      game = Game.new
      game.join(Player.new('seth'))
      game.start
      assert game.active?
    end

    def test_slack_formatting_players
      game = Game.new
      player1 = Player.new('seth')
      player2 = Player.new('wesley')
      player3 = Player.new('plough')

      game.join(player1)
      game.join(player2)
      game.join(player3)

      expected = "Players:  <@seth>, <@wesley>, <@plough>"
      assert_equal expected, game.format_players
    end

    def test_slack_formatting_players_when_no_players
      game = Game.new
      expected = "Zero players.  Type 'wolfbot join' to join the game."
      assert_equal expected, game.format_players
    end

    def test_slack_format_status_new_game
      game = Game.new
      assert_match /No game running/, game.format_status
      assert_match game.format_players, game.format_status
    end

    def test_slack_format_status_newly_active_game
      game = Game.new
      game.join(Player.new('seth'))
      game.start
      assert_match /Game is active/, game.format_status
      assert_match game.format_players, game.format_status
    end

    def test_roles_are_assigned_at_game_start
      game = Game.new
      game.join(Player.new('seth'))
      game.expects(:assign_roles)

      game.start
    end

    def test_all_players_have_roles_once_game_starts
      game = Game.new
      game.join(Player.new('seth'))
      game.join(Player.new('tom'))
      game.join(Player.new('bill'))
      game.start

      game.players.each do |player|
        assert player.role
      end
    end
    
    def test_instance_method_returns_new_instance
      assert_equal Game, Game.instance.class
    end

    def test_instance_method_returns_same_instance_when_called_twice
      x = Game.instance
      y = Game.instance
      assert_equal x, y
{'fraction_non_alphanumeric': 0.07874118568816924, 'fraction_numerical': 0.003917471924784539, 'mean_word_length': 2.590717299578059, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5801619', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2491, 'n_words': 475}