Пример #1
0
        public void EqualsAndHash()
        {
            Inertia inertia = new Inertia(1, 2, 3, 4, 5, 6);
            Inertia same    = new Inertia(1, 2, 3, 4, 5, 6);
            Inertia diff    = new Inertia(7, 7, 7, 7, 7, 7);

            Assert.IsTrue(inertia.Equals(inertia));
            Assert.IsFalse(inertia.Equals(null));
            Assert.IsTrue(inertia.Equals(same));
            Assert.IsTrue(same.Equals(inertia));
            Assert.IsFalse(inertia.Equals(diff));
            Assert.AreEqual(inertia.GetHashCode(), same.GetHashCode());
            Assert.AreNotEqual(inertia.GetHashCode(), diff.GetHashCode());
        }
Пример #2
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>The int</returns>
        public override int GetHashCode()
        {
            int result = Area.GetHashCode();

            result = (result * 397) ^ Centroid.GetHashCode();
            result = (result * 397) ^ Inertia.GetHashCode();
            result = (result * 397) ^ Mass.GetHashCode();
            return(result);
        }