# spec/spec_game.rb
require 'spec_helper'

module TicTacToe

  describe Game do
    before(:example) do
      board = TicTacToe::Board.new()
      @p1 = Base::Player.new(name: 'foo', type: TicTacToe::Shared::GameParms::O)
      @p2 = Base::Player.new(name: 'bar', type: TicTacToe::Shared::GameParms::X)      
      @game = Game.new(board, @p1, @p2)      
      @game_parms = TicTacToe::Shared::GameParms.setup
    end

    after(:example) do
      Base::Player.send(:reset)
    end
    
    context "#player" do

      it "initialize player turns - randomly" do
        actual = @game.send(:_init_players)
        expected = [@p1, @p2]
        expect(actual).to contain_exactly(*expected)
      end

      it "alternate the game between the two players" do
        actual1 = @game.send(:_switch_players, @p1, @p2)  # if p1, p2...
        actual2 = @game.send(:_switch_players, @p2, @p1)
        #
        expect(actual1).to match_array([@p2, @p1])        # then p2, p1
        expect(actual2).to match_array([@p1, @p2])
      end
      
    end
    
  end
  
end
