public void VerifyAllEnums() { var acceleration = new Acceleration(1, AccelerationUnit.BaseUnit); var angle = new Angle(1, AngleUnit.BaseUnit); var angularAcceleration = new AngularAcceleration(1, AngularAccelerationUnit.BaseUnit); var area = new Area(1, AreaUnit.BaseUnit); var density = new MassDensity(1, MassDensityUnit.BaseUnit); var electricCurrent = new ElectricCurrent(1, ElectricCurrentUnit.BaseUnit); var electricResistance = new ElectricResistance(1, ElectricResistanceUnit.BaseUnit); var electricVoltage = new ElectricPotential(1, ElectricPotentialUnit.BaseUnit); var energy = new Energy(1, EnergyUnit.BaseUnit); var force = new Force(1, ForceUnit.BaseUnit); var frequency = new Frequency(1, FrequencyUnit.BaseUnit); var jerk = new Jerk(1, JerkUnit.BaseUnit); var length = new Length(1, LengthUnit.BaseUnit); var mass = new Mass(1, MassUnit.BaseUnit); var massFlowRate = new MassFlowRate(1, MassFlowRateUnit.BaseUnit); var momentum = new Momentum(1, MomentumUnit.BaseUnit); var numeric = new Numeric(1, NumericUnit.BaseUnit); var power = new Power(1, PowerUnit.BaseUnit); var pressure = new Pressure(1, PressureUnit.BaseUnit); var speed = new Speed(1, SpeedUnit.BaseUnit); var temperature = new Temperature(1, TemperatureUnit.BaseUnit); var time = new Time(1, TimeUnit.BaseUnit); var torque = new Torque(1, TorqueUnit.BaseUnit); var volume = new Volume(1, VolumeUnit.BaseUnit); var volumetricFlowRate = new VolumetricFlowRate(1, VolumetricFlowRateUnit.BaseUnit); }
public void OpAddition() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(1, ElectricPotentialUnit.Kilovolt); var expected = new ElectricPotential(4000, ElectricPotentialUnit.Volt); (voltage1 + voltage2).ShouldEqual(expected); (voltage2 + voltage1).ShouldEqual(expected); }
/// <summary> /// Initializes a new instance of the <see cref="AmplitudeRatio"/> struct from the specified electric potential /// referenced to one volt RMS. This assumes both the specified electric potential and the one volt reference have the same /// resistance. /// </summary> /// <param name="voltage">The electric potential referenced to one volt.</param> public AmplitudeRatio(ElectricPotential voltage) : this() { if (voltage.Volts <= 0) throw new ArgumentOutOfRangeException( "voltage", "The base-10 logarithm of a number ≤ 0 is undefined. Voltage must be greater than 0 V."); // E(dBV) = 20*log10(value(V)/reference(V)) _decibelVolts = 20 * Math.Log10(voltage / ElectricPotential.FromVolts(1)); }
public void OpDivision() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(3, ElectricPotentialUnit.Kilovolt); (voltage1 / voltage2).ShouldBeWithinEpsilonOf(1); (voltage2 / voltage1).ShouldBeWithinEpsilonOf(1); (voltage1 / 2).ShouldEqual(new ElectricPotential(1500, ElectricPotentialUnit.Volt)); (voltage2 / 2).ShouldEqual(new ElectricPotential(1.5, ElectricPotentialUnit.Kilovolt)); }
public void OpInverseEquals() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(3, ElectricPotentialUnit.Kilovolt); var voltage3 = new ElectricPotential(10, ElectricPotentialUnit.Kilovolt); (voltage1 != voltage2).ShouldBeFalse(); (voltage2 != voltage1).ShouldBeFalse(); (voltage1 != voltage3).ShouldBeTrue(); (voltage3 != voltage1).ShouldBeTrue(); }
public void OpGreaterThanOrEqual() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(3, ElectricPotentialUnit.Kilovolt); var voltage3 = new ElectricPotential(10, ElectricPotentialUnit.Kilovolt); (voltage1 >= voltage3).ShouldBeFalse(); (voltage3 >= voltage1).ShouldBeTrue(); (voltage1 >= voltage2).ShouldBeTrue(); (voltage2 >= voltage1).ShouldBeTrue(); }
public void OpEquals() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(3, ElectricPotentialUnit.Kilovolt); var voltage3 = new ElectricPotential(10, ElectricPotentialUnit.Kilovolt); (voltage1 == voltage2).ShouldBeTrue(); (voltage2 == voltage1).ShouldBeTrue(); (voltage1 == voltage3).ShouldBeFalse(); (voltage3 == voltage1).ShouldBeFalse(); voltage1.Equals(voltage2) .ShouldBeTrue(); voltage1.Equals((object)voltage2) .ShouldBeTrue(); voltage2.Equals(voltage1) .ShouldBeTrue(); voltage2.Equals((object)voltage1) .ShouldBeTrue(); }
/// <inheritdoc cref="ElectricPotential.FromMicrovolts(double?)"/> public static ElectricPotential?Microvolts(this float?value) => ElectricPotential.FromMicrovolts(value);
/// <inheritdoc cref="ElectricPotential.FromMegavolts(double)"/> public static ElectricPotential Megavolts(this float value) => ElectricPotential.FromMegavolts(value);
public void ElectricCurrentMultipliedByElectricPotentialEqualsPower() { Power p = ElectricCurrent.FromAmperes(2) * ElectricPotential.FromVolts(10); Assert.Equal(20, p.Watts); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = ElectricPotential.FromVolts(value); Assert.Equal(ElectricPotential.FromVolts(-value), -quantity); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(QuantityType.ElectricPotential, Convert.ChangeType(quantity, typeof(QuantityType))); }
public void Convert_ToString_EqualsToString() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }
public void OpMultiplicationScaler() { var voltage = new ElectricPotential(1, ElectricPotentialUnit.Volt); var expected = new ElectricPotential(2, ElectricPotentialUnit.Volt); (voltage * 2).ShouldEqual(expected); (2 * voltage).ShouldEqual(expected); }
/// <summary> /// Initializes a new instance of the <see cref="Tmp36Connection"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Tmp36Connection(IInputAnalogPin inputPin, ElectricPotential referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }
public void OpLessThan() { var voltage1 = new ElectricPotential(3000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(3, ElectricPotentialUnit.Kilovolt); var voltage3 = new ElectricPotential(10, ElectricPotentialUnit.Kilovolt); (voltage1 < voltage3).ShouldBeTrue(); (voltage3 < voltage1).ShouldBeFalse(); (voltage1 < voltage2).ShouldBeFalse(); (voltage2 < voltage1).ShouldBeFalse(); }
/// <inheritdoc cref="ElectricPotential.FromMicrovolts(double?)"/> public static ElectricPotential?Microvolts(this decimal?value) => ElectricPotential.FromMicrovolts(value == null ? (double?)null : Convert.ToDouble(value.Value));
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricPotential))); }
public void ToBaseUnit_ReturnsQuantityWithBaseUnit() { var quantityInBaseUnit = ElectricPotential.FromVolts(1).ToBaseUnit(); Assert.Equal(ElectricPotential.BaseUnit, quantityInBaseUnit.Unit); }
public void OpSubtraction() { var voltage1 = new ElectricPotential(7000, ElectricPotentialUnit.Volt); var voltage2 = new ElectricPotential(1, ElectricPotentialUnit.Kilovolt); (voltage1 - voltage2).ShouldEqual(new ElectricPotential(6000, ElectricPotentialUnit.Volt)); (voltage2 - voltage1).ShouldEqual(new ElectricPotential(-6, ElectricPotentialUnit.Kilovolt)); }
public void Convert_ToSingle_EqualsValueAsSameType() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
public void CompareToThrowsOnTypeMismatch() { ElectricPotential volt = ElectricPotential.FromVolts(1); Assert.Throws <ArgumentException>(() => volt.CompareTo(new object())); }
public void Convert_ToUInt64_EqualsValueAsSameType() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void CompareToThrowsOnNull() { ElectricPotential volt = ElectricPotential.FromVolts(1); Assert.Throws <ArgumentNullException>(() => volt.CompareTo(null)); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricPotentialUnit))); }
public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() { var v = ElectricPotential.FromVolts(1); Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(ElectricPotential.FromVolts(1), -1, ComparisonType.Relative)); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(ElectricPotential.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void EqualsReturnsFalseOnTypeMismatch() { ElectricPotential volt = ElectricPotential.FromVolts(1); Assert.False(volt.Equals(new object())); }
public void GetHashCode_Equals() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(new { ElectricPotential.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void EqualsReturnsFalseOnNull() { ElectricPotential volt = ElectricPotential.FromVolts(1); Assert.False(volt.Equals(null)); }
public void ElectricCurrentTimesElectricResistanceEqualsElectricPotential(float current, float resistance, float expected) { ElectricPotential potential = ElectricCurrent.FromAmperes(current) * ElectricResistance.FromOhms(resistance); Assert.Equal(expected, potential.Volts); }
public void ToString_NullArgs_ThrowsArgumentNullException() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null)); }
protected void Read() { //read data from SPI channel prevSample = sample; sample = referenceVoltage * (double)spiInput.Read().Relative; }
public void ToString_NullProvider_EqualsCurrentUICulture() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); }
/// <inheritdoc cref="ElectricPotential.FromMicrovolts(double)"/> public static ElectricPotential Microvolts(this double value) => ElectricPotential.FromMicrovolts(value);
public void Convert_ToDateTime_ThrowsInvalidCastException() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity)); }
/// <inheritdoc cref="ElectricPotential.FromMicrovolts(double)"/> public static ElectricPotential Microvolts(this decimal value) => ElectricPotential.FromMicrovolts(Convert.ToDouble(value));
public void Convert_ToDecimal_EqualsValueAsSameType() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); }
/// <inheritdoc cref="ElectricPotential.FromMillivolts(double)"/> public static ElectricPotential Millivolts(this int value) => ElectricPotential.FromMillivolts(value);
public void Convert_ToInt32_EqualsValueAsSameType() { var quantity = ElectricPotential.FromVolts(1.0); Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); }
/// <summary> /// Gets an <see cref="AmplitudeRatio"/> in decibels (dB) relative to 1 volt RMS from an <see cref="ElectricPotential"/>. /// </summary> /// <param name="voltage">The voltage (electric potential) relative to one volt RMS.</param> public static AmplitudeRatio FromElectricPotential(ElectricPotential voltage) { return new AmplitudeRatio(voltage); }
/// <summary> /// Initializes a new instance of the <see cref="Mcp9701a"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Mcp9701a(InputAnalogPin inputPin, ElectricPotential referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }