public void ToUnit()
        {
            var coulomb = ElectricCharge.FromCoulombs(1);

            var amperehourQuantity = coulomb.ToUnit(ElectricChargeUnit.AmpereHour);

            AssertEx.EqualTolerance(AmpereHoursInOneCoulomb, (double)amperehourQuantity.Value, AmpereHoursTolerance);
            Assert.Equal(ElectricChargeUnit.AmpereHour, amperehourQuantity.Unit);

            var coulombQuantity = coulomb.ToUnit(ElectricChargeUnit.Coulomb);

            AssertEx.EqualTolerance(CoulombsInOneCoulomb, (double)coulombQuantity.Value, CoulombsTolerance);
            Assert.Equal(ElectricChargeUnit.Coulomb, coulombQuantity.Unit);

            var kiloamperehourQuantity = coulomb.ToUnit(ElectricChargeUnit.KiloampereHour);

            AssertEx.EqualTolerance(KiloampereHoursInOneCoulomb, (double)kiloamperehourQuantity.Value, KiloampereHoursTolerance);
            Assert.Equal(ElectricChargeUnit.KiloampereHour, kiloamperehourQuantity.Unit);

            var megaamperehourQuantity = coulomb.ToUnit(ElectricChargeUnit.MegaampereHour);

            AssertEx.EqualTolerance(MegaampereHoursInOneCoulomb, (double)megaamperehourQuantity.Value, MegaampereHoursTolerance);
            Assert.Equal(ElectricChargeUnit.MegaampereHour, megaamperehourQuantity.Unit);

            var milliamperehourQuantity = coulomb.ToUnit(ElectricChargeUnit.MilliampereHour);

            AssertEx.EqualTolerance(MilliampereHoursInOneCoulomb, (double)milliamperehourQuantity.Value, MilliampereHoursTolerance);
            Assert.Equal(ElectricChargeUnit.MilliampereHour, milliamperehourQuantity.Unit);
        }
示例#2
0
        public void EqualsIsImplemented()
        {
            ElectricCharge v = ElectricCharge.FromCoulombs(1);

            Assert.True(v.Equals(ElectricCharge.FromCoulombs(1), ElectricCharge.FromCoulombs(CoulombsTolerance)));
            Assert.False(v.Equals(ElectricCharge.Zero, ElectricCharge.FromCoulombs(CoulombsTolerance)));
        }
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = ElectricCharge.FromCoulombs(1);

            Assert.True(v.Equals(ElectricCharge.FromCoulombs(1), CoulombsTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(ElectricCharge.Zero, CoulombsTolerance, ComparisonType.Relative));
        }
        public void Equals_SameType_IsImplemented()
        {
            var a = ElectricCharge.FromCoulombs(1);
            var b = ElectricCharge.FromCoulombs(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
        public void CompareToIsImplemented()
        {
            ElectricCharge coulomb = ElectricCharge.FromCoulombs(1);

            Assert.Equal(0, coulomb.CompareTo(coulomb));
            Assert.True(coulomb.CompareTo(ElectricCharge.Zero) > 0);
            Assert.True(ElectricCharge.Zero.CompareTo(coulomb) < 0);
        }
        public void FromCoulombs_WithInfinityValue_CreateQuantityAndAffectInfinityValue()
        {
            var positiveInfinityQuantity = ElectricCharge.FromCoulombs(double.PositiveInfinity);
            var negativeInfinityQuantity = ElectricCharge.FromCoulombs(double.NegativeInfinity);

            Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value));
            Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value));
        }
