예제 #1
0
        public void HealthEqualsAndHashCode()
        {
            Health health = new Health(100, new KillableMock(), new Armor(ArmorType.Unarmored, 10));

            //Using IsTrue/IsFalse to cover all paths (aren't covered, when using Equals)
            //Equal tests
            Assert.IsTrue(health.Equals(health));
            Assert.AreEqual(health.GetHashCode(), health.GetHashCode());

            object equal = new Health(100, new KillableMock(), new Armor(ArmorType.Unarmored, 10));
            Assert.IsTrue(health.Equals(equal));
            Assert.AreEqual(equal.GetHashCode(), health.GetHashCode());

            Killable notEqualKillable = new KillableMock();
            notEqualKillable.Kill();
            equal = new Health(100, notEqualKillable, new Armor(ArmorType.Unarmored, 10));
            Assert.IsTrue(health.Equals(equal));
            Assert.AreEqual(equal.GetHashCode(), health.GetHashCode());

            //Not equal tests
            Assert.IsFalse(health.Equals(null));

            object notEqual = new object();
            Assert.IsFalse(health.Equals(notEqual));
            Assert.AreNotEqual(notEqual.GetHashCode(), health.GetHashCode());

            notEqual = new Health(90, new KillableMock(), new Armor(ArmorType.Unarmored, 10));
            Assert.IsFalse(health.Equals(notEqual));
            Assert.AreNotEqual(notEqual.GetHashCode(), health.GetHashCode());

            notEqual = new Health(100, new KillableMock(), null);
            Assert.IsFalse(health.Equals(notEqual));
            Assert.AreNotEqual(notEqual.GetHashCode(), health.GetHashCode());
        }
예제 #2
0
        public void DoDamage()
        {
            Damage evenDamage = new Damage(DamageType.Chaos, 20, 0);
            Damage unevenDamage = new Damage(DamageType.Chaos, 25, 0);
            Damage moreThanEnoughDamage = new Damage(DamageType.Chaos, 111, 0);

            //Test health with an armor mock
            Health armoredHealth = new Health(100, new KillableMock(), new ArmorMock());

            armoredHealth.DoDamage(evenDamage);
            Assert.AreEqual<int>(100 - 10, armoredHealth.Amount);

            armoredHealth.DoDamage(unevenDamage);
            Assert.AreEqual<int>(100 - 10 - 12, armoredHealth.Amount);

            //Test health with no armor
            Health nullArmorHealth = new Health(100, new KillableMock(), null);

            nullArmorHealth.DoDamage(evenDamage);
            Assert.AreEqual<int>(100 - 20, nullArmorHealth.Amount);

            nullArmorHealth.DoDamage(unevenDamage);
            Assert.AreEqual<int>(100 - 20 - 25, nullArmorHealth.Amount);

            //Test health with no armor and try to do more damage than possible,
            //check if Health is negative
            nullArmorHealth.DoDamage(moreThanEnoughDamage);
            Assert.AreEqual<int>(0, nullArmorHealth.Amount);
        }
예제 #3
0
        public void HealthCreation()
        {
            Health health = new Health(150, new KillableMock(), new ArmorMock());
            Assert.AreEqual<int>(150, health.Amount);
            Assert.AreEqual<int>(150, health.MaxAmount);
            Assert.AreEqual<Armor>(new ArmorMock(), health.Armor);

            health = new Health(150, new KillableMock(), null);
            Assert.AreEqual<Armor>(null, health.Armor);

            try {
                health = new Health(0, new KillableMock(), new ArmorMock());
                Assert.Fail("Healthes with a negative amount aren't allowed");
            } catch (ArgumentException) {
                //Do nothing here
            }
        }
예제 #4
0
        public void Kill()
        {
            KillableMock killableMock = new KillableMock();
            Health health = new Health(100, killableMock, null);

            health.DoDamage(new Damage(DamageType.Chaos, health.Amount, 0));
            Assert.IsFalse(killableMock.alive);
        }