/// <inheritdoc cref="AmountOfSubstance.FromMillimoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?Millimoles(this int?value) => AmountOfSubstance.FromMillimoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMicropoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance MicropoundMoles(this double value) => AmountOfSubstance.FromMicropoundMoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMicropoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance MicropoundMoles(this decimal value) => AmountOfSubstance.FromMicropoundMoles(Convert.ToDouble(value));
 /// <inheritdoc cref="AmountOfSubstance.FromKilopoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?KilopoundMoles(this double?value) => AmountOfSubstance.FromKilopoundMoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMicromoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?Micromoles(this double?value) => AmountOfSubstance.FromMicromoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromDecipoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?DecipoundMoles(this float?value) => AmountOfSubstance.FromDecipoundMoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromKilomoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?Kilomoles(this float?value) => AmountOfSubstance.FromKilomoles(value);
        public void CompareToThrowsOnTypeMismatch()
        {
            AmountOfSubstance mole = AmountOfSubstance.FromMoles(1);

            Assert.Throws <ArgumentException>(() => mole.CompareTo(new object()));
        }
        public void CompareToThrowsOnNull()
        {
            AmountOfSubstance mole = AmountOfSubstance.FromMoles(1);

            Assert.Throws <ArgumentNullException>(() => mole.CompareTo(null));
        }
Exemplo n.º 10
0
 public void FromMoles_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => AmountOfSubstance.FromMoles(double.NaN));
 }
Exemplo n.º 11
0
        public void ToUnit()
        {
            var mole = AmountOfSubstance.FromMoles(1);

            var centimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Centimole);

            AssertEx.EqualTolerance(CentimolesInOneMole, (double)centimoleQuantity.Value, CentimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Centimole, centimoleQuantity.Unit);

            var centipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.CentipoundMole);

            AssertEx.EqualTolerance(CentipoundMolesInOneMole, (double)centipoundmoleQuantity.Value, CentipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, centipoundmoleQuantity.Unit);

            var decimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Decimole);

            AssertEx.EqualTolerance(DecimolesInOneMole, (double)decimoleQuantity.Value, DecimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Decimole, decimoleQuantity.Unit);

            var decipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.DecipoundMole);

            AssertEx.EqualTolerance(DecipoundMolesInOneMole, (double)decipoundmoleQuantity.Value, DecipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, decipoundmoleQuantity.Unit);

            var kilomoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Kilomole);

            AssertEx.EqualTolerance(KilomolesInOneMole, (double)kilomoleQuantity.Value, KilomolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Kilomole, kilomoleQuantity.Unit);

            var kilopoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.KilopoundMole);

            AssertEx.EqualTolerance(KilopoundMolesInOneMole, (double)kilopoundmoleQuantity.Value, KilopoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, kilopoundmoleQuantity.Unit);

            var megamoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Megamole);

            AssertEx.EqualTolerance(MegamolesInOneMole, (double)megamoleQuantity.Value, MegamolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Megamole, megamoleQuantity.Unit);

            var micromoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Micromole);

            AssertEx.EqualTolerance(MicromolesInOneMole, (double)micromoleQuantity.Value, MicromolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Micromole, micromoleQuantity.Unit);

            var micropoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.MicropoundMole);

            AssertEx.EqualTolerance(MicropoundMolesInOneMole, (double)micropoundmoleQuantity.Value, MicropoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, micropoundmoleQuantity.Unit);

            var millimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Millimole);

            AssertEx.EqualTolerance(MillimolesInOneMole, (double)millimoleQuantity.Value, MillimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Millimole, millimoleQuantity.Unit);

            var millipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.MillipoundMole);

            AssertEx.EqualTolerance(MillipoundMolesInOneMole, (double)millipoundmoleQuantity.Value, MillipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, millipoundmoleQuantity.Unit);

            var moleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Mole);

            AssertEx.EqualTolerance(MolesInOneMole, (double)moleQuantity.Value, MolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Mole, moleQuantity.Unit);

            var nanomoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Nanomole);

            AssertEx.EqualTolerance(NanomolesInOneMole, (double)nanomoleQuantity.Value, NanomolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Nanomole, nanomoleQuantity.Unit);

            var nanopoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.NanopoundMole);

            AssertEx.EqualTolerance(NanopoundMolesInOneMole, (double)nanopoundmoleQuantity.Value, NanopoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, nanopoundmoleQuantity.Unit);

            var poundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.PoundMole);

            AssertEx.EqualTolerance(PoundMolesInOneMole, (double)poundmoleQuantity.Value, PoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.PoundMole, poundmoleQuantity.Unit);
        }
Exemplo n.º 12
0
 public void FromMoles_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => AmountOfSubstance.FromMoles(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => AmountOfSubstance.FromMoles(double.NegativeInfinity));
 }
