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);
 }
예제 #3
0
        /// <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();
 }
예제 #8
0
 /// <inheritdoc cref="ElectricPotential.FromMicrovolts(double?)"/>
 public static ElectricPotential?Microvolts(this float?value) => ElectricPotential.FromMicrovolts(value);
예제 #9
0
 /// <inheritdoc cref="ElectricPotential.FromMegavolts(double)"/>
 public static ElectricPotential Megavolts(this float value) => ElectricPotential.FromMegavolts(value);
예제 #10
0
        public void ElectricCurrentMultipliedByElectricPotentialEqualsPower()
        {
            Power p = ElectricCurrent.FromAmperes(2) * ElectricPotential.FromVolts(10);

            Assert.Equal(20, p.Watts);
        }
예제 #11
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = ElectricPotential.FromVolts(value);

            Assert.Equal(ElectricPotential.FromVolts(-value), -quantity);
        }
예제 #12
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
예제 #13
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(QuantityType.ElectricPotential, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
예제 #14
0
        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);
 }
예제 #16
0
 /// <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();
 }
예제 #18
0
 /// <inheritdoc cref="ElectricPotential.FromMicrovolts(double?)"/>
 public static ElectricPotential?Microvolts(this decimal?value) => ElectricPotential.FromMicrovolts(value == null ? (double?)null : Convert.ToDouble(value.Value));
예제 #19
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricPotential)));
        }
예제 #20
0
        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));
 }
예제 #22
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
예제 #23
0
        public void CompareToThrowsOnTypeMismatch()
        {
            ElectricPotential volt = ElectricPotential.FromVolts(1);

            Assert.Throws <ArgumentException>(() => volt.CompareTo(new object()));
        }
예제 #24
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
예제 #25
0
        public void CompareToThrowsOnNull()
        {
            ElectricPotential volt = ElectricPotential.FromVolts(1);

            Assert.Throws <ArgumentNullException>(() => volt.CompareTo(null));
        }
예제 #26
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricPotentialUnit)));
        }
예제 #27
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = ElectricPotential.FromVolts(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(ElectricPotential.FromVolts(1), -1, ComparisonType.Relative));
        }
예제 #28
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(ElectricPotential.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
예제 #29
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            ElectricPotential volt = ElectricPotential.FromVolts(1);

            Assert.False(volt.Equals(new object()));
        }
예제 #30
0
        public void GetHashCode_Equals()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(new { ElectricPotential.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
예제 #31
0
        public void EqualsReturnsFalseOnNull()
        {
            ElectricPotential volt = ElectricPotential.FromVolts(1);

            Assert.False(volt.Equals(null));
        }
예제 #32
0
        public void ElectricCurrentTimesElectricResistanceEqualsElectricPotential(float current, float resistance, float expected)
        {
            ElectricPotential potential = ElectricCurrent.FromAmperes(current) * ElectricResistance.FromOhms(resistance);

            Assert.Equal(expected, potential.Volts);
        }
예제 #33
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
예제 #34
0
 protected void Read()
 {
     //read data from SPI channel
     prevSample = sample;
     sample     = referenceVoltage * (double)spiInput.Read().Relative;
 }
예제 #35
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
예제 #36
0
 /// <inheritdoc cref="ElectricPotential.FromMicrovolts(double)"/>
 public static ElectricPotential Microvolts(this double value) => ElectricPotential.FromMicrovolts(value);
예제 #37
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
예제 #38
0
 /// <inheritdoc cref="ElectricPotential.FromMicrovolts(double)"/>
 public static ElectricPotential Microvolts(this decimal value) => ElectricPotential.FromMicrovolts(Convert.ToDouble(value));
예제 #39
0
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }
예제 #40
0
 /// <inheritdoc cref="ElectricPotential.FromMillivolts(double)"/>
 public static ElectricPotential Millivolts(this int value) => ElectricPotential.FromMillivolts(value);
예제 #41
0
        public void Convert_ToInt32_EqualsValueAsSameType()
        {
            var quantity = ElectricPotential.FromVolts(1.0);

            Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity));
        }
예제 #42
0
 /// <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;
 }