public void ToUnit() { var ohm = ElectricResistance.FromOhms(1); var gigaohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Gigaohm); AssertEx.EqualTolerance(GigaohmsInOneOhm, (double)gigaohmQuantity.Value, GigaohmsTolerance); Assert.Equal(ElectricResistanceUnit.Gigaohm, gigaohmQuantity.Unit); var kiloohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Kiloohm); AssertEx.EqualTolerance(KiloohmsInOneOhm, (double)kiloohmQuantity.Value, KiloohmsTolerance); Assert.Equal(ElectricResistanceUnit.Kiloohm, kiloohmQuantity.Unit); var megaohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Megaohm); AssertEx.EqualTolerance(MegaohmsInOneOhm, (double)megaohmQuantity.Value, MegaohmsTolerance); Assert.Equal(ElectricResistanceUnit.Megaohm, megaohmQuantity.Unit); var microohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Microohm); AssertEx.EqualTolerance(MicroohmsInOneOhm, (double)microohmQuantity.Value, MicroohmsTolerance); Assert.Equal(ElectricResistanceUnit.Microohm, microohmQuantity.Unit); var milliohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Milliohm); AssertEx.EqualTolerance(MilliohmsInOneOhm, (double)milliohmQuantity.Value, MilliohmsTolerance); Assert.Equal(ElectricResistanceUnit.Milliohm, milliohmQuantity.Unit); var ohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Ohm); AssertEx.EqualTolerance(OhmsInOneOhm, (double)ohmQuantity.Value, OhmsTolerance); Assert.Equal(ElectricResistanceUnit.Ohm, ohmQuantity.Unit); }
public void EqualsIsImplemented() { ElectricResistance v = ElectricResistance.FromOhms(1); Assert.True(v.Equals(ElectricResistance.FromOhms(1), ElectricResistance.FromOhms(OhmsTolerance))); Assert.False(v.Equals(ElectricResistance.Zero, ElectricResistance.FromOhms(OhmsTolerance))); }
public void Equals_RelativeTolerance_IsImplemented() { var v = ElectricResistance.FromOhms(1); Assert.True(v.Equals(ElectricResistance.FromOhms(1), OhmsTolerance, ComparisonType.Relative)); Assert.False(v.Equals(ElectricResistance.Zero, OhmsTolerance, ComparisonType.Relative)); }
public void EqualsIsImplemented() { ElectricResistance v = ElectricResistance.FromOhms(1); Assert.IsTrue(v.Equals(ElectricResistance.FromOhms(1))); Assert.IsFalse(v.Equals(ElectricResistance.Zero)); }
public void CompareToThrowsOnNull() { ElectricResistance ohm = ElectricResistance.FromOhms(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed ohm.CompareTo(null); }
public void CompareToThrowsOnTypeMismatch() { ElectricResistance ohm = ElectricResistance.FromOhms(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed ohm.CompareTo(new object()); }
public void CompareToIsImplemented() { ElectricResistance ohm = ElectricResistance.FromOhms(1); Assert.Equal(0, ohm.CompareTo(ohm)); Assert.True(ohm.CompareTo(ElectricResistance.Zero) > 0); Assert.True(ElectricResistance.Zero.CompareTo(ohm) < 0); }
public void ConversionRoundTrip() { ElectricResistance ohm = ElectricResistance.FromOhms(1); Assert.AreEqual(1, ElectricResistance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance); Assert.AreEqual(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); Assert.AreEqual(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); }
public void As() { var ohm = ElectricResistance.FromOhms(1); Assert.AreEqual(KiloohmsInOneOhm, ohm.As(ElectricResistanceUnit.Kiloohm), KiloohmsTolerance); Assert.AreEqual(MegaohmsInOneOhm, ohm.As(ElectricResistanceUnit.Megaohm), MegaohmsTolerance); Assert.AreEqual(OhmsInOneOhm, ohm.As(ElectricResistanceUnit.Ohm), OhmsTolerance); }
public void OhmToElectricResistanceUnits() { ElectricResistance ohm = ElectricResistance.FromOhms(1); Assert.AreEqual(KiloohmsInOneOhm, ohm.Kiloohms, KiloohmsTolerance); Assert.AreEqual(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); Assert.AreEqual(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); }
public void CompareToIsImplemented() { ElectricResistance ohm = ElectricResistance.FromOhms(1); Assert.AreEqual(0, ohm.CompareTo(ohm)); Assert.Greater(ohm.CompareTo(ElectricResistance.Zero), 0); Assert.Less(ElectricResistance.Zero.CompareTo(ohm), 0); }
public void PowerRatioToAmplitudeRatio_75OhmImpedance(double dBmW, double expected) { PowerRatio powerRatio = PowerRatio.FromDecibelMilliwatts(dBmW); double actual = Math.Round(powerRatio.ToAmplitudeRatio(ElectricResistance.FromOhms(75)).DecibelMillivolts, 2); Assert.Equal(expected, actual); }
public void AmplitudeRatioToPowerRatio_50OhmImpedance(double dBmV, double expected) { AmplitudeRatio ampRatio = AmplitudeRatio.FromDecibelMillivolts(dBmV); double actual = Math.Round(ampRatio.ToPowerRatio(ElectricResistance.FromOhms(50)).DecibelMilliwatts, 2); Assert.Equal(expected, actual); }
public void Equals_SameType_IsImplemented() { var a = ElectricResistance.FromOhms(1); var b = ElectricResistance.FromOhms(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
public void FromOhms_WithInfinityValue_CreateQuantityAndAffectInfinityValue() { var positiveInfinityQuantity = ElectricResistance.FromOhms(double.PositiveInfinity); var negativeInfinityQuantity = ElectricResistance.FromOhms(double.NegativeInfinity); Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value)); Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value)); }
public void Equals_QuantityAsObject_IsImplemented() { object a = ElectricResistance.FromOhms(1); object b = ElectricResistance.FromOhms(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); Assert.False(a.Equals((object)null)); }
public void OhmToElectricResistanceUnits() { ElectricResistance ohm = ElectricResistance.FromOhms(1); AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.Kiloohms, KiloohmsTolerance); AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.Milliohms, MilliohmsTolerance); AssertEx.EqualTolerance(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); }
public void As() { var ohm = ElectricResistance.FromOhms(1); AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.As(ElectricResistanceUnit.Kiloohm), KiloohmsTolerance); AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.As(ElectricResistanceUnit.Megaohm), MegaohmsTolerance); AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.As(ElectricResistanceUnit.Milliohm), MilliohmsTolerance); AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricResistanceUnit.Ohm), OhmsTolerance); }
public void ConversionRoundTrip() { ElectricResistance ohm = ElectricResistance.FromOhms(1); AssertEx.EqualTolerance(1, ElectricResistance.FromGigaohms(ohm.Gigaohms).Ohms, GigaohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); }
public void ArithmeticOperators() { ElectricResistance v = ElectricResistance.FromOhms(1); AssertEx.EqualTolerance(-1, -v.Ohms, OhmsTolerance); AssertEx.EqualTolerance(2, (ElectricResistance.FromOhms(3) - v).Ohms, OhmsTolerance); AssertEx.EqualTolerance(2, (v + v).Ohms, OhmsTolerance); AssertEx.EqualTolerance(10, (v * 10).Ohms, OhmsTolerance); AssertEx.EqualTolerance(10, (10 * v).Ohms, OhmsTolerance); AssertEx.EqualTolerance(2, (ElectricResistance.FromOhms(10) / 5).Ohms, OhmsTolerance); AssertEx.EqualTolerance(2, ElectricResistance.FromOhms(10) / ElectricResistance.FromOhms(5), OhmsTolerance); }
public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported() { var ohm = ElectricResistance.FromOhms(1); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.SI)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.CGS)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.BI)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.EE)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.USC)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.FPS)); Assert.Throws <ArgumentException>(() => ohm.ToUnit(UnitSystem.Astronomical)); }
public void EqualityOperators() { ElectricResistance a = ElectricResistance.FromOhms(1); ElectricResistance b = ElectricResistance.FromOhms(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() { ElectricResistance oneOhm = ElectricResistance.FromOhms(1); ElectricResistance twoOhms = ElectricResistance.FromOhms(2); Assert.True(oneOhm < twoOhms); Assert.True(oneOhm <= twoOhms); Assert.True(twoOhms > oneOhm); Assert.True(twoOhms >= oneOhm); Assert.False(oneOhm > twoOhms); Assert.False(oneOhm >= twoOhms); Assert.False(twoOhms < oneOhm); Assert.False(twoOhms <= oneOhm); }
/// <summary> /// Get battery profile /// </summary> /// <returns>Battery profile</returns> public BatteryProfile GetBatteryProfile() { byte[] response = _piJuice.ReadCommand(PiJuiceCommand.BatteryProfile, 14); return(new BatteryProfile( ElectricCharge.FromMilliampereHours(BinaryPrimitives.ReadInt16LittleEndian(response)), ElectricCurrent.FromMilliamperes(response[2] * 75 + 550), ElectricCurrent.FromMilliamperes(response[3] * 50 + 50), ElectricPotential.FromMillivolts(response[4] * 20 + 3500), ElectricPotential.FromMillivolts(response[5] * 20), Temperature.FromDegreesCelsius(response[6]), Temperature.FromDegreesCelsius(response[7]), Temperature.FromDegreesCelsius(response[8]), Temperature.FromDegreesCelsius(response[9]), (response[11] << 8) | response[10], ElectricResistance.FromOhms(((response[13] << 8) | response[12]) * 10))); }
public void EqualityOperators() { var a = ElectricResistance.FromOhms(1); var b = ElectricResistance.FromOhms(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 = ElectricResistance.FromOhms(value); Assert.Equal(ElectricResistance.FromOhms(-value), -quantity); }
public void GetHashCode_Equals() { var quantity = ElectricResistance.FromOhms(1.0); Assert.Equal(new { ElectricResistance.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = ElectricResistance.FromOhms(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = ElectricResistance.FromOhms(1.0); Assert.Equal(ElectricResistance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = ElectricResistance.FromOhms(1.0); Assert.Equal(QuantityType.ElectricResistance, Convert.ChangeType(quantity, typeof(QuantityType))); }