示例#7
0
        public void ToUnit()
        {
            var coulomb = ElectricCharge.FromCoulombs(1);

            var coulombQuantity = coulomb.ToUnit(ElectricChargeUnit.Coulomb);

            AssertEx.EqualTolerance(CoulombsInOneCoulomb, (double)coulombQuantity.Value, CoulombsTolerance);
            Assert.Equal(ElectricChargeUnit.Coulomb, coulombQuantity.Unit);
        }
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = ElectricCharge.FromCoulombs(1);
            object b = ElectricCharge.FromCoulombs(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
        public void ConversionRoundTrip()
        {
            ElectricCharge coulomb = ElectricCharge.FromCoulombs(1);

            AssertEx.EqualTolerance(1, ElectricCharge.FromAmpereHours(coulomb.AmpereHours).Coulombs, AmpereHoursTolerance);
            AssertEx.EqualTolerance(1, ElectricCharge.FromCoulombs(coulomb.Coulombs).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(1, ElectricCharge.FromKiloampereHours(coulomb.KiloampereHours).Coulombs, KiloampereHoursTolerance);
            AssertEx.EqualTolerance(1, ElectricCharge.FromMegaampereHours(coulomb.MegaampereHours).Coulombs, MegaampereHoursTolerance);
            AssertEx.EqualTolerance(1, ElectricCharge.FromMilliampereHours(coulomb.MilliampereHours).Coulombs, MilliampereHoursTolerance);
        }
        public void As()
        {
            var coulomb = ElectricCharge.FromCoulombs(1);

            AssertEx.EqualTolerance(AmpereHoursInOneCoulomb, coulomb.As(ElectricChargeUnit.AmpereHour), AmpereHoursTolerance);
            AssertEx.EqualTolerance(CoulombsInOneCoulomb, coulomb.As(ElectricChargeUnit.Coulomb), CoulombsTolerance);
            AssertEx.EqualTolerance(KiloampereHoursInOneCoulomb, coulomb.As(ElectricChargeUnit.KiloampereHour), KiloampereHoursTolerance);
            AssertEx.EqualTolerance(MegaampereHoursInOneCoulomb, coulomb.As(ElectricChargeUnit.MegaampereHour), MegaampereHoursTolerance);
            AssertEx.EqualTolerance(MilliampereHoursInOneCoulomb, coulomb.As(ElectricChargeUnit.MilliampereHour), MilliampereHoursTolerance);
        }
        public void CoulombToElectricChargeUnits()
        {
            ElectricCharge coulomb = ElectricCharge.FromCoulombs(1);

            AssertEx.EqualTolerance(AmpereHoursInOneCoulomb, coulomb.AmpereHours, AmpereHoursTolerance);
            AssertEx.EqualTolerance(CoulombsInOneCoulomb, coulomb.Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(KiloampereHoursInOneCoulomb, coulomb.KiloampereHours, KiloampereHoursTolerance);
            AssertEx.EqualTolerance(MegaampereHoursInOneCoulomb, coulomb.MegaampereHours, MegaampereHoursTolerance);
            AssertEx.EqualTolerance(MilliampereHoursInOneCoulomb, coulomb.MilliampereHours, MilliampereHoursTolerance);
        }
        public void ArithmeticOperators()
        {
            ElectricCharge v = ElectricCharge.FromCoulombs(1);

            AssertEx.EqualTolerance(-1, -v.Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(2, (ElectricCharge.FromCoulombs(3) - v).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(2, (v + v).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(10, (v * 10).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(10, (10 * v).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(2, (ElectricCharge.FromCoulombs(10) / 5).Coulombs, CoulombsTolerance);
            AssertEx.EqualTolerance(2, ElectricCharge.FromCoulombs(10) / ElectricCharge.FromCoulombs(5), CoulombsTolerance);
        }
        public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var coulomb = ElectricCharge.FromCoulombs(1);

            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.SI));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.CGS));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.BI));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.EE));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.USC));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.FPS));
            Assert.Throws <ArgumentException>(() => coulomb.ToUnit(UnitSystem.Astronomical));
        }
示例#14
0
        public void EqualityOperators()
        {
            ElectricCharge a = ElectricCharge.FromCoulombs(1);
            ElectricCharge b = ElectricCharge.FromCoulombs(2);

// ReSharper disable EqualExpressionComparison
            Assert.True(a == a);
            Assert.True(a != b);

            Assert.False(a == b);
            Assert.False(a != a);
// ReSharper restore EqualExpressionComparison
        }
        public void ComparisonOperators()
        {
            ElectricCharge oneCoulomb  = ElectricCharge.FromCoulombs(1);
            ElectricCharge twoCoulombs = ElectricCharge.FromCoulombs(2);

            Assert.True(oneCoulomb < twoCoulombs);
            Assert.True(oneCoulomb <= twoCoulombs);
            Assert.True(twoCoulombs > oneCoulomb);
            Assert.True(twoCoulombs >= oneCoulomb);

            Assert.False(oneCoulomb > twoCoulombs);
            Assert.False(oneCoulomb >= twoCoulombs);
            Assert.False(twoCoulombs < oneCoulomb);
            Assert.False(twoCoulombs <= oneCoulomb);
        }
示例#16
0
        private ElectricCharge ReadAccumulatedCharge()
        {
            float f_accumulatedCharge = 0.0f;
            int   accumulatedChargeADCCode;

            byte[] result = this.ReadRegisterByte(LTC2943_Constants.ACC_CHARGE_MSB, 2, true);

            if (result == null)
            {
                Console.WriteLine("Read from accumulated register failed.");
                return(ElectricCharge.Zero);
            }

            accumulatedChargeADCCode = result[0] * 256 + result[1];
            Console.WriteLine(string.Format("Read from accumulated register: {0}-{1}", result[0], result[1]));
            f_accumulatedCharge = CalculateAccumulatedChargeFromADCCode(accumulatedChargeADCCode);

            return(ElectricCharge.FromCoulombs(f_accumulatedCharge * 3.6f));
        }
示例#17
0
        public void EqualityOperators()
        {
            var a = ElectricCharge.FromCoulombs(1);
            var b = ElectricCharge.FromCoulombs(2);

#pragma warning disable CS8073
// ReSharper disable EqualExpressionComparison

            Assert.True(a == a);
            Assert.False(a != a);

            Assert.True(a != b);
            Assert.False(a == b);

            Assert.False(a == null);
            Assert.False(null == a);

// ReSharper restore EqualExpressionComparison
#pragma warning restore CS8073
        }
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = ElectricCharge.FromCoulombs(value);

            Assert.Equal(ElectricCharge.FromCoulombs(-value), -quantity);
        }
        public void GetHashCode_Equals()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(new { ElectricCharge.Info.Name, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(ElectricCharge.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
        public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(ElectricCharge.Info, Convert.ChangeType(quantity, typeof(QuantityInfo)));
        }
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(QuantityType.ElectricCharge, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricChargeUnit)));
        }
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricCharge)));
        }
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
        public void Convert_ToString_EqualsToString()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
        public void Convert_ToInt32_EqualsValueAsSameType()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity));
        }
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = ElectricCharge.FromCoulombs(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }