Exemplo n.º 1
0
        public void SiemensToElectricAdmittanceUnits()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance);
            AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance);
            AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance);
            AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance);
        }
Exemplo n.º 2
0
        public void EqualsIsImplemented()
        {
            var a = ElectricAdmittance.FromSiemens(1);
            var b = ElectricAdmittance.FromSiemens(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals(null));
        }
Exemplo n.º 3
0
        public void ConversionRoundTrip()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            AssertEx.EqualTolerance(1, ElectricAdmittance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance);
            AssertEx.EqualTolerance(1, ElectricAdmittance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance);
            AssertEx.EqualTolerance(1, ElectricAdmittance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance);
            AssertEx.EqualTolerance(1, ElectricAdmittance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance);
        }
Exemplo n.º 4
0
        public void As()
        {
            var siemens = ElectricAdmittance.FromSiemens(1);

            AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Microsiemens), MicrosiemensTolerance);
            AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Millisiemens), MillisiemensTolerance);
            AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Nanosiemens), NanosiemensTolerance);
            AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Siemens), SiemensTolerance);
        }
        public void ArithmeticOperators()
        {
            ElectricAdmittance v = ElectricAdmittance.FromSiemens(1);

            AssertEx.EqualTolerance(-1, -v.Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(2, (ElectricAdmittance.FromSiemens(3) - v).Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(2, (v + v).Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(10, (v * 10).Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(10, (10 * v).Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(2, (ElectricAdmittance.FromSiemens(10) / 5).Siemens, SiemensTolerance);
            AssertEx.EqualTolerance(2, ElectricAdmittance.FromSiemens(10) / ElectricAdmittance.FromSiemens(5), SiemensTolerance);
        }
        public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var siemens = ElectricAdmittance.FromSiemens(1);

            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.SI));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.CGS));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.BI));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.EE));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.USC));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.FPS));
            Assert.Throws <ArgumentException>(() => siemens.ToUnit(UnitSystem.Astronomical));
        }
        public void EqualityOperators()
        {
            ElectricAdmittance a = ElectricAdmittance.FromSiemens(1);
            ElectricAdmittance b = ElectricAdmittance.FromSiemens(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 As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var           quantity           = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit);
            Func <object> AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI);

            if (SupportsSIUnitSystem)
            {
                var value = (double)AsWithSIUnitSystem();
                Assert.Equal(1, value);
            }
            else
            {
                Assert.Throws <ArgumentException>(AsWithSIUnitSystem);
            }
        }
        public void ComparisonOperators()
        {
            ElectricAdmittance oneSiemens = ElectricAdmittance.FromSiemens(1);
            ElectricAdmittance twoSiemens = ElectricAdmittance.FromSiemens(2);

            Assert.True(oneSiemens < twoSiemens);
            Assert.True(oneSiemens <= twoSiemens);
            Assert.True(twoSiemens > oneSiemens);
            Assert.True(twoSiemens >= oneSiemens);

            Assert.False(oneSiemens > twoSiemens);
            Assert.False(oneSiemens >= twoSiemens);
            Assert.False(twoSiemens < oneSiemens);
            Assert.False(twoSiemens <= oneSiemens);
        }
        public void ElectricAdmittance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
        {
            var quantity = new ElectricAdmittance(1, ElectricAdmittanceUnit.Siemens);

            QuantityInfo <ElectricAdmittanceUnit> quantityInfo = quantity.QuantityInfo;

            Assert.Equal(ElectricAdmittance.Zero, quantityInfo.Zero);
            Assert.Equal("ElectricAdmittance", quantityInfo.Name);
            Assert.Equal(QuantityType.ElectricAdmittance, quantityInfo.QuantityType);

            var units     = EnumUtils.GetEnumValues <ElectricAdmittanceUnit>().Except(new[] { ElectricAdmittanceUnit.Undefined }).ToArray();
            var unitNames = units.Select(x => x.ToString());

            // Obsolete members
            Assert.Equal(units, quantityInfo.Units);
            Assert.Equal(unitNames, quantityInfo.UnitNames);
        }
        public void EqualityOperators()
        {
            var a = ElectricAdmittance.FromSiemens(1);
            var b = ElectricAdmittance.FromSiemens(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
        }
Exemplo n.º 12
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Microsiemens);

            AssertEx.EqualTolerance(1, quantity00.Microsiemens, MicrosiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Microsiemens, quantity00.Unit);

            var quantity01 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millisiemens);

            AssertEx.EqualTolerance(1, quantity01.Millisiemens, MillisiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Millisiemens, quantity01.Unit);

            var quantity02 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanosiemens);

            AssertEx.EqualTolerance(1, quantity02.Nanosiemens, NanosiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, quantity02.Unit);

            var quantity03 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Siemens);

            AssertEx.EqualTolerance(1, quantity03.Siemens, SiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Siemens, quantity03.Unit);
        }
