Ejemplo n.º 1
0
        public void AttackCleanUp_RemoveLowHealth()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            combatant1Copy.Health = 0;
            Combatant combatant2Copy = CopyCombatant(combatant2);
            combatant2Copy.Health = 0;
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants);

            // assert
            if (combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID))
            {
                Assert.Fail("AttackCleanUp failed to remove the attacker with low stanima");
                return;
            }
            if (combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID))
            {
                Assert.Fail("AttackCleanUp failed to remvoe the defender with low stanima");
                return;
            }
            Assert.IsTrue(true);
        }
Ejemplo n.º 2
0
        public void GetGoldRewards_CheckAmountInSpan()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);

            Battle battleClass = new Battle();

            // act
            // loop through the method 10000 times to get a good span
            int goldReward;
            for(int i = 0; i < 10000; i++) {
                goldReward = battleClass.GetGoldRewards(combatants);

                // assert
                if(goldReward < 4 || goldReward > 13) {
                    Assert.Fail("GetGoldRewards awards the wrong amount of gold");
                }
            }
            Assert.IsTrue(true);
        }
Ejemplo n.º 3
0
        public void AttackCleanUp_NoRemoval()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants);

            // assert
            if(combatant1Copy.Stanima == combatant1Copy.MaxStanima - 1 &&
                combatant2Copy.Stanima == combatant2Copy.MaxStanima - 1 &&
                combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID) &&
                combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID))
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("AttackCleanUp removes combatants it's not supposed to remove");
            }
        }
Ejemplo n.º 4
0
        public void Turn_CheckCombatLogEntries()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.Turn(ref combatants);

            // assert

            // print the combatlog to test output
            for (int i = 0; i < battleClass.GetCombatLog().Count; i++)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("LogEntry: {0} DefenderDamage: {1} AttackerDamage: {2}", battleClass.GetCombatLog()[i].Text, battleClass.GetCombatLog()[i].DefenderDamage, battleClass.GetCombatLog()[i].AttackerDamage));
            }

            // If a combatant died before he had a chance to do something, the combatlog will have one less entry
            // Due to the random nature of the turnorder, one can not be sure which combatant attacks first.
            if (combatants[0].Health <= 0 || combatants[1].Health <= 0)
            {
                if (battleClass.GetCombatLog().Count == 1 || battleClass.GetCombatLog().Count == 2)
                {
                    Assert.IsTrue(true);
                    return;
                }
            }
            else
            {
                Assert.AreEqual(2, battleClass.GetCombatLog().Count, "The turn method does not fill the combatlog with information correctly");
                return;
            }
            Assert.Fail("The turn method does not fill the combatlog with information correctly");
        }
Ejemplo n.º 5
0
        public void CombatCleanUp_CheckWithMoreThanOneTeamLeft()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(combatant2);

            Battle battleClass = new Battle();

            // act
            battleClass.CombatCleanUp(combatants);
        }
Ejemplo n.º 6
0
        public void CountChance_CheckNumberSecondSlightyHigh()
        {
            // arrange
            Battle battleClass = new Battle();

            // act
            // loop through the method 10000 times to get a good span
            int randomNumber;
            for (int i = 0; i < 10000; i++)
            {
                randomNumber = battleClass.CountChance(10, 12);

                // assert
                if (randomNumber < 5 || randomNumber > 22)
                {
                    Assert.Fail("CountChance has a chance of giving the wrong number if the second value sent to it is slightly higher than first");
                    return;
                }
            }
            Assert.IsTrue(true);
        }
Ejemplo n.º 7
0
        public void ContinueBattle_ShouldContinue()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(combatant2);
            combatants.Add(combatant3);

            Battle battleClass = new Battle();

            // act
            bool continueBattle = battleClass.ContinueBattle(combatants);

            // assert
            Assert.IsTrue(continueBattle, "ContinueBattle did not continue battle when it was supposed to");
        }
Ejemplo n.º 8
0
        public void ValidateCombatants_InvalidValues_EmptyCombatantList()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();

            Battle battleClass = new Battle();

            // act
            bool validateCombatants = battleClass.ValidateCombatants(combatants);

            // assert
            Assert.IsFalse(validateCombatants, "ValidateCombatants did not validate the invalid empty combatantlist correctly");
        }
Ejemplo n.º 9
0
        public void AssignCombatantIDs_CheckValidInput()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);
            combatant1Copy.CombatantID = 0;
            combatant2Copy.CombatantID = 0;
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.AssignCombatantIDs(ref combatants);

            // assert
            List<Combatant> expected = new List<Combatant>();
            expected.Add(combatant1);
            expected.Add(combatant2);
            if (expected[0].CombatantID == combatants[0].CombatantID)
            {
                Assert.AreEqual(expected[1].CombatantID, combatants[1].CombatantID, "AssignCombatantIDs did not assign combatant IDs as expected");
                return;
            }
            Assert.Fail("AssignCombatantIDs did not assign combatant IDs as expected");
        }
Ejemplo n.º 10
0
        public void ValidateCombatants_ValidValues()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(combatant2);
            combatants.Add(combatant3);

            Battle battleClass = new Battle();

            // act
            bool validateCombatants = battleClass.ValidateCombatants(combatants);

            // assert
            Assert.IsTrue(validateCombatants, "ValidateCombatants did not validate the valid combatants correctly");
        }
