コード例 #1
0
 public void FromValueAndUnit()
 {
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.BritishThermalUnit).BritishThermalUnits, BritishThermalUnitsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Calorie).Calories, CaloriesTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermEc).DecathermsEc, DecathermsEcTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermImperial).DecathermsImperial, DecathermsImperialTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermUs).DecathermsUs, DecathermsUsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ElectronVolt).ElectronVolts, ElectronVoltsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Erg).Ergs, ErgsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.FootPound).FootPounds, FootPoundsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigabritishThermalUnit).GigabritishThermalUnits, GigabritishThermalUnitsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigawattHour).GigawattHours, GigawattHoursTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Joule).Joules, JoulesTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilobritishThermalUnit).KilobritishThermalUnits, KilobritishThermalUnitsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilocalorie).Kilocalories, KilocaloriesTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilojoule).Kilojoules, KilojoulesTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilowattHour).KilowattHours, KilowattHoursTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegabritishThermalUnit).MegabritishThermalUnits, MegabritishThermalUnitsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Megajoule).Megajoules, MegajoulesTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegawattHour).MegawattHours, MegawattHoursTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermEc).ThermsEc, ThermsEcTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermImperial).ThermsImperial, ThermsImperialTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermUs).ThermsUs, ThermsUsTolerance);
     AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.WattHour).WattHours, WattHoursTolerance);
 }
コード例 #2
0
 public void FromValueAndUnit()
 {
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.BritishThermalUnit).BritishThermalUnits, BritishThermalUnitsTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Calorie).Calories, CaloriesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.ElectronVolt).ElectronVolts, ElectronVoltsTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Erg).Ergs, ErgsTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.FootPound).FootPounds, FootPoundsTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.GigawattHour).GigawattHours, GigawattHoursTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Joule).Joules, JoulesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Kilocalorie).Kilocalories, KilocaloriesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Kilojoule).Kilojoules, KilojoulesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.KilowattHour).KilowattHours, KilowattHoursTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Megajoule).Megajoules, MegajoulesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.MegawattHour).MegawattHours, MegawattHoursTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.WattHour).WattHours, WattHoursTolerance);
 }
コード例 #3
0
            private static Energy EnergyBurned(Dictionary <string, string> element)
            {
                var hasValue = element.TryGetValue("totalEnergyBurned", out var valueStr);

                element.TryGetValue("totalEnergyBurnedUnit", out var unitStr);

                if (!hasValue)
                {
                    return(Energy.Zero);
                }

                var value = valueStr.SafeParse(0);
                var unit  = Energy.ParseUnit(unitStr);

                return(Energy.From(value, unit));
            }
コード例 #4
0
 public void FromValueAndUnit()
 {
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Joule).Joules, JoulesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Kilojoule).Kilojoules, KilojoulesTolerance);
     Assert.AreEqual(1, Energy.From(1, EnergyUnit.Megajoule).Megajoules, MegajoulesTolerance);
 }
