const expect = require('chai').expect
import Player from '../app/scripts/lib/Player'
import BattleRPS from '../app/scripts/lib/BattleRPS'

describe('Player', function () {
  describe('Player Computer in Random mode', function () {
    it('should play randomly', () => {
      const RPS = [BattleRPS.ROCK, BattleRPS.PAPER, BattleRPS.SCISSORS]
      const computerPlayer = new Player(Player.COMPUTER, Player.COMPUTER_MODE_RANDOM)
      const hit = computerPlayer.play()

      expect(RPS).to.include(hit)
    })
  })

  describe('Player Computer in Gon mode', function () {
    beforeEach(function (done) {
      const gonPlayer = new Player(Player.COMPUTER, Player.COMPUTER_MODE_GON)
      done(gonPlayer)
    })
    it('should play randomly 33% with no battle score', (gonPlayer) => {
      const RPS = [BattleRPS.ROCK, BattleRPS.PAPER, BattleRPS.SCISSORS]
      let hit = gonPlayer.play()

      // random hit
      expect(RPS).to.include(hit)

      // if equality, next rounds would be random
      hit = gonPlayer(null, [{hit: 'R', status: 'E'}])

      // random hit
      expect(RPS).to.include(hit)
    })

    it('should play randomly 50% with battle score twice same hits', (gonPlayer) => {
      let rivalScore = []
      let hit = null

      rivalScore = [{hit: 'S'}, {hit: 'S'}]
      hit = gonPlayer.play(null, rivalScore)

      // never play rock after twice scissors
      expect(hit).to.be.not.equal('R')
      expect(['P', 'S']).to.include(hit)

      rivalScore = [{hit: 'R'}, {hit: 'R'}]
      hit = gonPlayer.play(null, rivalScore)

      // never play paper after twice rocks
      expect(hit).to.be.not.equal('P')
      expect(['R', 'S']).to.include(hit)

      rivalScore = [{hit: 'P'}, {hit: 'P'}]
      hit = gonPlayer.play(null, rivalScore)

      // never play scissors after twice papers
      expect(hit).to.be.not.equal('S')
      expect(['R', 'P']).to.include(hit)
    })

    it('should play a specific hit when rival won', (gonPlayer) => {
      let rivalScore = []
      let hit = null

      rivalScore = [{hit: 'R', status: 'W'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('P')

      rivalScore = [{hit: 'P', status: 'W'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('S')

      rivalScore = [{hit: 'S', status: 'W'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('R')
    })

    it('should play a specific hit when rival lose', (gonPlayer) => {
      let rivalScore = []
      let hit = null

      rivalScore = [{hit: 'R', status: 'L'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('S')

      rivalScore = [{hit: 'P', status: 'L'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('R')

      rivalScore = [{hit: 'S', status: 'L'}]
      hit = gonPlayer.play(null, rivalScore)
      expect(hit).to.be('P')
    })
  })
})

@@ -573,34 +573,65 @@
     
-beforeEach(function (done)
+it('should play randomly 33%25 with no battle score', () =%3E
  %7B%0A 
@@ -711,110 +711,8 @@
 ON)%0A
-      done(gonPlayer)%0A    %7D)%0A    it('should play randomly 33%25 with no battle score', (gonPlayer) =%3E %7B%0A
     
@@ -939,16 +939,21 @@
 onPlayer
+.play
 (null, %5B
@@ -1107,24 +1107,43 @@
 ame hits', (
+) =%3E %7B%0A      const 
 gonPlayer) =
@@ -1131,38 +1131,88 @@
  const gonPlayer
-)
  =
-%3E %7B
+ new Player(Player.COMPUTER, Player.COMPUTER_MODE_GON)
 %0A      let rival
@@ -1951,24 +1951,43 @@
 ival won', (
+) =%3E %7B%0A      const 
 gonPlayer) =
@@ -1975,38 +1975,88 @@
  const gonPlayer
-)
  =
-%3E %7B
+ new Player(Player.COMPUTER, Player.COMPUTER_MODE_GON)
 %0A      let rival
@@ -2197,24 +2197,30 @@
 t(hit).to.be
+.equal
 ('P')%0A%0A     
@@ -2319,32 +2319,38 @@
 xpect(hit).to.be
+.equal
 ('S')%0A%0A      riv
@@ -2449,24 +2449,30 @@
 t(hit).to.be
+.equal
 ('R')%0A    %7D)
@@ -2527,16 +2527,35 @@
 lose', (
+) =%3E %7B%0A      const 
 gonPlaye
@@ -2555,22 +2555,72 @@
 onPlayer
-)
  =
-%3E %7B
+ new Player(Player.COMPUTER, Player.COMPUTER_MODE_GON)
 %0A      l
@@ -2773,16 +2773,22 @@
 t).to.be
+.equal
 ('S')%0A%0A 
@@ -2899,16 +2899,22 @@
 t).to.be
+.equal
 ('R')%0A%0A 
@@ -3025,16 +3025,22 @@
 t).to.be
+.equal
 ('P')%0A  

Fix Player TDD test