Exemple #1
0
        public void EqualsAndHash()
        {
            Cylinder cylinder = new Cylinder(1, 2);
            Cylinder same     = new Cylinder(1, 2);
            Cylinder diff     = new Cylinder(7, 7);

            Assert.IsTrue(cylinder.Equals(cylinder));
            Assert.IsFalse(cylinder.Equals(null));
            Assert.IsTrue(cylinder.Equals(same));
            Assert.IsTrue(same.Equals(cylinder));
            Assert.IsFalse(cylinder.Equals(diff));
            Assert.AreEqual(cylinder.GetHashCode(), same.GetHashCode());
            Assert.AreNotEqual(cylinder.GetHashCode(), diff.GetHashCode());
        }
Exemple #2
0
        public void Cylinder_Equality()
        {
            var same      = new Cylinder(1.Meters(), 3.Meters());
            var different = new Cylinder(2.Meters(), 3.Meters());

            Assert.Multiple(() =>
            {
                Assert.IsTrue(same == this.cylinder, "Objects should be equal");
                Assert.IsTrue(same.Equals(this.cylinder), "Objects should be equal");
                Assert.IsTrue(different != this.cylinder, "Objects should be different");
                Assert.IsFalse(different == this.cylinder, "Objects should be different");
                Assert.IsFalse(different.Equals(this.cylinder), "Objects should be different");
            });
        }