コード例 #5
0
ファイル: EnergyTestsBase.g.cs プロジェクト: wgvdn/UnitsNet
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = Energy.From(1, EnergyUnit.BritishThermalUnit);

            AssertEx.EqualTolerance(1, quantity00.BritishThermalUnits, BritishThermalUnitsTolerance);
            Assert.Equal(EnergyUnit.BritishThermalUnit, quantity00.Unit);

            var quantity01 = Energy.From(1, EnergyUnit.Calorie);

            AssertEx.EqualTolerance(1, quantity01.Calories, CaloriesTolerance);
            Assert.Equal(EnergyUnit.Calorie, quantity01.Unit);

            var quantity02 = Energy.From(1, EnergyUnit.DecathermEc);

            AssertEx.EqualTolerance(1, quantity02.DecathermsEc, DecathermsEcTolerance);
            Assert.Equal(EnergyUnit.DecathermEc, quantity02.Unit);

            var quantity03 = Energy.From(1, EnergyUnit.DecathermImperial);

            AssertEx.EqualTolerance(1, quantity03.DecathermsImperial, DecathermsImperialTolerance);
            Assert.Equal(EnergyUnit.DecathermImperial, quantity03.Unit);

            var quantity04 = Energy.From(1, EnergyUnit.DecathermUs);

            AssertEx.EqualTolerance(1, quantity04.DecathermsUs, DecathermsUsTolerance);
            Assert.Equal(EnergyUnit.DecathermUs, quantity04.Unit);

            var quantity05 = Energy.From(1, EnergyUnit.ElectronVolt);

            AssertEx.EqualTolerance(1, quantity05.ElectronVolts, ElectronVoltsTolerance);
            Assert.Equal(EnergyUnit.ElectronVolt, quantity05.Unit);

            var quantity06 = Energy.From(1, EnergyUnit.Erg);

            AssertEx.EqualTolerance(1, quantity06.Ergs, ErgsTolerance);
            Assert.Equal(EnergyUnit.Erg, quantity06.Unit);

            var quantity07 = Energy.From(1, EnergyUnit.FootPound);

            AssertEx.EqualTolerance(1, quantity07.FootPounds, FootPoundsTolerance);
            Assert.Equal(EnergyUnit.FootPound, quantity07.Unit);

            var quantity08 = Energy.From(1, EnergyUnit.GigabritishThermalUnit);

            AssertEx.EqualTolerance(1, quantity08.GigabritishThermalUnits, GigabritishThermalUnitsTolerance);
            Assert.Equal(EnergyUnit.GigabritishThermalUnit, quantity08.Unit);

            var quantity09 = Energy.From(1, EnergyUnit.Gigajoule);

            AssertEx.EqualTolerance(1, quantity09.Gigajoules, GigajoulesTolerance);
            Assert.Equal(EnergyUnit.Gigajoule, quantity09.Unit);

            var quantity10 = Energy.From(1, EnergyUnit.GigawattHour);

            AssertEx.EqualTolerance(1, quantity10.GigawattHours, GigawattHoursTolerance);
            Assert.Equal(EnergyUnit.GigawattHour, quantity10.Unit);

            var quantity11 = Energy.From(1, EnergyUnit.Joule);

            AssertEx.EqualTolerance(1, quantity11.Joules, JoulesTolerance);
            Assert.Equal(EnergyUnit.Joule, quantity11.Unit);

            var quantity12 = Energy.From(1, EnergyUnit.KilobritishThermalUnit);

            AssertEx.EqualTolerance(1, quantity12.KilobritishThermalUnits, KilobritishThermalUnitsTolerance);
            Assert.Equal(EnergyUnit.KilobritishThermalUnit, quantity12.Unit);

            var quantity13 = Energy.From(1, EnergyUnit.Kilocalorie);

            AssertEx.EqualTolerance(1, quantity13.Kilocalories, KilocaloriesTolerance);
            Assert.Equal(EnergyUnit.Kilocalorie, quantity13.Unit);

            var quantity14 = Energy.From(1, EnergyUnit.Kilojoule);

            AssertEx.EqualTolerance(1, quantity14.Kilojoules, KilojoulesTolerance);
            Assert.Equal(EnergyUnit.Kilojoule, quantity14.Unit);

            var quantity15 = Energy.From(1, EnergyUnit.KilowattHour);

            AssertEx.EqualTolerance(1, quantity15.KilowattHours, KilowattHoursTolerance);
            Assert.Equal(EnergyUnit.KilowattHour, quantity15.Unit);

            var quantity16 = Energy.From(1, EnergyUnit.MegabritishThermalUnit);

            AssertEx.EqualTolerance(1, quantity16.MegabritishThermalUnits, MegabritishThermalUnitsTolerance);
            Assert.Equal(EnergyUnit.MegabritishThermalUnit, quantity16.Unit);

            var quantity17 = Energy.From(1, EnergyUnit.Megacalorie);

            AssertEx.EqualTolerance(1, quantity17.Megacalories, MegacaloriesTolerance);
            Assert.Equal(EnergyUnit.Megacalorie, quantity17.Unit);

            var quantity18 = Energy.From(1, EnergyUnit.Megajoule);

            AssertEx.EqualTolerance(1, quantity18.Megajoules, MegajoulesTolerance);
            Assert.Equal(EnergyUnit.Megajoule, quantity18.Unit);

            var quantity19 = Energy.From(1, EnergyUnit.MegawattHour);

            AssertEx.EqualTolerance(1, quantity19.MegawattHours, MegawattHoursTolerance);
            Assert.Equal(EnergyUnit.MegawattHour, quantity19.Unit);

            var quantity20 = Energy.From(1, EnergyUnit.Millijoule);

            AssertEx.EqualTolerance(1, quantity20.Millijoules, MillijoulesTolerance);
            Assert.Equal(EnergyUnit.Millijoule, quantity20.Unit);

            var quantity21 = Energy.From(1, EnergyUnit.TerawattHour);

            AssertEx.EqualTolerance(1, quantity21.TerawattHours, TerawattHoursTolerance);
            Assert.Equal(EnergyUnit.TerawattHour, quantity21.Unit);

            var quantity22 = Energy.From(1, EnergyUnit.ThermEc);

            AssertEx.EqualTolerance(1, quantity22.ThermsEc, ThermsEcTolerance);
            Assert.Equal(EnergyUnit.ThermEc, quantity22.Unit);

            var quantity23 = Energy.From(1, EnergyUnit.ThermImperial);

            AssertEx.EqualTolerance(1, quantity23.ThermsImperial, ThermsImperialTolerance);
            Assert.Equal(EnergyUnit.ThermImperial, quantity23.Unit);

            var quantity24 = Energy.From(1, EnergyUnit.ThermUs);

            AssertEx.EqualTolerance(1, quantity24.ThermsUs, ThermsUsTolerance);
            Assert.Equal(EnergyUnit.ThermUs, quantity24.Unit);

            var quantity25 = Energy.From(1, EnergyUnit.WattHour);

            AssertEx.EqualTolerance(1, quantity25.WattHours, WattHoursTolerance);
            Assert.Equal(EnergyUnit.WattHour, quantity25.Unit);
        }