Exemplo n.º 13
0
        public void ToUnit()
        {
            var siemens = ElectricAdmittance.FromSiemens(1);

            var microsiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Microsiemens);

            AssertEx.EqualTolerance(MicrosiemensInOneSiemens, (double)microsiemensQuantity.Value, MicrosiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Microsiemens, microsiemensQuantity.Unit);

            var millisiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Millisiemens);

            AssertEx.EqualTolerance(MillisiemensInOneSiemens, (double)millisiemensQuantity.Value, MillisiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Millisiemens, millisiemensQuantity.Unit);

            var nanosiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Nanosiemens);

            AssertEx.EqualTolerance(NanosiemensInOneSiemens, (double)nanosiemensQuantity.Value, NanosiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, nanosiemensQuantity.Unit);

            var siemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Siemens);

            AssertEx.EqualTolerance(SiemensInOneSiemens, (double)siemensQuantity.Value, SiemensTolerance);
            Assert.Equal(ElectricAdmittanceUnit.Siemens, siemensQuantity.Unit);
        }
Exemplo n.º 14
0
 public void FromSiemens_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => ElectricAdmittance.FromSiemens(double.NaN));
 }
Exemplo n.º 15
0
 public void FromSiemens_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => ElectricAdmittance.FromSiemens(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => ElectricAdmittance.FromSiemens(double.NegativeInfinity));
 }
 /// <inheritdoc cref="ElectricAdmittance.FromSiemens(UnitsNet.QuantityValue)" />
 public static ElectricAdmittance Siemens <T>(this T value) =>
 ElectricAdmittance.FromSiemens(Convert.ToDouble(value));
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = ElectricAdmittance.FromSiemens(1.0);

            Assert.Equal(QuantityType.ElectricAdmittance, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
 public void NumberToMillisiemensTest() =>
 Assert.Equal(ElectricAdmittance.FromMillisiemens(2), 2.Millisiemens());
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = ElectricAdmittance.FromSiemens(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricAdmittance)));
        }
Exemplo n.º 20
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            Assert.False(siemens.Equals(new object()));
        }
Exemplo n.º 21
0
        public void CompareToThrowsOnTypeMismatch()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            Assert.Throws <ArgumentException>(() => siemens.CompareTo(new object()));
        }
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = ElectricAdmittance.FromSiemens(1.0);

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

            Assert.Equal(ElectricAdmittance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
 public void NumberToSiemensTest() =>
 Assert.Equal(ElectricAdmittance.FromSiemens(2), 2.Siemens());
        public void GetHashCode_Equals()
        {
            var quantity = ElectricAdmittance.FromSiemens(1.0);

            Assert.Equal(new { ElectricAdmittance.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = ElectricAdmittance.FromSiemens(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricAdmittanceUnit)));
        }
Exemplo n.º 27
0
        public void CompareToThrowsOnNull()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            Assert.Throws <ArgumentNullException>(() => siemens.CompareTo(null));
        }
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = ElectricAdmittance.FromSiemens(value);

            Assert.Equal(ElectricAdmittance.FromSiemens(-value), -quantity);
        }
Exemplo n.º 29
0
        public void EqualsReturnsFalseOnNull()
        {
            ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);

            Assert.False(siemens.Equals(null));
        }
        public void Ctor_WithNaNValue_CreateQuantityAndAffectNaNValue()
        {
            var nanQuantity = new ElectricAdmittance(double.NaN, ElectricAdmittanceUnit.Siemens);

            Assert.True(double.IsNaN(nanQuantity.Value));
        }