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()); }
private bool Equals(KillableMock other) { return alive.Equals(other.alive); }
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); }