Exemplo n.º 13
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Centimole);

            AssertEx.EqualTolerance(1, quantity00.Centimoles, CentimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Centimole, quantity00.Unit);

            var quantity01 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.CentipoundMole);

            AssertEx.EqualTolerance(1, quantity01.CentipoundMoles, CentipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, quantity01.Unit);

            var quantity02 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Decimole);

            AssertEx.EqualTolerance(1, quantity02.Decimoles, DecimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Decimole, quantity02.Unit);

            var quantity03 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.DecipoundMole);

            AssertEx.EqualTolerance(1, quantity03.DecipoundMoles, DecipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, quantity03.Unit);

            var quantity04 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Kilomole);

            AssertEx.EqualTolerance(1, quantity04.Kilomoles, KilomolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Kilomole, quantity04.Unit);

            var quantity05 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.KilopoundMole);

            AssertEx.EqualTolerance(1, quantity05.KilopoundMoles, KilopoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, quantity05.Unit);

            var quantity06 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Megamole);

            AssertEx.EqualTolerance(1, quantity06.Megamoles, MegamolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Megamole, quantity06.Unit);

            var quantity07 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Micromole);

            AssertEx.EqualTolerance(1, quantity07.Micromoles, MicromolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Micromole, quantity07.Unit);

            var quantity08 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.MicropoundMole);

            AssertEx.EqualTolerance(1, quantity08.MicropoundMoles, MicropoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, quantity08.Unit);

            var quantity09 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Millimole);

            AssertEx.EqualTolerance(1, quantity09.Millimoles, MillimolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Millimole, quantity09.Unit);

            var quantity10 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.MillipoundMole);

            AssertEx.EqualTolerance(1, quantity10.MillipoundMoles, MillipoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, quantity10.Unit);

            var quantity11 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Mole);

            AssertEx.EqualTolerance(1, quantity11.Moles, MolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Mole, quantity11.Unit);

            var quantity12 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.Nanomole);

            AssertEx.EqualTolerance(1, quantity12.Nanomoles, NanomolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.Nanomole, quantity12.Unit);

            var quantity13 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.NanopoundMole);

            AssertEx.EqualTolerance(1, quantity13.NanopoundMoles, NanopoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, quantity13.Unit);

            var quantity14 = AmountOfSubstance.From(1, AmountOfSubstanceUnit.PoundMole);

            AssertEx.EqualTolerance(1, quantity14.PoundMoles, PoundMolesTolerance);
            Assert.Equal(AmountOfSubstanceUnit.PoundMole, quantity14.Unit);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");



            //public string SaveAsJSON()
            //{
            //    return JsonConvert.SerializeObject(this, ReturnJSONSettings());
            //}

            //public Fluid LoadFromJSON(string json)
            //{
            //    return JsonConvert.DeserializeObject<Fluid>(json, ReturnJSONSettings());
            //}


            EngineeringUnits.AmountOfSubstance A2 = new EngineeringUnits.AmountOfSubstance(65.743, EngineeringUnits.AmountOfSubstanceUnit.Mole);


            string json = JsonConvert.SerializeObject(A2);

            AmountOfSubstance test2 = JsonConvert.DeserializeObject <AmountOfSubstance>(json);



            UnitsNet.AmountOfSubstance A1 = new UnitsNet.AmountOfSubstance(65.743, UnitsNet.Units.AmountOfSubstanceUnit.Mole);



            //A2.ToUnit(AmountOfSubstanceUnit.);



            Debug.Print(A1.ToString("a"));



            UnitsNet.MassFlow         L1 = new UnitsNet.MassFlow(45442, UnitsNet.Units.MassFlowUnit.PoundPerMinute);
            EngineeringUnits.MassFlow L2 = new EngineeringUnits.MassFlow(45442, EngineeringUnits.MassFlowUnit.PoundPerMinute);



            //Debug.Print($"EngineeringUnits: {L2.As(EngineeringUnits.SpecificHeatCapacityUnit.JoulePerKilogramKelvin)}");
            //Debug.Print($"UnitsNet: {L1.As(UnitsNet.Units.SpecificEntropyUnit.JoulePerKilogramKelvin)}");


            //Debug.Print($"EngineeringUnits: {L2.As(EngineeringUnits.SpecificHeatCapacityUnit.BtuPerPoundFahrenheit)}");
            //Debug.Print($"UnitsNet: {L1.As(UnitsNet.Units.SpecificEntropyUnit.BtuPerPoundFahrenheit)}");


            Debug.Print($"UnitsNet: {L1.As(UnitsNet.Units.MassFlowUnit.PoundPerHour)}");
            Debug.Print($"EngineeringUnits: {L2.As(EngineeringUnits.MassFlowUnit.PoundPerHour)}");

            Debug.Print($"EngineeringUnits: {((L2.As(EngineeringUnits.MassFlowUnit.PoundPerHour) - L1.As(UnitsNet.Units.MassFlowUnit.PoundPerHour)) / L2.As(EngineeringUnits.MassFlowUnit.PoundPerHour))*100}");

            //Debug.Print($"{L2.As(EngineeringUnits.EnergyUnit.Joule) - L1.As(UnitsNet.Units.EnergyUnit.Joule)}");



            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Millimeter) - L1.As(UnitsNet.Units.LengthUnit.Millimeter), 4);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Micrometer) - L1.As(UnitsNet.Units.LengthUnit.Micrometer), 4000);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Nanometer) - L1.As(UnitsNet.Units.LengthUnit.Nanometer), 4000001);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Inch) - L1.As(UnitsNet.Units.LengthUnit.Inch), 0.16);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Hand) - L1.As(UnitsNet.Units.LengthUnit.Hand), 5281);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Foot) - L1.As(UnitsNet.Units.LengthUnit.Foot), 0.014);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Yard) - L1.As(UnitsNet.Units.LengthUnit.Yard), 0.0044);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Chain) - L1.As(UnitsNet.Units.LengthUnit.Chain), 0.0002);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Mile) - L1.As(UnitsNet.Units.LengthUnit.Mile), 0);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.NauticalMile) - L1.As(UnitsNet.Units.LengthUnit.NauticalMile), 2.2E-06);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.LightYear) - L1.As(UnitsNet.Units.LengthUnit.LightYear), 4.3E-19);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.AstronomicalUnit) - L1.As(UnitsNet.Units.LengthUnit.AstronomicalUnit), 2.74E-14);
            //Assert.AreEqual(0, L2.As(EngineeringUnits.LengthUnit.Parsec) - L1.As(UnitsNet.Units.LengthUnit.Parsec), 1.3E-19);
        }
 protected void SetScalarValue(DependencyProperty property, AmountOfSubstance? quantity)
 {
     // we set this flag to prevent from setting scalar value changing quantity values.
     this.isUpdatingScalarValue = true;
     var value = quantity != null
         ? this.Unit.GetScalarValue(quantity.Value)
         : (double?)null;
     this.SetCurrentValue(property, value);
     this.isUpdatingScalarValue = false;
 }
