<commit_before>const chai = require('chai');
const assert = chai.assert;

const Player = require('../lib/player');
const KeyTracker = require('../lib/keyboard-tracker');
const Food = require('../lib/food')

describe('Player eats food', function(){
  context('Player 1', function(){
    it('eats a piece of food if its in range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 6, y: 6} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray) // the eatFood function checks the area around a player and eats anything in range
      assert.equal(foodArray.length, 0)
    });

    it('does not eat a piece of food if its out of range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 5, y: 20} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)

      keyTracker.keyPressed[83] = true;
      for(var i = 0; i < 10; i++){
        player1.move();
      };

      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)
    });

    it('moves towards food and eats a piece of food if its in range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 5, y: 20} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)
      // player1 needs to move 3 times towards the food to have it be in range to eat
      keyTracker.keyPressed[83] = true;
      player1.move();
      assert.equal(foodArray.length, 1)
      player1.move()
      player1.move()

      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 0)
    });
  });
});<commit_msg>finishs the last test to allow for changes in player speed as we work on variations of the game<commit_after>const chai = require('chai');
const assert = chai.assert;

const Player = require('../lib/player');
const KeyTracker = require('../lib/keyboard-tracker');
const Food = require('../lib/food')

describe('Player eats food', function(){
  context('Player 1', function(){
    it('eats a piece of food if its in range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 6, y: 6} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray) // the eatFood function checks the area around a player and eats anything in range
      assert.equal(foodArray.length, 0)
    });

    it('does not eat a piece of food if its out of range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 5, y: 20} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)

      keyTracker.keyPressed[83] = true;
      for(var i = 0; i < 10; i++){
        player1.move();
      };

      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)
    });

    it('moves towards food and eats a piece of food if its in range', function(){
      var canvas = { width: 500, height: 500 };
      var keyTracker = new KeyTracker(canvas);
      let player1 = new Player("Player 1", 5, 5, 5, keyTracker);
      var food1 = new Food( { x: 5, y: 20} );
      var foodArray = [food1]

      assert.equal(foodArray.length, 1)
      player1.eatFood(foodArray)
      assert.equal(foodArray.length, 1)
      // player1 needs to move 3 times towards the food to have it be in range to eat
      keyTracker.keyPressed[83] = true;

      for(var i = 0; i < 10; i++){
        player1.move();
        player1.eatFood(foodArray)
      };

      assert.equal(foodArray.length, 0)
    });
  });
});
{'fraction_non_alphanumeric': 0.13275349050125887, 'fraction_numerical': 0.03433279926756695, 'mean_word_length': 2.7382378100940974, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '2860288', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1342, 'n_words': 454}