<commit_before>define [
  'phaser'
  'underscore'
  'app/player'
  'test/helpers'
], (Phaser, _, Player, helpers) ->

  describe 'Player', ->
    game = null
    player = null

    beforeEach ->
      spyOn Player::, '_initialize'
      player = new Player()
      spyOn(player, method).and.callThrough() for method in [
        '_beginJump'
        '_beginRun'
        '_beginTurn', '_endTurn'
        '_playAnimation'
      ]
      _.extend player, helpers.createFakePlayerProps(player)

      player._initPhysics()
      player._initState()

    testStartAnimation = ->
      it 'will play start animation', ->
        expect(player.nextAction).toBe 'start'
        expect(player._playAnimation).toHaveBeenCalledWith 'start', undefined

    describe 'when initialized', ->
      it 'is set to still and facing right', ->
        expect(player.state).toBe 'still'
        expect(player.direction).toBe Player.Direction.Right
        expect(player.animation).toBeNull()

      it 'has no next state info', ->
        expect(player.nextAction).toBe 'none'
        expect(player.nextDirection).toBeNull()
        expect(player.nextState).toBeNull()

    describe 'when x cursor key is down in same direction', ->
      beforeEach ->
        player.cursors.right.isDown = yes
        player.update()

      it 'can get and set the right direction from #_xDirectionInput', ->
        expect(player._xDirectionInput()).toBe Player.Direction.Right
        expect(player.nextDirection).toBe Player.Direction.Right

      describe 'when still', ->
        it 'will begin to run', ->
          expect(player.state).toBe 'running'
          expect(player._beginRun).toHaveBeenCalled()

        testStartAnimation()

    describe 'when x cursor key is down in opposite direction', ->
      beforeEach ->
        player.cursors.left.isDown = yes
        player.update()

      it 'can get and set the right direction from #_xDirectionInput', ->
        expect(player._xDirectionInput()).toBe Player.Direction.Left
        expect(player.nextDirection).toBe Player.Direction.Left

      describe 'when still', ->
        it 'will immediately (end) turn and begin to run', ->
          expect(player._isTurning).toBe yes
          expect(player.direction).toBe Player.Direction.Left
          expect(player._beginRun).toHaveBeenCalled()

        testStartAnimation()<commit_msg>Expand Player specs for basic jumping except landing.<commit_after>define [
  'phaser'
  'underscore'
  'app/player'
  'test/helpers'
], (Phaser, _, Player, helpers) ->

  describe 'Player', ->
    game = null
    player = null

    beforeEach ->
      spyOn Player::, '_initialize'
      player = new Player()
      spyOn(player, method).and.callThrough() for method in [
        '_beginJump', '_buildJump', '_endJump'
        '_beginRun'
        '_beginTurn', '_endTurn'
        '_playAnimation'
      ]
      _.extend player, helpers.createFakePlayerProps(player)

      player._initPhysics()
      player._initState()

    testStartAnimation = ->
      it 'will play start animation', ->
        expect(player.nextAction).toBe 'start'
        expect(player._playAnimation).toHaveBeenCalledWith 'start', undefined

    describe 'when initialized', ->
      it 'is set to still and facing right', ->
        expect(player.state).toBe 'still'
        expect(player.direction).toBe Player.Direction.Right
        expect(player.animation).toBeNull()

      it 'has no next state info', ->
        expect(player.nextAction).toBe 'none'
        expect(player.nextDirection).toBeNull()
        expect(player.nextState).toBeNull()

    describe 'when x cursor key is down in same direction', ->
      beforeEach ->
        player.cursors.right.isDown = yes
        player.update()

      it 'can get and set the right direction from #_xDirectionInput', ->
        expect(player._xDirectionInput()).toBe Player.Direction.Right
        expect(player.nextDirection).toBe Player.Direction.Right

      describe 'when still', ->
        it 'will begin to run', ->
          expect(player.state).toBe 'running'
          expect(player._beginRun).toHaveBeenCalled()

        testStartAnimation()

    describe 'when x cursor key is down in opposite direction', ->
      beforeEach ->
        player.cursors.left.isDown = yes
        player.update()

      it 'can get and set the right direction from #_xDirectionInput', ->
        expect(player._xDirectionInput()).toBe Player.Direction.Left
        expect(player.nextDirection).toBe Player.Direction.Left

      describe 'when still', ->
        it 'will immediately (end) turn and begin to run', ->
          expect(player._isTurning).toBe yes
          expect(player.direction).toBe Player.Direction.Left
          expect(player._beginRun).toHaveBeenCalled()

        testStartAnimation()

    describe 'when up key is down', ->
      initialYAcceleration = null

      beforeEach ->
        player.cursors.up.isDown = yes
        initialYAcceleration = player.acceleration.y
        player.update()

      describe 'when still', ->
        it 'will only begin to jump', ->
          expect(player.state).toBe 'rising'
          expect(player._beginJump).toHaveBeenCalled()

          expect(player._buildJump).not.toHaveBeenCalled()
          expect(player._endJump).not.toHaveBeenCalled()

        it 'will play jump animation', ->
          expect(player.nextAction).toBe 'jump'
          expect(player._playAnimation).toHaveBeenCalledWith 'jump', undefined

        it 'will not run on jump', ->
          expect(player._beginRun).not.toHaveBeenCalled()

        it 'will decrease y acceleration', ->
          expect(player.acceleration.y).toBeLessThan initialYAcceleration

      describe 'when rising', ->
        beforeEach ->
          player.update()

        it 'will only continue and build jump', ->
          expect(player.state).toBe 'rising'
          expect(player._buildJump).toHaveBeenCalled()

          expect(player._beginJump.calls.count()).toBe 1
          expect(player._endJump).not.toHaveBeenCalled()

      describe 'when done building', ->
        beforeEach ->
          player.update()
          player.velocity.y = 1
          player.cursors.up.isDown = no
          player.cursors.up.isUp = yes
          player.update() # End jump.
          player.update() # Fall.

        it 'will only end the jump and start falling', ->
          expect(player.acceleration.y).toBe initialYAcceleration

          expect(player._beginJump.calls.count()).toBe 1
          expect(player._buildJump.calls.count()).toBe 1

          expect(player.state).toBe 'falling'

        it 'will play fall animation', ->
          expect(player._playAnimation).toHaveBeenCalledWith 31, no
{'fraction_non_alphanumeric': 0.11129345069371924, 'fraction_numerical': 0.0008951215873489483, 'mean_word_length': 2.4844074844074844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '3056890', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1774, 'n_words': 438}