Beispiel #1
0
        public void EqualsIsImplemented()
        {
            Energy v = Energy.FromJoules(1);

            Assert.True(v.Equals(Energy.FromJoules(1)));
            Assert.False(v.Equals(Energy.Zero));
        }
 public void OpEquals()
 {
     var energy1 = new Energy(2000, EnergyUnit.NewtonMeters);
     var energy2 = new Energy(2, EnergyUnit.Kilojoules);
     var energy3 = new Energy(4000, EnergyUnit.Joules);
     (energy1 == energy2).ShouldBeTrue();
     (energy2 == energy1).ShouldBeTrue();
     (energy1 == energy3).ShouldBeFalse();
     (energy3 == energy1).ShouldBeFalse();
     energy1.Equals(energy2)
            .ShouldBeTrue();
     energy1.Equals((object)energy2)
            .ShouldBeTrue();
     energy2.Equals(energy1)
            .ShouldBeTrue();
     energy2.Equals((object)energy1)
            .ShouldBeTrue();
 }
Beispiel #3
0
        public void EqualsObjectTest()
        {
            Energy target   = new Energy(10F);
            object obj      = new Energy(10F);
            bool   expected = true;
            bool   actual;

            actual = target.Equals(obj);
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void EqualsDoubleTest()
        {
            Energy target   = new Energy(10F);
            double obj      = 10F;
            bool   expected = false;
            bool   actual;

            actual = target.Equals(obj);
            Assert.AreEqual(expected, actual);
        }
            public void ZeroUnitsEnergy_ShouldBeEqualToZeroJoules()
            {
                // arrange
                var zeroJoulesEnergy = new Energy(Constants.Zero);
                var zeroUnitsEnergy  = new Energy(Constants.Zero, CreateUnitOtherThan(EnergyUnit.Joule));

                // act
                // assert
                zeroJoulesEnergy.Equals(zeroUnitsEnergy).Should().BeTrue(because: "'new Energy(Constants.Zero)' should be equal 'new Energy(Constants.Zero, SomeUnit)'");
                zeroUnitsEnergy.Equals(zeroJoulesEnergy).Should().BeTrue(because: "'new Energy(Constants.Zero, SomeUnit)' should be equal 'new Energy(Constants.Zero)'");
            }
            public void EnergyCreateUsingParamlessConstructor_ShouldBeEqualToZeroJoules()
            {
                // arrange
                var zeroJoulesEnergy           = new Energy(Constants.Zero);
                var paramlessConstructedEnergy = new Energy();

                // act
                // assert
                zeroJoulesEnergy.Equals(paramlessConstructedEnergy).Should().BeTrue(because: "'new Energy(Constants.Zero)' should be equal 'new Energy()'");
                paramlessConstructedEnergy.Equals(zeroJoulesEnergy).Should().BeTrue(because: "'new Energy()' should be equal 'new Energy(Constants.Zero)'");
            }
            public void DefaultEnergy_ShouldBeEqualToZeroJoules()
            {
                // arrange
                var defaultEnergy    = default(Energy);
                var zeroJoulesEnergy = new Energy(Constants.Zero);

                // act
                // assert
                zeroJoulesEnergy.Equals(defaultEnergy).Should().BeTrue(because: "'new Energy(Constants.Zero)' should be equal 'default(Energy)'");
                defaultEnergy.Equals(zeroJoulesEnergy).Should().BeTrue(because: "'default(Energy)' should be equal 'new Energy(Constants.Zero)'");
            }
            public void EnergysConvertedToDifferentUnitsEqualInJoules_ShouldBeEqual()
            {
                // arrange
                var energy1 = new Energy(Fixture.Create <number>()).Convert(Fixture.Create <EnergyUnit>());
                var energy2 = new Energy(energy1.Joules).Convert(CreateUnitOtherThan(energy1.Unit));

                // act
                bool equalsResult = energy1.Equals(energy2);

                // assert
                equalsResult.Should().BeTrue();
            }
Beispiel #9
0
        public void EqualsReturnsFalseOnNull()
        {
            Energy joule = Energy.FromJoules(1);

            Assert.False(joule.Equals(null));
        }
Beispiel #10
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            Energy joule = Energy.FromJoules(1);

            Assert.False(joule.Equals(new object()));
        }
Beispiel #11
0
 public void EqualsObjectTest()
 {
     Energy target = new Energy(10F);
     object obj = new Energy(10F);
     bool expected = true;
     bool actual;
     actual = target.Equals(obj);
     Assert.AreEqual(expected, actual);
 }
Beispiel #12
0
 public void EqualsDoubleTest()
 {
     Energy target = new Energy(10F);
     double obj = 10F;
     bool expected = false;
     bool actual;
     actual = target.Equals(obj);
     Assert.AreEqual(expected, actual);
 }