コード例 #1
0
        public void EqualsRelativeToleranceIsImplemented()
        {
            var v = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.True(v.Equals(ElectricCurrentGradient.FromAmperesPerSecond(1), AmperesPerSecondTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(ElectricCurrentGradient.Zero, AmperesPerSecondTolerance, ComparisonType.Relative));
        }
コード例 #2
0
 public void CompareToIsImplemented()
 {
     ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);
     Assert.Equal(0, amperepersecond.CompareTo(amperepersecond));
     Assert.True(amperepersecond.CompareTo(ElectricCurrentGradient.Zero) > 0);
     Assert.True(ElectricCurrentGradient.Zero.CompareTo(amperepersecond) < 0);
 }
コード例 #3
0
        public void EqualsIsImplemented()
        {
            ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.True(v.Equals(ElectricCurrentGradient.FromAmperesPerSecond(1), ElectricCurrentGradient.FromAmperesPerSecond(AmperesPerSecondTolerance)));
            Assert.False(v.Equals(ElectricCurrentGradient.Zero, ElectricCurrentGradient.FromAmperesPerSecond(AmperesPerSecondTolerance)));
        }
コード例 #4
0
        public void Equals_SameType_IsImplemented()
        {
            var a = ElectricCurrentGradient.FromAmperesPerSecond(1);
            var b = ElectricCurrentGradient.FromAmperesPerSecond(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
コード例 #5
0
 public void ConversionRoundTrip()
 {
     ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);
     AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerMicrosecond(amperepersecond.AmperesPerMicrosecond).AmperesPerSecond, AmperesPerMicrosecondTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerMillisecond(amperepersecond.AmperesPerMillisecond).AmperesPerSecond, AmperesPerMillisecondTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerNanosecond(amperepersecond.AmperesPerNanosecond).AmperesPerSecond, AmperesPerNanosecondTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerSecond(amperepersecond.AmperesPerSecond).AmperesPerSecond, AmperesPerSecondTolerance);
 }
コード例 #6
0
 public void As()
 {
     var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);
     AssertEx.EqualTolerance(AmperesPerMicrosecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerMicrosecond), AmperesPerMicrosecondTolerance);
     AssertEx.EqualTolerance(AmperesPerMillisecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerMillisecond), AmperesPerMillisecondTolerance);
     AssertEx.EqualTolerance(AmperesPerNanosecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerNanosecond), AmperesPerNanosecondTolerance);
     AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerSecond), AmperesPerSecondTolerance);
 }
コード例 #7
0
        public void FromAmperesPerSecond_WithInfinityValue_CreateQuantityAndAffectInfinityValue()
        {
            var positiveInfinityQuantity = ElectricCurrentGradient.FromAmperesPerSecond(double.PositiveInfinity);
            var negativeInfinityQuantity = ElectricCurrentGradient.FromAmperesPerSecond(double.NegativeInfinity);

            Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value));
            Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value));
        }
コード例 #8
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = ElectricCurrentGradient.FromAmperesPerSecond(1);
            object b = ElectricCurrentGradient.FromAmperesPerSecond(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
コード例 #9
0
        public void ToUnit()
        {
            var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            var amperepersecondQuantity = amperepersecond.ToUnit(ElectricCurrentGradientUnit.AmperePerSecond);

            AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, (double)amperepersecondQuantity.Value, AmperesPerSecondTolerance);
            Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, amperepersecondQuantity.Unit);
        }
コード例 #10
0
ファイル: Axp192.cs プロジェクト: mmalyska/iot
        /// <summary>
        /// Gets Coulomb
        /// </summary>
        /// <returns>typical values are in mA per hour</returns>
        public ElectricCurrentGradient GetCoulomb()
        {
            uint coin           = GetCoulombCharge();
            uint coout          = GetCoulombDischarge();
            uint valueDifferent = 0;
            bool bIsNegative    = false;

            if (coin > coout)
            {
                // Expected, in always more then out
                valueDifferent = coin - coout;
            }
            else
            {
                // Warning: Out is more than In, the battery is not started at 0%
                // just Flip the output sign later
                bIsNegative    = true;
                valueDifferent = coout - coin;
            }

            // c = 65536 * current_LSB * (coin - coout) / 3600 / ADC rate
            // Adc rate can be read from 84H, change this variable if you change the ADC reate
            double adcDiv;

            switch (AdcFrequency)
            {
            case AdcFrequency.Frequency25Hz:
                adcDiv = 25.0;
                break;

            case AdcFrequency.Frequency50Hz:
                adcDiv = 50.0;
                break;

            case AdcFrequency.Frequency100Hz:
                adcDiv = 100.0;
                break;

            default:
            case AdcFrequency.Frequency200Hz:
                adcDiv = 200.0;
                break;
            }

            double ccc = (65536 * 0.5 * valueDifferent) / 3600.0 / adcDiv;  // Note the ADC has defaulted to be 200 Hz

            if (bIsNegative)
            {
                ccc = 0.0 - ccc;    // Flip it back to negative
            }

            // ccc is in the mA per hour.
            return(ElectricCurrentGradient.FromAmperesPerSecond(ccc * 3.6));
        }