Ejemplo n.º 11
0
        public void ValidateCombatants_InvalidValues_TiredCharacter()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(combatant2);
            combatants.Add(combatant3);
            combatants.Add(tiredCombatant1);

            Battle battleClass = new Battle();

            // act
            bool validateCombatants = battleClass.ValidateCombatants(combatants);

            // assert
            Assert.IsFalse(validateCombatants, "ValidateCombatants did not validate the invalid tired combatant correctly");
        }
Ejemplo n.º 12
0
        public void ContinueBattle_InvalidValues_EmptyCombatantList()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();

            Battle battleClass = new Battle();

            // act
            bool continueBattle = battleClass.ContinueBattle(combatants);

            // assert
            Assert.IsFalse(continueBattle, "ContinueBattle continued even though there were not combatants in the list");
        }
Ejemplo n.º 13
0
        public void ContinueBattle_InvalidValues_EmptyCombatant()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(new Combatant());

            Battle battleClass = new Battle();

            // act
            bool continueBattle = battleClass.ContinueBattle(combatants);
        }
Ejemplo n.º 14
0
        public void ContinueBattle_ShouldNotContinue()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant2);
            combatants.Add(combatant3);

            Battle battleClass = new Battle();

            // act
            bool continueBattle = battleClass.ContinueBattle(combatants);

            // assert
            Assert.IsFalse(continueBattle, "ContinueBattle continued even when it should not have");
        }
Ejemplo n.º 15
0
        public void CountChance_CheckNumberSameValue()
        {
            // arrange
            Battle battleClass = new Battle();

            // act
            // loop through the method 10000 times to get a good span
            int randomNumber;
            for (int i = 0; i < 10000; i++)
            {
                randomNumber = battleClass.CountChance(10,10);

                // assert
                if (randomNumber < 5 || randomNumber > 20)
                {
                    Assert.Fail("CountChance has a chance of giving the wrong number if the values sent to it match");
                    return;
                }
            }
            Assert.IsTrue(true);
        }
Ejemplo n.º 16
0
        public void CreateTurnOrder_CheckSortedTurnOrder()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            combatants.Add(combatant1);
            combatants.Add(combatant2);
            combatants.Add(combatant3);

            Battle battleClass = new Battle();

            // act
            var turnOrder = battleClass.CreateTurnOrder(combatants);
            int[] turnOrderInt = new int[3];
            int i = 0;

            // assert
            foreach (KeyValuePair<int, Combatant> pair in turnOrder)
            {
                turnOrderInt[i] = pair.Key;
                i++;
            }

            if (turnOrderInt[0] > turnOrderInt[1] && turnOrderInt[1] > turnOrderInt[2])
            {
                Assert.IsTrue(true);
                return;
            }
            Assert.Fail("CreateTurnOrder does not order the list correctly. Order: {0}, {1}, {2}", turnOrderInt[0], turnOrderInt[1], turnOrderInt[2]);
        }
Ejemplo n.º 17
0
        public void CountChance_CheckNumberFirstHigh()
        {
            // arrange
            Battle battleClass = new Battle();

            // act
            // loop through the method 10000 times to get a good span
            int randomNumber;
            for (int i = 0; i < 10000; i++)
            {
                randomNumber = battleClass.CountChance(40,10);

                // assert
                if (randomNumber < 5 || randomNumber > 25)
                {
                    Assert.Fail("CountChance has a chance of giving the wrong number if the first value sent to it is at least 1.5 times higher than the second");
                    return;
                }
            }
            Assert.IsTrue(true);
        }
Ejemplo n.º 18
0
        public void CreateTurnOrder_CheckForMultipleAttacks()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            combatant1Copy.Speed = 60;
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2);
            combatants.Add(combatant3);

            Battle battleClass = new Battle();

            // act
            var turnOrder = battleClass.CreateTurnOrder(combatants);

            int turnOrderCount = 0;
            foreach (KeyValuePair<int, Combatant> pair in turnOrder)
            {
                turnOrderCount++;
            }

            // assert
            Assert.AreEqual(4, turnOrderCount, "CreateTurnOrder does not let combatant do multiple attacks");
        }
Ejemplo n.º 19
0
        public void InitBattle_InvalidCombatants()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant deadCombatant1Copy = CopyCombatant(deadCombatant1);
            combatants.Add(combatant1Copy);
            combatants.Add(deadCombatant1Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.InitBattle(combatants);
        }
Ejemplo n.º 20
0
        public void InitBattle_TestBattleOutputCombatLog()
        {
            // NOTICE: This test only tests the output of a battle
            // For each individual part of the battle, check the other tests!

            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);

            // to prevent the battlesystem to search the database for the combatants
            combatant1Copy.UserID = null;
            combatant2Copy.UserID = null;
            combatant1Copy.CombatantID = 0;
            combatant2Copy.CombatantID = 0;

            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            try
            {
                battleClass.InitBattle(combatants);
                List<CombatLog> combatLog = battleClass.GetCombatLog();

                // print the combatlog to test output
                for (int i = 0; i < combatLog.Count; i++)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("LogEntry: {0} DefenderDamage: {1} AttackerDamage: {2}", combatLog[i].Text, combatLog[i].DefenderDamage, combatLog[i].AttackerDamage));
                }
            }
            catch (Exception ex)
            {
                // assert
                Assert.Fail("Something prohibited the battle from finishing. ErrorMsg: {0}", ex.Message);
                return;
            }
            Assert.IsTrue(true);
        }