Exemplo n.º 16
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            AmountOfSubstance mole = AmountOfSubstance.FromMoles(1);

            Assert.False(mole.Equals(new object()));
        }
 /// <inheritdoc cref="AmountOfSubstance.FromDecipoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance DecipoundMoles(this double value) => AmountOfSubstance.FromDecipoundMoles(value);
Exemplo n.º 18
0
        public void EqualsReturnsFalseOnNull()
        {
            AmountOfSubstance mole = AmountOfSubstance.FromMoles(1);

            Assert.False(mole.Equals(null));
        }
 /// <inheritdoc cref="AmountOfSubstance.FromKilomoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance Kilomoles(this double value) => AmountOfSubstance.FromKilomoles(value);
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of <see cref="Gu.Units.Wpf.AmountOfSubstanceExtension"/>.
 /// </summary>
 /// <param name="value"><see cref="Gu.Units.AmountOfSubstance"/>.</param>
 public AmountOfSubstanceExtension(AmountOfSubstance value)
 {
     this.Value = value;
 }
 /// <inheritdoc cref="AmountOfSubstance.FromKilomoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance Kilomoles(this decimal value) => AmountOfSubstance.FromKilomoles(Convert.ToDouble(value));
 public static AmountOfSubstance Millimoles <T>(this T value) =>
 AmountOfSubstance.FromMillimoles(Convert.ToDecimal(value));
 /// <inheritdoc cref="AmountOfSubstance.FromKilopoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance KilopoundMoles(this float value) => AmountOfSubstance.FromKilopoundMoles(value);
 public static AmountOfSubstance PoundMoles <T>(this T value) =>
 AmountOfSubstance.FromPoundMoles(Convert.ToDecimal(value));
 /// <inheritdoc cref="AmountOfSubstance.FromMicromoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance Micromoles(this float value) => AmountOfSubstance.FromMicromoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromCentipoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance CentipoundMoles(this float value) => AmountOfSubstance.FromCentipoundMoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMicropoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?MicropoundMoles(this float?value) => AmountOfSubstance.FromMicropoundMoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromDecimoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?Decimoles(this double?value) => AmountOfSubstance.FromDecimoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMicropoundMoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance?MicropoundMoles(this decimal?value) => AmountOfSubstance.FromMicropoundMoles(value == null ? (double?)null : Convert.ToDouble(value.Value));
 /// <inheritdoc cref="AmountOfSubstance.FromDecimoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance Decimoles(this float value) => AmountOfSubstance.FromDecimoles(value);
 /// <inheritdoc cref="AmountOfSubstance.FromMillimoles(UnitsNet.QuantityValue)" />
 public static AmountOfSubstance Millimoles(this long value) => AmountOfSubstance.FromMillimoles(value);
 protected virtual void OnMaxValueChanged(AmountOfSubstance? oldValue, AmountOfSubstance? newValue)
 {
     this.SetScalarValue(ScalarMaxValueProperty, newValue);
 }