コード例 #11
0
 public void ArithmeticOperators()
 {
     ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1);
     AssertEx.EqualTolerance(-1, -v.AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(3)-v).AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(2, (v + v).AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(10, (v*10).AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(10, (10*v).AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(10)/5).AmperesPerSecond, AmperesPerSecondTolerance);
     AssertEx.EqualTolerance(2, ElectricCurrentGradient.FromAmperesPerSecond(10)/ElectricCurrentGradient.FromAmperesPerSecond(5), AmperesPerSecondTolerance);
 }
コード例 #12
0
        public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.SI));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.CGS));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.BI));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.EE));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.USC));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.FPS));
            Assert.Throws<ArgumentException>(() => amperepersecond.ToUnit(UnitSystem.Astronomical));
        }
コード例 #13
0
        public void EqualityOperators()
        {
            ElectricCurrentGradient a = ElectricCurrentGradient.FromAmperesPerSecond(1);
            ElectricCurrentGradient b = ElectricCurrentGradient.FromAmperesPerSecond(2);

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

            Assert.False(a == b);
            Assert.False(a != a);
// ReSharper restore EqualExpressionComparison
        }
コード例 #14
0
        public void ComparisonOperators()
        {
            ElectricCurrentGradient oneAmperePerSecond  = ElectricCurrentGradient.FromAmperesPerSecond(1);
            ElectricCurrentGradient twoAmperesPerSecond = ElectricCurrentGradient.FromAmperesPerSecond(2);

            Assert.True(oneAmperePerSecond < twoAmperesPerSecond);
            Assert.True(oneAmperePerSecond <= twoAmperesPerSecond);
            Assert.True(twoAmperesPerSecond > oneAmperePerSecond);
            Assert.True(twoAmperesPerSecond >= oneAmperePerSecond);

            Assert.False(oneAmperePerSecond > twoAmperesPerSecond);
            Assert.False(oneAmperePerSecond >= twoAmperesPerSecond);
            Assert.False(twoAmperesPerSecond < oneAmperePerSecond);
            Assert.False(twoAmperesPerSecond <= oneAmperePerSecond);
        }
コード例 #15
0
        public void EqualityOperators()
        {
            var a = ElectricCurrentGradient.FromAmperesPerSecond(1);
            var b = ElectricCurrentGradient.FromAmperesPerSecond(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
        }
コード例 #16
0
 public void Convert_ToString_EqualsToString()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
 }
コード例 #17
0
        public void CompareToThrowsOnNull()
        {
            ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.Throws <ArgumentNullException>(() => amperepersecond.CompareTo(null));
        }
コード例 #18
0
        public void CompareToThrowsOnTypeMismatch()
        {
            ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.Throws <ArgumentException>(() => amperepersecond.CompareTo(new object()));
        }
コード例 #19
0
 public void Convert_ToDecimal_EqualsValueAsSameType()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
 }
コード例 #20
0
 public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(value);
     Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(-value), -quantity);
 }
コード例 #21
0
 public void GetHashCode_Equals()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal(new {ElectricCurrentGradient.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode());
 }
コード例 #22
0
 public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Throws<InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
 }
コード例 #23
0
 public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal(ElectricCurrentGradient.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
 }
コード例 #24
0
 public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal(ElectricCurrentGradient.Info, Convert.ChangeType(quantity, typeof(QuantityInfo)));
 }
コード例 #25
0
        public void EqualsReturnsFalseOnNull()
        {
            ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.False(amperepersecond.Equals(null));
        }
コード例 #26
0
 public void Convert_ToSingle_EqualsValueAsSameType()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
 }
コード例 #27
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            Assert.False(amperepersecond.Equals(new object()));
        }
コード例 #28
0
 public void Convert_ToUInt64_EqualsValueAsSameType()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
 }
コード例 #29
0
        public void AmperePerSecondToElectricCurrentGradientUnits()
        {
            ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1);

            AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.AmperesPerSecond, AmperesPerSecondTolerance);
        }
コード例 #30
0
 public void Convert_ChangeType_UnitType_EqualsUnit()
 {
     var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0);
     Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricCurrentGradientUnit)));
 }