<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading;
using NUnit.Framework;
using UnityEngine;
using NSubstitute;
using System.Reflection;

namespace UnityTest
{

	[TestFixture]
	[Category("Player Movement Test")]
	internal class PlayerMovementTest
	{
		private UnityScriptTestHelper testHelper = new UnityScriptTestHelper();
		public MockInputHelper inputHelper;

		public PlayerMovement testObject;

		[SetUp]
		public void Setup() {
			testObject = testHelper.InstantiateScript<PlayerMovement>();
			inputHelper = testHelper.InstantiateScript<MockInputHelper>();
			testObject.inputHelper = inputHelper;
			testObject.gameObject.AddComponent<Rigidbody2D>();
			testObject.gameObject.AddComponent<Animator> ();

			testHelper.Start(testObject);
		}

		[TearDown]
		public void TearDown() {
			testHelper.CleanUp ();
		}

		[Test]
		[Category("Player Movement")]
		public void PlayerMovesRightWhenMovingRight ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (1, 0);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate (testObject);

			//Assert
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (new Vector2(2, 0), rb.velocity);
		}

		
		[Test]
		[Category("Player Movement")]
		public void PlayerMovesAtNormalizedSpeedWhenMovingDiagonal ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (1, 1);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate(testObject);
			
			//Assert
			Vector2 expectedResult = new Vector2 (1, 1);
			expectedResult.Normalize ();
			expectedResult = expectedResult * testObject.movementSpeed;
			
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (expectedResult, rb.velocity);
		}
		
		[Test]
		[Category("Player Movement")]
		public void PlayerMovesAtAnalogSpeedWhenMovementIsInAnalog ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (0.5f, 0.5f);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate (testObject);
			
			//Assert
			Vector2 expectedResult = new Vector2 (0.5f, 0.5f);
			expectedResult = expectedResult * testObject.movementSpeed;
			
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (new Vector2(1, 1), rb.velocity);
		}

	}
}<commit_msg>Added test<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading;
using NUnit.Framework;
using UnityEngine;
using NSubstitute;
using System.Reflection;

namespace UnityTest
{

	[TestFixture]
	[Category("Player Movement Test")]
	internal class PlayerMovementTest 
	{
		private UnityScriptTestHelper testHelper = new UnityScriptTestHelper();
		public MockInputHelper inputHelper;

		public PlayerMovement testObject;

		[SetUp]
		public void Setup() {
			testObject = testHelper.InstantiateScript<PlayerMovement>();
			inputHelper = testHelper.InstantiateScript<MockInputHelper>();
			testObject.inputHelper = inputHelper;
			testObject.gameObject.AddComponent<Rigidbody2D>();
			testObject.gameObject.AddComponent<Animator> ();

			testHelper.Start(testObject);
		}

		[TearDown]
		public void TearDown() {
			testHelper.CleanUp ();
		}

		[Test]
		[Category("Player Movement")]
		public void PlayerMovesRightWhenMovingRight ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (1, 0);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate (testObject);

			//Assert
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (new Vector2(2, 0), rb.velocity);
		}

		
		[Test]
		[Category("Player Movement")]
		public void PlayerMovesAtNormalizedSpeedWhenMovingDiagonal ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (1, 1);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate(testObject);
			
			//Assert
			Vector2 expectedResult = new Vector2 (1, 1);
			expectedResult.Normalize ();
			expectedResult = expectedResult * testObject.movementSpeed;
			
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (expectedResult, rb.velocity);
		}
		
		[Test]
		[Category("Player Movement")]
		public void PlayerMovesAtAnalogSpeedWhenMovementIsInAnalog ()
		{
			//Arrange
			inputHelper.mockAxisRaw = new Vector2 (0.5f, 0.5f);
			//Act
			testHelper.Update(testObject);
			testHelper.FixedUpdate (testObject);
			
			//Assert
			Vector2 expectedResult = new Vector2 (0.5f, 0.5f);
			expectedResult = expectedResult * testObject.movementSpeed;
			
			var rb = testObject.GetComponent<Rigidbody2D> ();
			Assert.AreEqual (new Vector2(1, 1), rb.velocity);
		}

		[Test]
		public void KnockbackDisablesControlsAndMovesPlayerInDirection () {
			//arrange
			testObject.damagedMovementSpeed = 5f;

			//act
			testObject.KnockBack(new Vector2(1,0));
			testHelper.FixedUpdate (testObject);

			//assert
			Assert.AreEqual (new Vector2 (5,0), testObject.GetComponent<Rigidbody2D>().velocity);

		}
	}
}
{'fraction_non_alphanumeric': 0.11149825783972125, 'fraction_numerical': 0.014347202295552367, 'mean_word_length': 4.252960172228202, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '4660766', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1523, 'n_words': 305}