Skip to content
Snippets Groups Projects
Commit 5f8170ee authored by Trandinh Thien's avatar Trandinh Thien
Browse files

Added unit testing for animation class

parent 507c9cf3
No related branches found
No related tags found
No related merge requests found
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Model;
using Microsoft.Xna.Framework;
using System;
using Controller;
namespace ControllerTest
{
[TestClass]
public class AnimationTest
{
[TestMethod]
//Test unit returns to original location after attacking Right, Left, Up, and Down
public void attackAnimation_Return_to_previous_location_ShouldReturnTrue()
{
Mock<Unit> mockUnit = new Mock<Unit>(); //create mock object for unit
mockUnit.Setup(Unit => Unit.Position).Returns(new Tuple<int, int>(18, 15)); //mock position of unit to return (18, 15)
var unitOrigPosition = new Tuple<int, int>(18, 15); //store mock original position of unit at (18, 15)
View.Animation.attackAnimation(Direction.Right, mockUnit.Object); //animate unit attacking Right
Assert.IsTrue(mockUnit.Object.Position==unitOrigPosition);
View.Animation.attackAnimation(Direction.Left, mockUnit.Object); //animate unit attacking Left
Assert.IsTrue(mockUnit.Object.Position == unitOrigPosition);
View.Animation.attackAnimation(Direction.Up, mockUnit.Object); //animate unit attacking Up
Assert.IsTrue(mockUnit.Object.Position == unitOrigPosition);
View.Animation.attackAnimation(Direction.Down, mockUnit.Object); //animate unit attacking Down
Assert.IsTrue(mockUnit.Object.Position == unitOrigPosition);
}
[TestMethod]
//Test unit successfully moves to new node55
public void animatePosition_should_move_to_new_location_ShouldReturnTrue()
{
Mock<Unit> mockUnit = new Mock<Unit>(); //create mock object for unit
Mock<Graph> mockGraph = new Mock<Graph>(); //create mock game graph
Mock<Node> mockNode = new Mock<Node>(); //create mock node that is clicked
//set unit and node so that unit moves right
mockUnit.Setup(Unit => Unit.PixelCoordinates).Returns(new Vector2 (576,480)); //mock position of unit to return (18, 15)
mockNode.Setup(Node => Node.getPositionX()).Returns(20); //set node position X to be 2 to the right of unit
mockNode.Setup(Node => Node.getPositionX()).Returns(15); //set node position Y to be same as unit
Vector2 nodeVectorPixelCoordinates = new Vector2(mockNode.Object.getPositionX()*32, (mockNode.Object.getPositionY()*32));
View.Animation.animateUnitPosition(mockGraph.Object, mockUnit.Object, mockNode.Object);
Assert.IsTrue(mockUnit.Object.PixelCoordinates == nodeVectorPixelCoordinates);
//set unit and node so that unit moves left
mockUnit.Setup(Unit => Unit.PixelCoordinates).Returns(new Vector2(640, 480)); //mock position of unit to return (20, 15)
mockNode.Setup(Node => Node.getPositionX()).Returns(18); //set node position X to be 2 to the left of unit
mockNode.Setup(Node => Node.getPositionX()).Returns(15); //set node position Y to be same as unit
nodeVectorPixelCoordinates = new Vector2(mockNode.Object.getPositionX() * 32, (mockNode.Object.getPositionY() * 32));
View.Animation.animateUnitPosition(mockGraph.Object, mockUnit.Object, mockNode.Object);
Assert.IsTrue(mockUnit.Object.PixelCoordinates == nodeVectorPixelCoordinates);
//set unit and node so that unit moves down
mockUnit.Setup(Unit => Unit.PixelCoordinates).Returns(new Vector2(576, 480)); //mock position of unit to return (18, 15)
mockNode.Setup(Node => Node.getPositionX()).Returns(18); //set node position X to be 2 to the right of unit
mockNode.Setup(Node => Node.getPositionX()).Returns(17); //set node position Y to be 2 down of unit
nodeVectorPixelCoordinates = new Vector2(mockNode.Object.getPositionX() * 32, (mockNode.Object.getPositionY() * 32));
View.Animation.animateUnitPosition(mockGraph.Object, mockUnit.Object, mockNode.Object);
Assert.IsTrue(mockUnit.Object.PixelCoordinates == nodeVectorPixelCoordinates);
//set unit and node so that unit moves up
mockUnit.Setup(Unit => Unit.PixelCoordinates).Returns(new Vector2(576, 544)); //mock position of unit to return (18, 17)
mockNode.Setup(Node => Node.getPositionX()).Returns(18); //set node position X to be 2 to the right of unit
mockNode.Setup(Node => Node.getPositionX()).Returns(15); //set node position Y to be same as unit
nodeVectorPixelCoordinates = new Vector2(mockNode.Object.getPositionX() * 32, (mockNode.Object.getPositionY() * 32));
View.Animation.animateUnitPosition(mockGraph.Object, mockUnit.Object, mockNode.Object);
Assert.IsTrue(mockUnit.Object.PixelCoordinates == nodeVectorPixelCoordinates);
}
[TestMethod]
//Test unit returns to original location after attacking Right, Left, Up, and Down
public void animate_changes_to_correct_frame_ShouldReturnTrue()
{
Mock<Unit> mockUnit = new Mock<Unit>(); //create mock object for unit
//check animation for unit moving down
mockUnit.Setup(Unit => Unit.currentFrame).Returns(5); //unit is facing a different direction
View.Animation.animate(Direction.Down, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 1); //unit should now face down
mockUnit.Setup(Unit => Unit.currentFrame).Returns(0); //frame 1 of walking down
View.Animation.animate(Direction.Down, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 1); //should be frame 2 of walking down
mockUnit.Setup(Unit => Unit.currentFrame).Returns(1); //frame 2 of walking down
View.Animation.animate(Direction.Down, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 2); //should be frame 3 of walking down
mockUnit.Setup(Unit => Unit.currentFrame).Returns(2); //frame 3 of walking down
View.Animation.animate(Direction.Down, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 0); //should be frame 1 of walking down
//check animation for unit moving left
mockUnit.Setup(Unit => Unit.currentFrame).Returns(10); //unit is facing a different direction
View.Animation.animate(Direction.Left, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 4); //unit should now face left
mockUnit.Setup(Unit => Unit.currentFrame).Returns(3); //frame 1 of walking left
View.Animation.animate(Direction.Left, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 4); //should be frame 2 of walking left
mockUnit.Setup(Unit => Unit.currentFrame).Returns(4); //frame 2 of walking left
View.Animation.animate(Direction.Left, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 5); //should be frame 3 of walking left
mockUnit.Setup(Unit => Unit.currentFrame).Returns(5); //frame 3 of walking left
View.Animation.animate(Direction.Left, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 3); //should be frame 1 of walking left
//check animation for unit moving right
mockUnit.Setup(Unit => Unit.currentFrame).Returns(11); //unit is facing a different direction
View.Animation.animate(Direction.Right, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 7); //unit should now face right
mockUnit.Setup(Unit => Unit.currentFrame).Returns(6); //frame 1 of walking right
View.Animation.animate(Direction.Right, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 7); //should be frame 2 of walking right
mockUnit.Setup(Unit => Unit.currentFrame).Returns(7); //frame 2 of walking right
View.Animation.animate(Direction.Right, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 8); //should be frame 3 of walking right
mockUnit.Setup(Unit => Unit.currentFrame).Returns(8); //frame 3 of walking right
View.Animation.animate(Direction.Right, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 6); //should be frame 1 of walking right
//check animation for unit moving up
mockUnit.Setup(Unit => Unit.currentFrame).Returns(1); //unit is facing a different direction
View.Animation.animate(Direction.Up, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 10); //unit should now face up
mockUnit.Setup(Unit => Unit.currentFrame).Returns(9); //frame 1 of walking up
View.Animation.animate(Direction.Up, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 10); //should be frame 2 of walking up
mockUnit.Setup(Unit => Unit.currentFrame).Returns(10); //frame 2 of walking up
View.Animation.animate(Direction.Up, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 11); //should be frame 3 of walking up
mockUnit.Setup(Unit => Unit.currentFrame).Returns(11); //frame 3 of walking up
View.Animation.animate(Direction.Up, mockUnit.Object);
Assert.IsTrue(mockUnit.Object.currentFrame == 9); //should be frame 1 of walking up
}
}
}
......@@ -61,6 +61,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="AnimationTest.cs" />
<Compile Include="GameFunctionTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -72,3 +72,77 @@ C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Cas
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Moq.dll
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Castle.Core.xml
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Moq.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Game_Map.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\MenuImage.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\attackableNode.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\moveableNode.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\items.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\move.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\wait.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\warrior.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\instructions1.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\instructions2.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\instructions3.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\archer.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\mage.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2archer.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2archer_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2mage.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2mage_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2warrior.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2warrior_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\archer_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\mage_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\warrior_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\attack_confirm.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\confirm_attack.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\archer_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2archer_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2mage_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\2warrior_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\mage_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\warrior_stats.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\exit_game.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Inventory_Button.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\End_Button.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\player1turn.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\player2turn.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\map1_obstacles.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\ClearBar.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\HealthBar1.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\HealthBar2.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\player1turn_overlay.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\player2turn_overlay.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\PixelFont.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\PixelFontLarge.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\PixelFontLargest.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Bow.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Fireball.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Footstep.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\Sword.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\MenuSong.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\BattleTheme.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Content\MapTheme.xnb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\BlazeBrigadeTest.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\BlazeBrigadeTest.pdb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Blaze_Brigade.exe
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Castle.Core.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Game.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Graphics.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Moq.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.GamerServices.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Input.Touch.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Blaze_Brigade.pdb
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Castle.Core.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Game.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Graphics.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Moq.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.GamerServices.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\bin\Debug\Microsoft.Xna.Framework.Input.Touch.xml
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\obj\Debug\BlazeBrigadeTest.csprojResolveAssemblyReference.cache
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\obj\Debug\BlazeBrigadeTest.dll
C:\Users\Thien Trandinh\Documents\Blaze-Brigade\src\BlazeBrigadeTest\obj\Debug\BlazeBrigadeTest.pdb
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment