diff --git a/UnitsNet.Tests/CustomCode/AngleTests.cs b/UnitsNet.Tests/CustomCode/AngleTests.cs index 965e3c5364..988496525e 100644 --- a/UnitsNet.Tests/CustomCode/AngleTests.cs +++ b/UnitsNet.Tests/CustomCode/AngleTests.cs @@ -35,9 +35,25 @@ protected override double GradiansInOneDegree get { return 400/360.0; } } + protected override double ArcminutesInOneDegree + { + get + { + return 60.0; + } + } + protected override double RadiansInOneDegree { get { return Math.PI/2/90; } } + + protected override double ArcsecondsInOneDegree + { + get + { + return 3600.0; + } + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/FrequencyTests.cs b/UnitsNet.Tests/CustomCode/FrequencyTests.cs index 0cd6b24e23..6d87a41a6a 100644 --- a/UnitsNet.Tests/CustomCode/FrequencyTests.cs +++ b/UnitsNet.Tests/CustomCode/FrequencyTests.cs @@ -59,5 +59,13 @@ protected override double CyclesPerMinuteInOneHertz { get { return 0.016666667; } } + + protected override double RadiansPerSecondInOneHertz + { + get + { + return 2 * Math.PI; + } + } } } diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index a880495060..896da4f6e4 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + namespace UnitsNet.Tests.CustomCode { public class LengthTests : LengthTestsBase @@ -87,5 +89,11 @@ protected override double YardsInOneMeter { get { return 1.09361; } } + + protected override double NauticalMilesInOneMeter + { + get + { return 1.0/1852.0; } + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs new file mode 100644 index 0000000000..21f452ded4 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -0,0 +1,46 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class MassFlowTests : MassFlowTestsBase + { + // TODO Override properties in base class here + protected override double KilogramsPerSecondInOneKilogramPerSecond + { + get + { + return 1.0; + } + } + + protected override double TonnesPerDayInOneKilogramPerSecond + { + get + { + return (60.0 * 60 * 24 / 1000); + } + } + } +} diff --git a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs index 264b42680d..9d0e934f83 100644 --- a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs @@ -19,10 +19,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + namespace UnitsNet.Tests.CustomCode { public class RotationalSpeedTests : RotationalSpeedTestsBase { + protected override double RadiansPerSecondInOneRevolutionPerSecond + { + get + { + return 2 * Math.PI; + } + } + protected override double RevolutionsPerMinuteInOneRevolutionPerSecond { get { return 1.0*60; } diff --git a/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs new file mode 100644 index 0000000000..aec916542e --- /dev/null +++ b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs @@ -0,0 +1,94 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class SpecificEnergyTests : SpecificEnergyTestsBase + { + protected override double JoulesPerKilogramInOneJoulePerKilogram + { + get + { + return 1.0; + } + } + + protected override double CaloriesPerGramInOneJoulePerKilogram + { + get + { + return 1.0 / (4.184E3); + } + } + + protected override double KilocaloriesPerGramInOneJoulePerKilogram + { + get + { + return 1.0 / (4.184E6); + } + } + + + protected override double KilojoulesPerKilogramInOneJoulePerKilogram + { + get + { + return 1.0E-3; + } + } + + protected override double KilowattHoursPerKilogramInOneJoulePerKilogram + { + get + { + return 2.77777778e-7; + } + } + + protected override double MegajoulesPerKilogramInOneJoulePerKilogram + { + get + { + return 1.0E-6; + } + } + + protected override double MegawattHoursPerKilogramInOneJoulePerKilogram + { + get + { + return 2.77777778E-10; + } + } + + protected override double WattHoursPerKilogramInOneJoulePerKilogram + { + get + { + return 1.0 / 3.6e3; + } + } + } +} diff --git a/UnitsNet.Tests/CustomCode/SpeedTests.cs b/UnitsNet.Tests/CustomCode/SpeedTests.cs index 38db48de94..ec3c549715 100644 --- a/UnitsNet.Tests/CustomCode/SpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/SpeedTests.cs @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + namespace UnitsNet.Tests.CustomCode { public class SpeedTests : SpeedTestsBase @@ -79,5 +81,12 @@ protected override double KilometersPerSecondInOneMeterPerSecond get { return 1E-3; } } + protected override double MetersPerHourInOneMeterPerSecond + { + get + { + return 3600.0; + } + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs index 4a6735d542..9582b7c16b 100644 --- a/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs @@ -36,11 +36,15 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class AngleTestsBase { + protected abstract double ArcminutesInOneDegree { get; } + protected abstract double ArcsecondsInOneDegree { get; } protected abstract double DegreesInOneDegree { get; } protected abstract double GradiansInOneDegree { get; } protected abstract double RadiansInOneDegree { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double ArcminutesTolerance { get { return 1e-5; } } + protected virtual double ArcsecondsTolerance { get { return 1e-5; } } protected virtual double DegreesTolerance { get { return 1e-5; } } protected virtual double GradiansTolerance { get { return 1e-5; } } protected virtual double RadiansTolerance { get { return 1e-5; } } @@ -50,6 +54,8 @@ public abstract partial class AngleTestsBase public void DegreeToAngleUnits() { Angle degree = Angle.FromDegrees(1); + Assert.AreEqual(ArcminutesInOneDegree, degree.Arcminutes, ArcminutesTolerance); + Assert.AreEqual(ArcsecondsInOneDegree, degree.Arcseconds, ArcsecondsTolerance); Assert.AreEqual(DegreesInOneDegree, degree.Degrees, DegreesTolerance); Assert.AreEqual(GradiansInOneDegree, degree.Gradians, GradiansTolerance); Assert.AreEqual(RadiansInOneDegree, degree.Radians, RadiansTolerance); @@ -58,6 +64,8 @@ public void DegreeToAngleUnits() [Test] public void FromValueAndUnit() { + Assert.AreEqual(1, Angle.From(1, AngleUnit.Arcminute).Arcminutes, ArcminutesTolerance); + Assert.AreEqual(1, Angle.From(1, AngleUnit.Arcsecond).Arcseconds, ArcsecondsTolerance); Assert.AreEqual(1, Angle.From(1, AngleUnit.Degree).Degrees, DegreesTolerance); Assert.AreEqual(1, Angle.From(1, AngleUnit.Gradian).Gradians, GradiansTolerance); Assert.AreEqual(1, Angle.From(1, AngleUnit.Radian).Radians, RadiansTolerance); @@ -67,6 +75,8 @@ public void FromValueAndUnit() public void As() { var degree = Angle.FromDegrees(1); + Assert.AreEqual(ArcminutesInOneDegree, degree.As(AngleUnit.Arcminute), ArcminutesTolerance); + Assert.AreEqual(ArcsecondsInOneDegree, degree.As(AngleUnit.Arcsecond), ArcsecondsTolerance); Assert.AreEqual(DegreesInOneDegree, degree.As(AngleUnit.Degree), DegreesTolerance); Assert.AreEqual(GradiansInOneDegree, degree.As(AngleUnit.Gradian), GradiansTolerance); Assert.AreEqual(RadiansInOneDegree, degree.As(AngleUnit.Radian), RadiansTolerance); @@ -76,6 +86,8 @@ public void As() public void ConversionRoundTrip() { Angle degree = Angle.FromDegrees(1); + Assert.AreEqual(1, Angle.FromArcminutes(degree.Arcminutes).Degrees, ArcminutesTolerance); + Assert.AreEqual(1, Angle.FromArcseconds(degree.Arcseconds).Degrees, ArcsecondsTolerance); Assert.AreEqual(1, Angle.FromDegrees(degree.Degrees).Degrees, DegreesTolerance); Assert.AreEqual(1, Angle.FromGradians(degree.Gradians).Degrees, GradiansTolerance); Assert.AreEqual(1, Angle.FromRadians(degree.Radians).Degrees, RadiansTolerance); diff --git a/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs index 4434d6aea2..94ce535b49 100644 --- a/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs @@ -42,6 +42,7 @@ public abstract partial class FrequencyTestsBase protected abstract double HertzInOneHertz { get; } protected abstract double KilohertzInOneHertz { get; } protected abstract double MegahertzInOneHertz { get; } + protected abstract double RadiansPerSecondInOneHertz { get; } protected abstract double TerahertzInOneHertz { get; } // ReSharper disable VirtualMemberNeverOverriden.Global @@ -51,6 +52,7 @@ public abstract partial class FrequencyTestsBase protected virtual double HertzTolerance { get { return 1e-5; } } protected virtual double KilohertzTolerance { get { return 1e-5; } } protected virtual double MegahertzTolerance { get { return 1e-5; } } + protected virtual double RadiansPerSecondTolerance { get { return 1e-5; } } protected virtual double TerahertzTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -64,6 +66,7 @@ public void HertzToFrequencyUnits() Assert.AreEqual(HertzInOneHertz, hertz.Hertz, HertzTolerance); Assert.AreEqual(KilohertzInOneHertz, hertz.Kilohertz, KilohertzTolerance); Assert.AreEqual(MegahertzInOneHertz, hertz.Megahertz, MegahertzTolerance); + Assert.AreEqual(RadiansPerSecondInOneHertz, hertz.RadiansPerSecond, RadiansPerSecondTolerance); Assert.AreEqual(TerahertzInOneHertz, hertz.Terahertz, TerahertzTolerance); } @@ -76,6 +79,7 @@ public void FromValueAndUnit() Assert.AreEqual(1, Frequency.From(1, FrequencyUnit.Hertz).Hertz, HertzTolerance); Assert.AreEqual(1, Frequency.From(1, FrequencyUnit.Kilohertz).Kilohertz, KilohertzTolerance); Assert.AreEqual(1, Frequency.From(1, FrequencyUnit.Megahertz).Megahertz, MegahertzTolerance); + Assert.AreEqual(1, Frequency.From(1, FrequencyUnit.RadianPerSecond).RadiansPerSecond, RadiansPerSecondTolerance); Assert.AreEqual(1, Frequency.From(1, FrequencyUnit.Terahertz).Terahertz, TerahertzTolerance); } @@ -89,6 +93,7 @@ public void As() Assert.AreEqual(HertzInOneHertz, hertz.As(FrequencyUnit.Hertz), HertzTolerance); Assert.AreEqual(KilohertzInOneHertz, hertz.As(FrequencyUnit.Kilohertz), KilohertzTolerance); Assert.AreEqual(MegahertzInOneHertz, hertz.As(FrequencyUnit.Megahertz), MegahertzTolerance); + Assert.AreEqual(RadiansPerSecondInOneHertz, hertz.As(FrequencyUnit.RadianPerSecond), RadiansPerSecondTolerance); Assert.AreEqual(TerahertzInOneHertz, hertz.As(FrequencyUnit.Terahertz), TerahertzTolerance); } @@ -102,6 +107,7 @@ public void ConversionRoundTrip() Assert.AreEqual(1, Frequency.FromHertz(hertz.Hertz).Hertz, HertzTolerance); Assert.AreEqual(1, Frequency.FromKilohertz(hertz.Kilohertz).Hertz, KilohertzTolerance); Assert.AreEqual(1, Frequency.FromMegahertz(hertz.Megahertz).Hertz, MegahertzTolerance); + Assert.AreEqual(1, Frequency.FromRadiansPerSecond(hertz.RadiansPerSecond).Hertz, RadiansPerSecondTolerance); Assert.AreEqual(1, Frequency.FromTerahertz(hertz.Terahertz).Hertz, TerahertzTolerance); } diff --git a/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs index 200e7e538e..a7f4b0a82f 100644 --- a/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs @@ -48,6 +48,7 @@ public abstract partial class LengthTestsBase protected abstract double MilesInOneMeter { get; } protected abstract double MillimetersInOneMeter { get; } protected abstract double NanometersInOneMeter { get; } + protected abstract double NauticalMilesInOneMeter { get; } protected abstract double YardsInOneMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global @@ -63,6 +64,7 @@ public abstract partial class LengthTestsBase protected virtual double MilesTolerance { get { return 1e-5; } } protected virtual double MillimetersTolerance { get { return 1e-5; } } protected virtual double NanometersTolerance { get { return 1e-5; } } + protected virtual double NauticalMilesTolerance { get { return 1e-5; } } protected virtual double YardsTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -82,6 +84,7 @@ public void MeterToLengthUnits() Assert.AreEqual(MilesInOneMeter, meter.Miles, MilesTolerance); Assert.AreEqual(MillimetersInOneMeter, meter.Millimeters, MillimetersTolerance); Assert.AreEqual(NanometersInOneMeter, meter.Nanometers, NanometersTolerance); + Assert.AreEqual(NauticalMilesInOneMeter, meter.NauticalMiles, NauticalMilesTolerance); Assert.AreEqual(YardsInOneMeter, meter.Yards, YardsTolerance); } @@ -100,6 +103,7 @@ public void FromValueAndUnit() Assert.AreEqual(1, Length.From(1, LengthUnit.Mile).Miles, MilesTolerance); Assert.AreEqual(1, Length.From(1, LengthUnit.Millimeter).Millimeters, MillimetersTolerance); Assert.AreEqual(1, Length.From(1, LengthUnit.Nanometer).Nanometers, NanometersTolerance); + Assert.AreEqual(1, Length.From(1, LengthUnit.NauticalMile).NauticalMiles, NauticalMilesTolerance); Assert.AreEqual(1, Length.From(1, LengthUnit.Yard).Yards, YardsTolerance); } @@ -119,6 +123,7 @@ public void As() Assert.AreEqual(MilesInOneMeter, meter.As(LengthUnit.Mile), MilesTolerance); Assert.AreEqual(MillimetersInOneMeter, meter.As(LengthUnit.Millimeter), MillimetersTolerance); Assert.AreEqual(NanometersInOneMeter, meter.As(LengthUnit.Nanometer), NanometersTolerance); + Assert.AreEqual(NauticalMilesInOneMeter, meter.As(LengthUnit.NauticalMile), NauticalMilesTolerance); Assert.AreEqual(YardsInOneMeter, meter.As(LengthUnit.Yard), YardsTolerance); } @@ -138,6 +143,7 @@ public void ConversionRoundTrip() Assert.AreEqual(1, Length.FromMiles(meter.Miles).Meters, MilesTolerance); Assert.AreEqual(1, Length.FromMillimeters(meter.Millimeters).Meters, MillimetersTolerance); Assert.AreEqual(1, Length.FromNanometers(meter.Nanometers).Meters, NanometersTolerance); + Assert.AreEqual(1, Length.FromNauticalMiles(meter.NauticalMiles).Meters, NauticalMilesTolerance); Assert.AreEqual(1, Length.FromYards(meter.Yards).Meters, YardsTolerance); } diff --git a/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs new file mode 100644 index 0000000000..c7999d864e --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs @@ -0,0 +1,173 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using NUnit.Framework; +using UnitsNet.Units; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of MassFlow. + /// + [TestFixture] +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class MassFlowTestsBase + { + protected abstract double KilogramsPerSecondInOneKilogramPerSecond { get; } + protected abstract double TonnesPerDayInOneKilogramPerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double KilogramsPerSecondTolerance { get { return 1e-5; } } + protected virtual double TonnesPerDayTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Test] + public void KilogramPerSecondToMassFlowUnits() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.AreEqual(KilogramsPerSecondInOneKilogramPerSecond, kilogrampersecond.KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(TonnesPerDayInOneKilogramPerSecond, kilogrampersecond.TonnesPerDay, TonnesPerDayTolerance); + } + + [Test] + public void FromValueAndUnit() + { + Assert.AreEqual(1, MassFlow.From(1, MassFlowUnit.KilogramPerSecond).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(1, MassFlow.From(1, MassFlowUnit.TonnePerDay).TonnesPerDay, TonnesPerDayTolerance); + } + + [Test] + public void As() + { + var kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.AreEqual(KilogramsPerSecondInOneKilogramPerSecond, kilogrampersecond.As(MassFlowUnit.KilogramPerSecond), KilogramsPerSecondTolerance); + Assert.AreEqual(TonnesPerDayInOneKilogramPerSecond, kilogrampersecond.As(MassFlowUnit.TonnePerDay), TonnesPerDayTolerance); + } + + [Test] + public void ConversionRoundTrip() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.AreEqual(1, MassFlow.FromKilogramsPerSecond(kilogrampersecond.KilogramsPerSecond).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(1, MassFlow.FromTonnesPerDay(kilogrampersecond.TonnesPerDay).KilogramsPerSecond, TonnesPerDayTolerance); + } + + [Test] + public void ArithmeticOperators() + { + MassFlow v = MassFlow.FromKilogramsPerSecond(1); + Assert.AreEqual(-1, -v.KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(2, (MassFlow.FromKilogramsPerSecond(3)-v).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(2, (v + v).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(10, (v*10).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(10, (10*v).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(2, (MassFlow.FromKilogramsPerSecond(10)/5).KilogramsPerSecond, KilogramsPerSecondTolerance); + Assert.AreEqual(2, MassFlow.FromKilogramsPerSecond(10)/MassFlow.FromKilogramsPerSecond(5), KilogramsPerSecondTolerance); + } + + [Test] + public void ComparisonOperators() + { + MassFlow oneKilogramPerSecond = MassFlow.FromKilogramsPerSecond(1); + MassFlow twoKilogramsPerSecond = MassFlow.FromKilogramsPerSecond(2); + + Assert.True(oneKilogramPerSecond < twoKilogramsPerSecond); + Assert.True(oneKilogramPerSecond <= twoKilogramsPerSecond); + Assert.True(twoKilogramsPerSecond > oneKilogramPerSecond); + Assert.True(twoKilogramsPerSecond >= oneKilogramPerSecond); + + Assert.False(oneKilogramPerSecond > twoKilogramsPerSecond); + Assert.False(oneKilogramPerSecond >= twoKilogramsPerSecond); + Assert.False(twoKilogramsPerSecond < oneKilogramPerSecond); + Assert.False(twoKilogramsPerSecond <= oneKilogramPerSecond); + } + + [Test] + public void CompareToIsImplemented() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.AreEqual(0, kilogrampersecond.CompareTo(kilogrampersecond)); + Assert.Greater(kilogrampersecond.CompareTo(MassFlow.Zero), 0); + Assert.Less(MassFlow.Zero.CompareTo(kilogrampersecond), 0); + } + + [Test] + [ExpectedException(typeof(ArgumentException))] + public void CompareToThrowsOnTypeMismatch() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + kilogrampersecond.CompareTo(new object()); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void CompareToThrowsOnNull() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + kilogrampersecond.CompareTo(null); + } + + + [Test] + public void EqualityOperators() + { + MassFlow a = MassFlow.FromKilogramsPerSecond(1); + MassFlow b = MassFlow.FromKilogramsPerSecond(2); + +// ReSharper disable EqualExpressionComparison + Assert.True(a == a); + Assert.True(a != b); + + Assert.False(a == b); + Assert.False(a != a); +// ReSharper restore EqualExpressionComparison + } + + [Test] + public void EqualsIsImplemented() + { + MassFlow v = MassFlow.FromKilogramsPerSecond(1); + Assert.IsTrue(v.Equals(MassFlow.FromKilogramsPerSecond(1))); + Assert.IsFalse(v.Equals(MassFlow.Zero)); + } + + [Test] + public void EqualsReturnsFalseOnTypeMismatch() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.IsFalse(kilogrampersecond.Equals(new object())); + } + + [Test] + public void EqualsReturnsFalseOnNull() + { + MassFlow kilogrampersecond = MassFlow.FromKilogramsPerSecond(1); + Assert.IsFalse(kilogrampersecond.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs index fa01f014e9..c19e55c6aa 100644 --- a/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs @@ -36,10 +36,12 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class RotationalSpeedTestsBase { + protected abstract double RadiansPerSecondInOneRevolutionPerSecond { get; } protected abstract double RevolutionsPerMinuteInOneRevolutionPerSecond { get; } protected abstract double RevolutionsPerSecondInOneRevolutionPerSecond { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double RadiansPerSecondTolerance { get { return 1e-5; } } protected virtual double RevolutionsPerMinuteTolerance { get { return 1e-5; } } protected virtual double RevolutionsPerSecondTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -48,6 +50,7 @@ public abstract partial class RotationalSpeedTestsBase public void RevolutionPerSecondToRotationalSpeedUnits() { RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1); + Assert.AreEqual(RadiansPerSecondInOneRevolutionPerSecond, revolutionpersecond.RadiansPerSecond, RadiansPerSecondTolerance); Assert.AreEqual(RevolutionsPerMinuteInOneRevolutionPerSecond, revolutionpersecond.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); Assert.AreEqual(RevolutionsPerSecondInOneRevolutionPerSecond, revolutionpersecond.RevolutionsPerSecond, RevolutionsPerSecondTolerance); } @@ -55,6 +58,7 @@ public void RevolutionPerSecondToRotationalSpeedUnits() [Test] public void FromValueAndUnit() { + Assert.AreEqual(1, RotationalSpeed.From(1, RotationalSpeedUnit.RadianPerSecond).RadiansPerSecond, RadiansPerSecondTolerance); Assert.AreEqual(1, RotationalSpeed.From(1, RotationalSpeedUnit.RevolutionPerMinute).RevolutionsPerMinute, RevolutionsPerMinuteTolerance); Assert.AreEqual(1, RotationalSpeed.From(1, RotationalSpeedUnit.RevolutionPerSecond).RevolutionsPerSecond, RevolutionsPerSecondTolerance); } @@ -63,6 +67,7 @@ public void FromValueAndUnit() public void As() { var revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1); + Assert.AreEqual(RadiansPerSecondInOneRevolutionPerSecond, revolutionpersecond.As(RotationalSpeedUnit.RadianPerSecond), RadiansPerSecondTolerance); Assert.AreEqual(RevolutionsPerMinuteInOneRevolutionPerSecond, revolutionpersecond.As(RotationalSpeedUnit.RevolutionPerMinute), RevolutionsPerMinuteTolerance); Assert.AreEqual(RevolutionsPerSecondInOneRevolutionPerSecond, revolutionpersecond.As(RotationalSpeedUnit.RevolutionPerSecond), RevolutionsPerSecondTolerance); } @@ -71,6 +76,7 @@ public void As() public void ConversionRoundTrip() { RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1); + Assert.AreEqual(1, RotationalSpeed.FromRadiansPerSecond(revolutionpersecond.RadiansPerSecond).RevolutionsPerSecond, RadiansPerSecondTolerance); Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerMinute(revolutionpersecond.RevolutionsPerMinute).RevolutionsPerSecond, RevolutionsPerMinuteTolerance); Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerSecond(revolutionpersecond.RevolutionsPerSecond).RevolutionsPerSecond, RevolutionsPerSecondTolerance); } diff --git a/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs new file mode 100644 index 0000000000..b1a8db42f3 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs @@ -0,0 +1,209 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using NUnit.Framework; +using UnitsNet.Units; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of SpecificEnergy. + /// + [TestFixture] +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class SpecificEnergyTestsBase + { + protected abstract double CaloriesPerGramInOneJoulePerKilogram { get; } + protected abstract double JoulesPerKilogramInOneJoulePerKilogram { get; } + protected abstract double KilocaloriesPerGramInOneJoulePerKilogram { get; } + protected abstract double KilojoulesPerKilogramInOneJoulePerKilogram { get; } + protected abstract double KilowattHoursPerKilogramInOneJoulePerKilogram { get; } + protected abstract double MegajoulesPerKilogramInOneJoulePerKilogram { get; } + protected abstract double MegawattHoursPerKilogramInOneJoulePerKilogram { get; } + protected abstract double WattHoursPerKilogramInOneJoulePerKilogram { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double CaloriesPerGramTolerance { get { return 1e-5; } } + protected virtual double JoulesPerKilogramTolerance { get { return 1e-5; } } + protected virtual double KilocaloriesPerGramTolerance { get { return 1e-5; } } + protected virtual double KilojoulesPerKilogramTolerance { get { return 1e-5; } } + protected virtual double KilowattHoursPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MegajoulesPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MegawattHoursPerKilogramTolerance { get { return 1e-5; } } + protected virtual double WattHoursPerKilogramTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Test] + public void JoulePerKilogramToSpecificEnergyUnits() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.AreEqual(CaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.CaloriesPerGram, CaloriesPerGramTolerance); + Assert.AreEqual(JoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(KilocaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.KilocaloriesPerGram, KilocaloriesPerGramTolerance); + Assert.AreEqual(KilojoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); + Assert.AreEqual(KilowattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); + Assert.AreEqual(MegajoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); + Assert.AreEqual(MegawattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); + Assert.AreEqual(WattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.WattHoursPerKilogram, WattHoursPerKilogramTolerance); + } + + [Test] + public void FromValueAndUnit() + { + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.CaloriePerGram).CaloriesPerGram, CaloriesPerGramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.JoulePerKilogram).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilocaloriePerGram).KilocaloriesPerGram, KilocaloriesPerGramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilojoulePerKilogram).KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilowattHourPerKilogram).KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.MegajoulePerKilogram).MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.MegawattHourPerKilogram).MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.From(1, SpecificEnergyUnit.WattHourPerKilogram).WattHoursPerKilogram, WattHoursPerKilogramTolerance); + } + + [Test] + public void As() + { + var jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.AreEqual(CaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.CaloriePerGram), CaloriesPerGramTolerance); + Assert.AreEqual(JoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.JoulePerKilogram), JoulesPerKilogramTolerance); + Assert.AreEqual(KilocaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilocaloriePerGram), KilocaloriesPerGramTolerance); + Assert.AreEqual(KilojoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilojoulePerKilogram), KilojoulesPerKilogramTolerance); + Assert.AreEqual(KilowattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilowattHourPerKilogram), KilowattHoursPerKilogramTolerance); + Assert.AreEqual(MegajoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.MegajoulePerKilogram), MegajoulesPerKilogramTolerance); + Assert.AreEqual(MegawattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.MegawattHourPerKilogram), MegawattHoursPerKilogramTolerance); + Assert.AreEqual(WattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.WattHourPerKilogram), WattHoursPerKilogramTolerance); + } + + [Test] + public void ConversionRoundTrip() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.AreEqual(1, SpecificEnergy.FromCaloriesPerGram(jouleperkilogram.CaloriesPerGram).JoulesPerKilogram, CaloriesPerGramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromJoulesPerKilogram(jouleperkilogram.JoulesPerKilogram).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromKilocaloriesPerGram(jouleperkilogram.KilocaloriesPerGram).JoulesPerKilogram, KilocaloriesPerGramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromKilojoulesPerKilogram(jouleperkilogram.KilojoulesPerKilogram).JoulesPerKilogram, KilojoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromKilowattHoursPerKilogram(jouleperkilogram.KilowattHoursPerKilogram).JoulesPerKilogram, KilowattHoursPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromMegajoulesPerKilogram(jouleperkilogram.MegajoulesPerKilogram).JoulesPerKilogram, MegajoulesPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromMegawattHoursPerKilogram(jouleperkilogram.MegawattHoursPerKilogram).JoulesPerKilogram, MegawattHoursPerKilogramTolerance); + Assert.AreEqual(1, SpecificEnergy.FromWattHoursPerKilogram(jouleperkilogram.WattHoursPerKilogram).JoulesPerKilogram, WattHoursPerKilogramTolerance); + } + + [Test] + public void ArithmeticOperators() + { + SpecificEnergy v = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.AreEqual(-1, -v.JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(2, (SpecificEnergy.FromJoulesPerKilogram(3)-v).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(2, (v + v).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(10, (v*10).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(10, (10*v).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(2, (SpecificEnergy.FromJoulesPerKilogram(10)/5).JoulesPerKilogram, JoulesPerKilogramTolerance); + Assert.AreEqual(2, SpecificEnergy.FromJoulesPerKilogram(10)/SpecificEnergy.FromJoulesPerKilogram(5), JoulesPerKilogramTolerance); + } + + [Test] + public void ComparisonOperators() + { + SpecificEnergy oneJoulePerKilogram = SpecificEnergy.FromJoulesPerKilogram(1); + SpecificEnergy twoJoulesPerKilogram = SpecificEnergy.FromJoulesPerKilogram(2); + + Assert.True(oneJoulePerKilogram < twoJoulesPerKilogram); + Assert.True(oneJoulePerKilogram <= twoJoulesPerKilogram); + Assert.True(twoJoulesPerKilogram > oneJoulePerKilogram); + Assert.True(twoJoulesPerKilogram >= oneJoulePerKilogram); + + Assert.False(oneJoulePerKilogram > twoJoulesPerKilogram); + Assert.False(oneJoulePerKilogram >= twoJoulesPerKilogram); + Assert.False(twoJoulesPerKilogram < oneJoulePerKilogram); + Assert.False(twoJoulesPerKilogram <= oneJoulePerKilogram); + } + + [Test] + public void CompareToIsImplemented() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.AreEqual(0, jouleperkilogram.CompareTo(jouleperkilogram)); + Assert.Greater(jouleperkilogram.CompareTo(SpecificEnergy.Zero), 0); + Assert.Less(SpecificEnergy.Zero.CompareTo(jouleperkilogram), 0); + } + + [Test] + [ExpectedException(typeof(ArgumentException))] + public void CompareToThrowsOnTypeMismatch() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + jouleperkilogram.CompareTo(new object()); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void CompareToThrowsOnNull() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + jouleperkilogram.CompareTo(null); + } + + + [Test] + public void EqualityOperators() + { + SpecificEnergy a = SpecificEnergy.FromJoulesPerKilogram(1); + SpecificEnergy b = SpecificEnergy.FromJoulesPerKilogram(2); + +// ReSharper disable EqualExpressionComparison + Assert.True(a == a); + Assert.True(a != b); + + Assert.False(a == b); + Assert.False(a != a); +// ReSharper restore EqualExpressionComparison + } + + [Test] + public void EqualsIsImplemented() + { + SpecificEnergy v = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.IsTrue(v.Equals(SpecificEnergy.FromJoulesPerKilogram(1))); + Assert.IsFalse(v.Equals(SpecificEnergy.Zero)); + } + + [Test] + public void EqualsReturnsFalseOnTypeMismatch() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.IsFalse(jouleperkilogram.Equals(new object())); + } + + [Test] + public void EqualsReturnsFalseOnNull() + { + SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); + Assert.IsFalse(jouleperkilogram.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs index dd6ef76e1f..39839231d8 100644 --- a/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs @@ -42,6 +42,7 @@ public abstract partial class SpeedTestsBase protected abstract double KilometersPerHourInOneMeterPerSecond { get; } protected abstract double KilometersPerSecondInOneMeterPerSecond { get; } protected abstract double KnotsInOneMeterPerSecond { get; } + protected abstract double MetersPerHourInOneMeterPerSecond { get; } protected abstract double MetersPerSecondInOneMeterPerSecond { get; } protected abstract double MicrometersPerSecondInOneMeterPerSecond { get; } protected abstract double MilesPerHourInOneMeterPerSecond { get; } @@ -55,6 +56,7 @@ public abstract partial class SpeedTestsBase protected virtual double KilometersPerHourTolerance { get { return 1e-5; } } protected virtual double KilometersPerSecondTolerance { get { return 1e-5; } } protected virtual double KnotsTolerance { get { return 1e-5; } } + protected virtual double MetersPerHourTolerance { get { return 1e-5; } } protected virtual double MetersPerSecondTolerance { get { return 1e-5; } } protected virtual double MicrometersPerSecondTolerance { get { return 1e-5; } } protected virtual double MilesPerHourTolerance { get { return 1e-5; } } @@ -72,6 +74,7 @@ public void MeterPerSecondToSpeedUnits() Assert.AreEqual(KilometersPerHourInOneMeterPerSecond, meterpersecond.KilometersPerHour, KilometersPerHourTolerance); Assert.AreEqual(KilometersPerSecondInOneMeterPerSecond, meterpersecond.KilometersPerSecond, KilometersPerSecondTolerance); Assert.AreEqual(KnotsInOneMeterPerSecond, meterpersecond.Knots, KnotsTolerance); + Assert.AreEqual(MetersPerHourInOneMeterPerSecond, meterpersecond.MetersPerHour, MetersPerHourTolerance); Assert.AreEqual(MetersPerSecondInOneMeterPerSecond, meterpersecond.MetersPerSecond, MetersPerSecondTolerance); Assert.AreEqual(MicrometersPerSecondInOneMeterPerSecond, meterpersecond.MicrometersPerSecond, MicrometersPerSecondTolerance); Assert.AreEqual(MilesPerHourInOneMeterPerSecond, meterpersecond.MilesPerHour, MilesPerHourTolerance); @@ -88,6 +91,7 @@ public void FromValueAndUnit() Assert.AreEqual(1, Speed.From(1, SpeedUnit.KilometerPerHour).KilometersPerHour, KilometersPerHourTolerance); Assert.AreEqual(1, Speed.From(1, SpeedUnit.KilometerPerSecond).KilometersPerSecond, KilometersPerSecondTolerance); Assert.AreEqual(1, Speed.From(1, SpeedUnit.Knot).Knots, KnotsTolerance); + Assert.AreEqual(1, Speed.From(1, SpeedUnit.MeterPerHour).MetersPerHour, MetersPerHourTolerance); Assert.AreEqual(1, Speed.From(1, SpeedUnit.MeterPerSecond).MetersPerSecond, MetersPerSecondTolerance); Assert.AreEqual(1, Speed.From(1, SpeedUnit.MicrometerPerSecond).MicrometersPerSecond, MicrometersPerSecondTolerance); Assert.AreEqual(1, Speed.From(1, SpeedUnit.MilePerHour).MilesPerHour, MilesPerHourTolerance); @@ -105,6 +109,7 @@ public void As() Assert.AreEqual(KilometersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.KilometerPerHour), KilometersPerHourTolerance); Assert.AreEqual(KilometersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.KilometerPerSecond), KilometersPerSecondTolerance); Assert.AreEqual(KnotsInOneMeterPerSecond, meterpersecond.As(SpeedUnit.Knot), KnotsTolerance); + Assert.AreEqual(MetersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MeterPerHour), MetersPerHourTolerance); Assert.AreEqual(MetersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MeterPerSecond), MetersPerSecondTolerance); Assert.AreEqual(MicrometersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MicrometerPerSecond), MicrometersPerSecondTolerance); Assert.AreEqual(MilesPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MilePerHour), MilesPerHourTolerance); @@ -122,6 +127,7 @@ public void ConversionRoundTrip() Assert.AreEqual(1, Speed.FromKilometersPerHour(meterpersecond.KilometersPerHour).MetersPerSecond, KilometersPerHourTolerance); Assert.AreEqual(1, Speed.FromKilometersPerSecond(meterpersecond.KilometersPerSecond).MetersPerSecond, KilometersPerSecondTolerance); Assert.AreEqual(1, Speed.FromKnots(meterpersecond.Knots).MetersPerSecond, KnotsTolerance); + Assert.AreEqual(1, Speed.FromMetersPerHour(meterpersecond.MetersPerHour).MetersPerSecond, MetersPerHourTolerance); Assert.AreEqual(1, Speed.FromMetersPerSecond(meterpersecond.MetersPerSecond).MetersPerSecond, MetersPerSecondTolerance); Assert.AreEqual(1, Speed.FromMicrometersPerSecond(meterpersecond.MicrometersPerSecond).MetersPerSecond, MicrometersPerSecondTolerance); Assert.AreEqual(1, Speed.FromMilesPerHour(meterpersecond.MilesPerHour).MetersPerSecond, MilesPerHourTolerance); diff --git a/UnitsNet/GeneratedCode/Enums/AngleUnit.g.cs b/UnitsNet/GeneratedCode/Enums/AngleUnit.g.cs index 83d7b5b74f..dd3c5a6ed7 100644 --- a/UnitsNet/GeneratedCode/Enums/AngleUnit.g.cs +++ b/UnitsNet/GeneratedCode/Enums/AngleUnit.g.cs @@ -25,6 +25,8 @@ namespace UnitsNet.Units public enum AngleUnit { Undefined = 0, + Arcminute, + Arcsecond, Degree, Gradian, Radian, diff --git a/UnitsNet/GeneratedCode/Enums/FrequencyUnit.g.cs b/UnitsNet/GeneratedCode/Enums/FrequencyUnit.g.cs index 7cf8436567..b2e4420ac7 100644 --- a/UnitsNet/GeneratedCode/Enums/FrequencyUnit.g.cs +++ b/UnitsNet/GeneratedCode/Enums/FrequencyUnit.g.cs @@ -31,6 +31,7 @@ public enum FrequencyUnit Hertz, Kilohertz, Megahertz, + RadianPerSecond, Terahertz, } } diff --git a/UnitsNet/GeneratedCode/Enums/LengthUnit.g.cs b/UnitsNet/GeneratedCode/Enums/LengthUnit.g.cs index 1136b3d77b..3991e1c3eb 100644 --- a/UnitsNet/GeneratedCode/Enums/LengthUnit.g.cs +++ b/UnitsNet/GeneratedCode/Enums/LengthUnit.g.cs @@ -37,6 +37,7 @@ public enum LengthUnit Mile, Millimeter, Nanometer, + NauticalMile, Yard, } } diff --git a/UnitsNet/GeneratedCode/Enums/MassFlowUnit.g.cs b/UnitsNet/GeneratedCode/Enums/MassFlowUnit.g.cs new file mode 100644 index 0000000000..a5e9c951ce --- /dev/null +++ b/UnitsNet/GeneratedCode/Enums/MassFlowUnit.g.cs @@ -0,0 +1,31 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + public enum MassFlowUnit + { + Undefined = 0, + KilogramPerSecond, + TonnePerDay, + } +} diff --git a/UnitsNet/GeneratedCode/Enums/RotationalSpeedUnit.g.cs b/UnitsNet/GeneratedCode/Enums/RotationalSpeedUnit.g.cs index 6a585982ab..7f17328fd8 100644 --- a/UnitsNet/GeneratedCode/Enums/RotationalSpeedUnit.g.cs +++ b/UnitsNet/GeneratedCode/Enums/RotationalSpeedUnit.g.cs @@ -25,6 +25,7 @@ namespace UnitsNet.Units public enum RotationalSpeedUnit { Undefined = 0, + RadianPerSecond, RevolutionPerMinute, RevolutionPerSecond, } diff --git a/UnitsNet/GeneratedCode/Enums/SpecificEnergyUnit.g.cs b/UnitsNet/GeneratedCode/Enums/SpecificEnergyUnit.g.cs new file mode 100644 index 0000000000..f20d5d3a71 --- /dev/null +++ b/UnitsNet/GeneratedCode/Enums/SpecificEnergyUnit.g.cs @@ -0,0 +1,37 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + public enum SpecificEnergyUnit + { + Undefined = 0, + CaloriePerGram, + JoulePerKilogram, + KilocaloriePerGram, + KilojoulePerKilogram, + KilowattHourPerKilogram, + MegajoulePerKilogram, + MegawattHourPerKilogram, + WattHourPerKilogram, + } +} diff --git a/UnitsNet/GeneratedCode/Enums/SpeedUnit.g.cs b/UnitsNet/GeneratedCode/Enums/SpeedUnit.g.cs index dc69664c6e..85d89edaa5 100644 --- a/UnitsNet/GeneratedCode/Enums/SpeedUnit.g.cs +++ b/UnitsNet/GeneratedCode/Enums/SpeedUnit.g.cs @@ -31,6 +31,7 @@ public enum SpeedUnit KilometerPerHour, KilometerPerSecond, Knot, + MeterPerHour, MeterPerSecond, MicrometerPerSecond, MilePerHour, diff --git a/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs index 1c948afbc3..e1249c9a44 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs @@ -54,6 +54,22 @@ public static AngleUnit BaseUnit get { return AngleUnit.Degree; } } + /// + /// Get Angle in Arcminutes. + /// + public double Arcminutes + { + get { return _degrees*60; } + } + + /// + /// Get Angle in Arcseconds. + /// + public double Arcseconds + { + get { return _degrees*3600; } + } + /// /// Get Angle in Degrees. /// @@ -87,6 +103,22 @@ public static Angle Zero get { return new Angle(); } } + /// + /// Get Angle from Arcminutes. + /// + public static Angle FromArcminutes(double arcminutes) + { + return new Angle(arcminutes/60); + } + + /// + /// Get Angle from Arcseconds. + /// + public static Angle FromArcseconds(double arcseconds) + { + return new Angle(arcseconds/3600); + } + /// /// Get Angle from Degrees. /// @@ -122,6 +154,10 @@ public static Angle From(double value, AngleUnit fromUnit) { switch (fromUnit) { + case AngleUnit.Arcminute: + return FromArcminutes(value); + case AngleUnit.Arcsecond: + return FromArcseconds(value); case AngleUnit.Degree: return FromDegrees(value); case AngleUnit.Gradian: @@ -261,6 +297,10 @@ public double As(AngleUnit unit) { switch (unit) { + case AngleUnit.Arcminute: + return Arcminutes; + case AngleUnit.Arcsecond: + return Arcseconds; case AngleUnit.Degree: return Degrees; case AngleUnit.Gradian: diff --git a/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs index 7912df891c..d089c4aa5e 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs @@ -102,6 +102,14 @@ public double Megahertz get { return (_hertz) / 1e6d; } } + /// + /// Get Frequency in RadiansPerSecond. + /// + public double RadiansPerSecond + { + get { return _hertz*6.2831853072; } + } + /// /// Get Frequency in Terahertz. /// @@ -167,6 +175,14 @@ public static Frequency FromMegahertz(double megahertz) return new Frequency((megahertz) * 1e6d); } + /// + /// Get Frequency from RadiansPerSecond. + /// + public static Frequency FromRadiansPerSecond(double radianspersecond) + { + return new Frequency(radianspersecond/6.2831853072); + } + /// /// Get Frequency from Terahertz. /// @@ -198,6 +214,8 @@ public static Frequency From(double value, FrequencyUnit fromUnit) return FromKilohertz(value); case FrequencyUnit.Megahertz: return FromMegahertz(value); + case FrequencyUnit.RadianPerSecond: + return FromRadiansPerSecond(value); case FrequencyUnit.Terahertz: return FromTerahertz(value); @@ -345,6 +363,8 @@ public double As(FrequencyUnit unit) return Kilohertz; case FrequencyUnit.Megahertz: return Megahertz; + case FrequencyUnit.RadianPerSecond: + return RadiansPerSecond; case FrequencyUnit.Terahertz: return Terahertz; diff --git a/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs index a39fff52a8..5a74f3bd41 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs @@ -150,6 +150,14 @@ public double Nanometers get { return (_meters) / 1e-9d; } } + /// + /// Get Length in NauticalMiles. + /// + public double NauticalMiles + { + get { return _meters/1852; } + } + /// /// Get Length in Yards. /// @@ -263,6 +271,14 @@ public static Length FromNanometers(double nanometers) return new Length((nanometers) * 1e-9d); } + /// + /// Get Length from NauticalMiles. + /// + public static Length FromNauticalMiles(double nauticalmiles) + { + return new Length(nauticalmiles*1852); + } + /// /// Get Length from Yards. /// @@ -306,6 +322,8 @@ public static Length From(double value, LengthUnit fromUnit) return FromMillimeters(value); case LengthUnit.Nanometer: return FromNanometers(value); + case LengthUnit.NauticalMile: + return FromNauticalMiles(value); case LengthUnit.Yard: return FromYards(value); @@ -465,6 +483,8 @@ public double As(LengthUnit unit) return Millimeters; case LengthUnit.Nanometer: return Nanometers; + case LengthUnit.NauticalMile: + return NauticalMiles; case LengthUnit.Yard: return Yards; diff --git a/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs b/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs new file mode 100644 index 0000000000..c873a47a41 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs @@ -0,0 +1,412 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// + // ReSharper disable once PartialTypeWithSinglePart + public partial struct MassFlow : IComparable, IComparable + { + /// + /// Base unit of MassFlow. + /// + private readonly double _kilogramsPerSecond; + + public MassFlow(double kilogramspersecond) : this() + { + _kilogramsPerSecond = kilogramspersecond; + } + + #region Properties + + public static MassFlowUnit BaseUnit + { + get { return MassFlowUnit.KilogramPerSecond; } + } + + /// + /// Get MassFlow in KilogramsPerSecond. + /// + public double KilogramsPerSecond + { + get { return _kilogramsPerSecond; } + } + + /// + /// Get MassFlow in TonnesPerDay. + /// + public double TonnesPerDay + { + get { return _kilogramsPerSecond*86.4000; } + } + + #endregion + + #region Static + + public static MassFlow Zero + { + get { return new MassFlow(); } + } + + /// + /// Get MassFlow from KilogramsPerSecond. + /// + public static MassFlow FromKilogramsPerSecond(double kilogramspersecond) + { + return new MassFlow(kilogramspersecond); + } + + /// + /// Get MassFlow from TonnesPerDay. + /// + public static MassFlow FromTonnesPerDay(double tonnesperday) + { + return new MassFlow(tonnesperday/86.4000); + } + + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFlow unit value. + public static MassFlow From(double value, MassFlowUnit fromUnit) + { + switch (fromUnit) + { + case MassFlowUnit.KilogramPerSecond: + return FromKilogramsPerSecond(value); + case MassFlowUnit.TonnePerDay: + return FromTonnesPerDay(value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Culture to use for localization. Defaults to Thread.CurrentUICulture. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(MassFlowUnit unit, CultureInfo culture = null) + { + return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit); + } + + #endregion + + #region Arithmetic Operators + + public static MassFlow operator -(MassFlow right) + { + return new MassFlow(-right._kilogramsPerSecond); + } + + public static MassFlow operator +(MassFlow left, MassFlow right) + { + return new MassFlow(left._kilogramsPerSecond + right._kilogramsPerSecond); + } + + public static MassFlow operator -(MassFlow left, MassFlow right) + { + return new MassFlow(left._kilogramsPerSecond - right._kilogramsPerSecond); + } + + public static MassFlow operator *(double left, MassFlow right) + { + return new MassFlow(left*right._kilogramsPerSecond); + } + + public static MassFlow operator *(MassFlow left, double right) + { + return new MassFlow(left._kilogramsPerSecond*(double)right); + } + + public static MassFlow operator /(MassFlow left, double right) + { + return new MassFlow(left._kilogramsPerSecond/(double)right); + } + + public static double operator /(MassFlow left, MassFlow right) + { + return Convert.ToDouble(left._kilogramsPerSecond/right._kilogramsPerSecond); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is MassFlow)) throw new ArgumentException("Expected type MassFlow.", "obj"); + return CompareTo((MassFlow) obj); + } + + public int CompareTo(MassFlow other) + { + return _kilogramsPerSecond.CompareTo(other._kilogramsPerSecond); + } + + public static bool operator <=(MassFlow left, MassFlow right) + { + return left._kilogramsPerSecond <= right._kilogramsPerSecond; + } + + public static bool operator >=(MassFlow left, MassFlow right) + { + return left._kilogramsPerSecond >= right._kilogramsPerSecond; + } + + public static bool operator <(MassFlow left, MassFlow right) + { + return left._kilogramsPerSecond < right._kilogramsPerSecond; + } + + public static bool operator >(MassFlow left, MassFlow right) + { + return left._kilogramsPerSecond > right._kilogramsPerSecond; + } + + public static bool operator ==(MassFlow left, MassFlow right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._kilogramsPerSecond == right._kilogramsPerSecond; + } + + public static bool operator !=(MassFlow left, MassFlow right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._kilogramsPerSecond != right._kilogramsPerSecond; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _kilogramsPerSecond.Equals(((MassFlow) obj)._kilogramsPerSecond); + } + + public override int GetHashCode() + { + return _kilogramsPerSecond.GetHashCode(); + } + + #endregion + + #region Conversion + + /// + /// Convert to the unit representation . + /// + /// Value in new unit if successful, exception otherwise. + /// If conversion was not successful. + public double As(MassFlowUnit unit) + { + switch (unit) + { + case MassFlowUnit.KilogramPerSecond: + return KilogramsPerSecond; + case MassFlowUnit.TonnePerDay: + return TonnesPerDay; + + default: + throw new NotImplementedException("unit: " + unit); + } + } + + #endregion + + #region Parsing + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + public static MassFlow Parse(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + + var numFormat = formatProvider != null ? + (NumberFormatInfo) formatProvider.GetFormat(typeof (NumberFormatInfo)) : + NumberFormatInfo.CurrentInfo; + + var numRegex = string.Format(@"[\d., {0}{1}]*\d", // allows digits, dots, commas, and spaces in the quantity (must end in digit) + numFormat.NumberGroupSeparator, // adds provided (or current) culture's group separator + numFormat.NumberDecimalSeparator); // adds provided (or current) culture's decimal separator + var exponentialRegex = @"(?:[eE][-+]?\d+)?)"; + var regexString = string.Format(@"(?:\s*(?[-+]?{0}{1}{2}{3})?{4}{5}", + numRegex, // capture base (integral) Quantity value + exponentialRegex, // capture exponential (if any), end of Quantity capturing + @"\s?", // ignore whitespace (allows both "1kg", "1 kg") + @"(?[^\s\d,]+)", // capture Unit (non-whitespace) input + @"(and)?,?", // allow "and" & "," separators between quantities + @"(?[a-z]*)?"); // capture invalid input + + var quantities = ParseWithRegex(regexString, str, formatProvider); + if (quantities.Count == 0) + { + throw new ArgumentException( + "Expected string to have at least one pair of quantity and unit in the format" + + " \"<quantity> <unit>\". Eg. \"5.5 m\" or \"1ft 2in\""); + } + return quantities.Aggregate((x, y) => x + y); + } + + /// + /// Parse a string given a particular regular expression. + /// + /// Error parsing string. + private static List ParseWithRegex(string regexString, string str, IFormatProvider formatProvider = null) + { + var regex = new Regex(regexString); + MatchCollection matches = regex.Matches(str.Trim()); + var converted = new List(); + + foreach (Match match in matches) + { + GroupCollection groups = match.Groups; + + var valueString = groups["value"].Value; + var unitString = groups["unit"].Value; + if (groups["invalid"].Value != "") + { + var newEx = new UnitsNetException("Invalid string detected: " + groups["invalid"].Value); + newEx.Data["input"] = str; + newEx.Data["matched value"] = valueString; + newEx.Data["matched unit"] = unitString; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + if (valueString == "" && unitString == "") continue; + + try + { + MassFlowUnit unit = ParseUnit(unitString, formatProvider); + double value = double.Parse(valueString, formatProvider); + + converted.Add(From(value, unit)); + } + catch (Exception ex) + { + var newEx = new UnitsNetException("Error parsing string.", ex); + newEx.Data["input"] = str; + newEx.Data["matched value"] = valueString; + newEx.Data["matched unit"] = unitString; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + } + return converted; + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassFlowUnit ParseUnit(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + var unitSystem = UnitSystem.GetCached(formatProvider); + + var unit = unitSystem.Parse(str.Trim()); + + if (unit == MassFlowUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized MassFlowUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(MassFlowUnit.KilogramPerSecond); + } + + /// + /// Get string representation of value and unit. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// The number of significant digits after the radix point. + /// String representation. + [UsedImplicitly] + public string ToString(MassFlowUnit unit, CultureInfo culture = null, int significantDigitsAfterRadix = 2) + { + return ToString(unit, culture, UnitFormatter.GetFormat(As(unit), significantDigitsAfterRadix)); + } + + /// + /// Get string representation of value and unit. + /// + /// Culture to use for localization and number formatting. + /// Unit representation to use. + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + [UsedImplicitly] + public string ToString(MassFlowUnit unit, CultureInfo culture, string format, params object[] args) + { + return string.Format(culture, format, UnitFormatter.GetFormatArgs(unit, As(unit), culture, args)); + } + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs index 3186657470..1685378504 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs @@ -54,6 +54,14 @@ public static RotationalSpeedUnit BaseUnit get { return RotationalSpeedUnit.RevolutionPerSecond; } } + /// + /// Get RotationalSpeed in RadiansPerSecond. + /// + public double RadiansPerSecond + { + get { return _revolutionsPerSecond*6.2831853072; } + } + /// /// Get RotationalSpeed in RevolutionsPerMinute. /// @@ -79,6 +87,14 @@ public static RotationalSpeed Zero get { return new RotationalSpeed(); } } + /// + /// Get RotationalSpeed from RadiansPerSecond. + /// + public static RotationalSpeed FromRadiansPerSecond(double radianspersecond) + { + return new RotationalSpeed(radianspersecond/6.2831853072); + } + /// /// Get RotationalSpeed from RevolutionsPerMinute. /// @@ -106,6 +122,8 @@ public static RotationalSpeed From(double value, RotationalSpeedUnit fromUnit) { switch (fromUnit) { + case RotationalSpeedUnit.RadianPerSecond: + return FromRadiansPerSecond(value); case RotationalSpeedUnit.RevolutionPerMinute: return FromRevolutionsPerMinute(value); case RotationalSpeedUnit.RevolutionPerSecond: @@ -243,6 +261,8 @@ public double As(RotationalSpeedUnit unit) { switch (unit) { + case RotationalSpeedUnit.RadianPerSecond: + return RadiansPerSecond; case RotationalSpeedUnit.RevolutionPerMinute: return RevolutionsPerMinute; case RotationalSpeedUnit.RevolutionPerSecond: diff --git a/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs new file mode 100644 index 0000000000..6482241d60 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs @@ -0,0 +1,532 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// The SpecificEnergy + /// + // ReSharper disable once PartialTypeWithSinglePart + public partial struct SpecificEnergy : IComparable, IComparable + { + /// + /// Base unit of SpecificEnergy. + /// + private readonly double _joulesPerKilogram; + + public SpecificEnergy(double joulesperkilogram) : this() + { + _joulesPerKilogram = joulesperkilogram; + } + + #region Properties + + public static SpecificEnergyUnit BaseUnit + { + get { return SpecificEnergyUnit.JoulePerKilogram; } + } + + /// + /// Get SpecificEnergy in CaloriesPerGram. + /// + public double CaloriesPerGram + { + get { return _joulesPerKilogram/4.184e3; } + } + + /// + /// Get SpecificEnergy in JoulesPerKilogram. + /// + public double JoulesPerKilogram + { + get { return _joulesPerKilogram; } + } + + /// + /// Get SpecificEnergy in KilocaloriesPerGram. + /// + public double KilocaloriesPerGram + { + get { return (_joulesPerKilogram/4.184e3) / 1e3d; } + } + + /// + /// Get SpecificEnergy in KilojoulesPerKilogram. + /// + public double KilojoulesPerKilogram + { + get { return (_joulesPerKilogram) / 1e3d; } + } + + /// + /// Get SpecificEnergy in KilowattHoursPerKilogram. + /// + public double KilowattHoursPerKilogram + { + get { return (_joulesPerKilogram/3.6e3) / 1e3d; } + } + + /// + /// Get SpecificEnergy in MegajoulesPerKilogram. + /// + public double MegajoulesPerKilogram + { + get { return (_joulesPerKilogram) / 1e6d; } + } + + /// + /// Get SpecificEnergy in MegawattHoursPerKilogram. + /// + public double MegawattHoursPerKilogram + { + get { return (_joulesPerKilogram/3.6e3) / 1e6d; } + } + + /// + /// Get SpecificEnergy in WattHoursPerKilogram. + /// + public double WattHoursPerKilogram + { + get { return _joulesPerKilogram/3.6e3; } + } + + #endregion + + #region Static + + public static SpecificEnergy Zero + { + get { return new SpecificEnergy(); } + } + + /// + /// Get SpecificEnergy from CaloriesPerGram. + /// + public static SpecificEnergy FromCaloriesPerGram(double caloriespergram) + { + return new SpecificEnergy(caloriespergram*4.184e3); + } + + /// + /// Get SpecificEnergy from JoulesPerKilogram. + /// + public static SpecificEnergy FromJoulesPerKilogram(double joulesperkilogram) + { + return new SpecificEnergy(joulesperkilogram); + } + + /// + /// Get SpecificEnergy from KilocaloriesPerGram. + /// + public static SpecificEnergy FromKilocaloriesPerGram(double kilocaloriespergram) + { + return new SpecificEnergy((kilocaloriespergram*4.184e3) * 1e3d); + } + + /// + /// Get SpecificEnergy from KilojoulesPerKilogram. + /// + public static SpecificEnergy FromKilojoulesPerKilogram(double kilojoulesperkilogram) + { + return new SpecificEnergy((kilojoulesperkilogram) * 1e3d); + } + + /// + /// Get SpecificEnergy from KilowattHoursPerKilogram. + /// + public static SpecificEnergy FromKilowattHoursPerKilogram(double kilowatthoursperkilogram) + { + return new SpecificEnergy((kilowatthoursperkilogram*3.6e3) * 1e3d); + } + + /// + /// Get SpecificEnergy from MegajoulesPerKilogram. + /// + public static SpecificEnergy FromMegajoulesPerKilogram(double megajoulesperkilogram) + { + return new SpecificEnergy((megajoulesperkilogram) * 1e6d); + } + + /// + /// Get SpecificEnergy from MegawattHoursPerKilogram. + /// + public static SpecificEnergy FromMegawattHoursPerKilogram(double megawatthoursperkilogram) + { + return new SpecificEnergy((megawatthoursperkilogram*3.6e3) * 1e6d); + } + + /// + /// Get SpecificEnergy from WattHoursPerKilogram. + /// + public static SpecificEnergy FromWattHoursPerKilogram(double watthoursperkilogram) + { + return new SpecificEnergy(watthoursperkilogram*3.6e3); + } + + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// SpecificEnergy unit value. + public static SpecificEnergy From(double value, SpecificEnergyUnit fromUnit) + { + switch (fromUnit) + { + case SpecificEnergyUnit.CaloriePerGram: + return FromCaloriesPerGram(value); + case SpecificEnergyUnit.JoulePerKilogram: + return FromJoulesPerKilogram(value); + case SpecificEnergyUnit.KilocaloriePerGram: + return FromKilocaloriesPerGram(value); + case SpecificEnergyUnit.KilojoulePerKilogram: + return FromKilojoulesPerKilogram(value); + case SpecificEnergyUnit.KilowattHourPerKilogram: + return FromKilowattHoursPerKilogram(value); + case SpecificEnergyUnit.MegajoulePerKilogram: + return FromMegajoulesPerKilogram(value); + case SpecificEnergyUnit.MegawattHourPerKilogram: + return FromMegawattHoursPerKilogram(value); + case SpecificEnergyUnit.WattHourPerKilogram: + return FromWattHoursPerKilogram(value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Culture to use for localization. Defaults to Thread.CurrentUICulture. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(SpecificEnergyUnit unit, CultureInfo culture = null) + { + return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit); + } + + #endregion + + #region Arithmetic Operators + + public static SpecificEnergy operator -(SpecificEnergy right) + { + return new SpecificEnergy(-right._joulesPerKilogram); + } + + public static SpecificEnergy operator +(SpecificEnergy left, SpecificEnergy right) + { + return new SpecificEnergy(left._joulesPerKilogram + right._joulesPerKilogram); + } + + public static SpecificEnergy operator -(SpecificEnergy left, SpecificEnergy right) + { + return new SpecificEnergy(left._joulesPerKilogram - right._joulesPerKilogram); + } + + public static SpecificEnergy operator *(double left, SpecificEnergy right) + { + return new SpecificEnergy(left*right._joulesPerKilogram); + } + + public static SpecificEnergy operator *(SpecificEnergy left, double right) + { + return new SpecificEnergy(left._joulesPerKilogram*(double)right); + } + + public static SpecificEnergy operator /(SpecificEnergy left, double right) + { + return new SpecificEnergy(left._joulesPerKilogram/(double)right); + } + + public static double operator /(SpecificEnergy left, SpecificEnergy right) + { + return Convert.ToDouble(left._joulesPerKilogram/right._joulesPerKilogram); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is SpecificEnergy)) throw new ArgumentException("Expected type SpecificEnergy.", "obj"); + return CompareTo((SpecificEnergy) obj); + } + + public int CompareTo(SpecificEnergy other) + { + return _joulesPerKilogram.CompareTo(other._joulesPerKilogram); + } + + public static bool operator <=(SpecificEnergy left, SpecificEnergy right) + { + return left._joulesPerKilogram <= right._joulesPerKilogram; + } + + public static bool operator >=(SpecificEnergy left, SpecificEnergy right) + { + return left._joulesPerKilogram >= right._joulesPerKilogram; + } + + public static bool operator <(SpecificEnergy left, SpecificEnergy right) + { + return left._joulesPerKilogram < right._joulesPerKilogram; + } + + public static bool operator >(SpecificEnergy left, SpecificEnergy right) + { + return left._joulesPerKilogram > right._joulesPerKilogram; + } + + public static bool operator ==(SpecificEnergy left, SpecificEnergy right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._joulesPerKilogram == right._joulesPerKilogram; + } + + public static bool operator !=(SpecificEnergy left, SpecificEnergy right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._joulesPerKilogram != right._joulesPerKilogram; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _joulesPerKilogram.Equals(((SpecificEnergy) obj)._joulesPerKilogram); + } + + public override int GetHashCode() + { + return _joulesPerKilogram.GetHashCode(); + } + + #endregion + + #region Conversion + + /// + /// Convert to the unit representation . + /// + /// Value in new unit if successful, exception otherwise. + /// If conversion was not successful. + public double As(SpecificEnergyUnit unit) + { + switch (unit) + { + case SpecificEnergyUnit.CaloriePerGram: + return CaloriesPerGram; + case SpecificEnergyUnit.JoulePerKilogram: + return JoulesPerKilogram; + case SpecificEnergyUnit.KilocaloriePerGram: + return KilocaloriesPerGram; + case SpecificEnergyUnit.KilojoulePerKilogram: + return KilojoulesPerKilogram; + case SpecificEnergyUnit.KilowattHourPerKilogram: + return KilowattHoursPerKilogram; + case SpecificEnergyUnit.MegajoulePerKilogram: + return MegajoulesPerKilogram; + case SpecificEnergyUnit.MegawattHourPerKilogram: + return MegawattHoursPerKilogram; + case SpecificEnergyUnit.WattHourPerKilogram: + return WattHoursPerKilogram; + + default: + throw new NotImplementedException("unit: " + unit); + } + } + + #endregion + + #region Parsing + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + public static SpecificEnergy Parse(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + + var numFormat = formatProvider != null ? + (NumberFormatInfo) formatProvider.GetFormat(typeof (NumberFormatInfo)) : + NumberFormatInfo.CurrentInfo; + + var numRegex = string.Format(@"[\d., {0}{1}]*\d", // allows digits, dots, commas, and spaces in the quantity (must end in digit) + numFormat.NumberGroupSeparator, // adds provided (or current) culture's group separator + numFormat.NumberDecimalSeparator); // adds provided (or current) culture's decimal separator + var exponentialRegex = @"(?:[eE][-+]?\d+)?)"; + var regexString = string.Format(@"(?:\s*(?[-+]?{0}{1}{2}{3})?{4}{5}", + numRegex, // capture base (integral) Quantity value + exponentialRegex, // capture exponential (if any), end of Quantity capturing + @"\s?", // ignore whitespace (allows both "1kg", "1 kg") + @"(?[^\s\d,]+)", // capture Unit (non-whitespace) input + @"(and)?,?", // allow "and" & "," separators between quantities + @"(?[a-z]*)?"); // capture invalid input + + var quantities = ParseWithRegex(regexString, str, formatProvider); + if (quantities.Count == 0) + { + throw new ArgumentException( + "Expected string to have at least one pair of quantity and unit in the format" + + " \"<quantity> <unit>\". Eg. \"5.5 m\" or \"1ft 2in\""); + } + return quantities.Aggregate((x, y) => x + y); + } + + /// + /// Parse a string given a particular regular expression. + /// + /// Error parsing string. + private static List ParseWithRegex(string regexString, string str, IFormatProvider formatProvider = null) + { + var regex = new Regex(regexString); + MatchCollection matches = regex.Matches(str.Trim()); + var converted = new List(); + + foreach (Match match in matches) + { + GroupCollection groups = match.Groups; + + var valueString = groups["value"].Value; + var unitString = groups["unit"].Value; + if (groups["invalid"].Value != "") + { + var newEx = new UnitsNetException("Invalid string detected: " + groups["invalid"].Value); + newEx.Data["input"] = str; + newEx.Data["matched value"] = valueString; + newEx.Data["matched unit"] = unitString; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + if (valueString == "" && unitString == "") continue; + + try + { + SpecificEnergyUnit unit = ParseUnit(unitString, formatProvider); + double value = double.Parse(valueString, formatProvider); + + converted.Add(From(value, unit)); + } + catch (Exception ex) + { + var newEx = new UnitsNetException("Error parsing string.", ex); + newEx.Data["input"] = str; + newEx.Data["matched value"] = valueString; + newEx.Data["matched unit"] = unitString; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + } + return converted; + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static SpecificEnergyUnit ParseUnit(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + var unitSystem = UnitSystem.GetCached(formatProvider); + + var unit = unitSystem.Parse(str.Trim()); + + if (unit == SpecificEnergyUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized SpecificEnergyUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString(); + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(SpecificEnergyUnit.JoulePerKilogram); + } + + /// + /// Get string representation of value and unit. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// The number of significant digits after the radix point. + /// String representation. + [UsedImplicitly] + public string ToString(SpecificEnergyUnit unit, CultureInfo culture = null, int significantDigitsAfterRadix = 2) + { + return ToString(unit, culture, UnitFormatter.GetFormat(As(unit), significantDigitsAfterRadix)); + } + + /// + /// Get string representation of value and unit. + /// + /// Culture to use for localization and number formatting. + /// Unit representation to use. + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + [UsedImplicitly] + public string ToString(SpecificEnergyUnit unit, CultureInfo culture, string format, params object[] args) + { + return string.Format(culture, format, UnitFormatter.GetFormatArgs(unit, As(unit), culture, args)); + } + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs index 5ea3ebcd58..3d5e211df1 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs @@ -102,6 +102,14 @@ public double Knots get { return _metersPerSecond/0.514444; } } + /// + /// Get Speed in MetersPerHour. + /// + public double MetersPerHour + { + get { return _metersPerSecond*3600; } + } + /// /// Get Speed in MetersPerSecond. /// @@ -199,6 +207,14 @@ public static Speed FromKnots(double knots) return new Speed(knots*0.514444); } + /// + /// Get Speed from MetersPerHour. + /// + public static Speed FromMetersPerHour(double metersperhour) + { + return new Speed(metersperhour/3600); + } + /// /// Get Speed from MetersPerSecond. /// @@ -262,6 +278,8 @@ public static Speed From(double value, SpeedUnit fromUnit) return FromKilometersPerSecond(value); case SpeedUnit.Knot: return FromKnots(value); + case SpeedUnit.MeterPerHour: + return FromMetersPerHour(value); case SpeedUnit.MeterPerSecond: return FromMetersPerSecond(value); case SpeedUnit.MicrometerPerSecond: @@ -417,6 +435,8 @@ public double As(SpeedUnit unit) return KilometersPerSecond; case SpeedUnit.Knot: return Knots; + case SpeedUnit.MeterPerHour: + return MetersPerHour; case SpeedUnit.MeterPerSecond: return MetersPerSecond; case SpeedUnit.MicrometerPerSecond: diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 4b614a858b..b3bed178e0 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -95,6 +95,16 @@ private static readonly ReadOnlyCollection DefaultLocalization new UnitLocalization(typeof (AngleUnit), new[] { + new CulturesForEnumValue((int) AngleUnit.Arcminute, + new[] + { + new AbbreviationsForCulture("en-US", "'", "arcmin", "amin", "min"), + }), + new CulturesForEnumValue((int) AngleUnit.Arcsecond, + new[] + { + new AbbreviationsForCulture("en-US", "″", "arcsec", "asec", "sec"), + }), new CulturesForEnumValue((int) AngleUnit.Degree, new[] { @@ -558,6 +568,11 @@ private static readonly ReadOnlyCollection DefaultLocalization { new AbbreviationsForCulture("en-US", "MHz"), }), + new CulturesForEnumValue((int) FrequencyUnit.RadianPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "rad/s"), + }), new CulturesForEnumValue((int) FrequencyUnit.Terahertz, new[] { @@ -825,6 +840,12 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "nm"), new AbbreviationsForCulture("ru-RU", "нм"), }), + new CulturesForEnumValue((int) LengthUnit.NauticalMile, + new[] + { + new AbbreviationsForCulture("en-US", "NM"), + new AbbreviationsForCulture("ru-RU", "мил"), + }), new CulturesForEnumValue((int) LengthUnit.Yard, new[] { @@ -949,6 +970,20 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("ru-RU", "т"), }), }), + new UnitLocalization(typeof (MassFlowUnit), + new[] + { + new CulturesForEnumValue((int) MassFlowUnit.KilogramPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "kg/s"), + }), + new CulturesForEnumValue((int) MassFlowUnit.TonnePerDay, + new[] + { + new AbbreviationsForCulture("en-US", "t/d"), + }), + }), new UnitLocalization(typeof (PowerUnit), new[] { @@ -1279,6 +1314,11 @@ private static readonly ReadOnlyCollection DefaultLocalization new UnitLocalization(typeof (RotationalSpeedUnit), new[] { + new CulturesForEnumValue((int) RotationalSpeedUnit.RadianPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "rad/s"), + }), new CulturesForEnumValue((int) RotationalSpeedUnit.RevolutionPerMinute, new[] { @@ -1292,6 +1332,50 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("ru-RU", "об/с"), }), }), + new UnitLocalization(typeof (SpecificEnergyUnit), + new[] + { + new CulturesForEnumValue((int) SpecificEnergyUnit.CaloriePerGram, + new[] + { + new AbbreviationsForCulture("en-US", "cal/g"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.JoulePerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "J/kg"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.KilocaloriePerGram, + new[] + { + new AbbreviationsForCulture("en-US", "kcal/g"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.KilojoulePerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "kJ/kg"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.KilowattHourPerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "kWh/kg"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.MegajoulePerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "MJ/kg"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.MegawattHourPerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "MWh/kg"), + }), + new CulturesForEnumValue((int) SpecificEnergyUnit.WattHourPerKilogram, + new[] + { + new AbbreviationsForCulture("en-US", "Wh/kg"), + }), + }), new UnitLocalization(typeof (SpecificWeightUnit), new[] { @@ -1409,6 +1493,11 @@ private static readonly ReadOnlyCollection DefaultLocalization { new AbbreviationsForCulture("en-US", "kt", "kn", "knot", "knots"), }), + new CulturesForEnumValue((int) SpeedUnit.MeterPerHour, + new[] + { + new AbbreviationsForCulture("en-US", "m/h"), + }), new CulturesForEnumValue((int) SpeedUnit.MeterPerSecond, new[] { diff --git a/UnitsNet/Scripts/UnitDefinitions/Angle.json b/UnitsNet/Scripts/UnitDefinitions/Angle.json index 5236aba3e5..551b4339d5 100644 --- a/UnitsNet/Scripts/UnitDefinitions/Angle.json +++ b/UnitsNet/Scripts/UnitDefinitions/Angle.json @@ -35,7 +35,31 @@ } ] }, - { + { + "SingularName": "Arcminute", + "PluralName": "Arcminutes", + "FromUnitToBaseFunc": "x/60", + "FromBaseToUnitFunc": "x*60", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["'", "arcmin", "amin", "min"] + } + ] + }, + { + "SingularName": "Arcsecond", + "PluralName": "Arcseconds", + "FromUnitToBaseFunc": "x/3600", + "FromBaseToUnitFunc": "x*3600", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["″", "arcsec", "asec", "sec"] + } + ] + }, + { "SingularName": "Gradian", "PluralName": "Gradians", "FromUnitToBaseFunc": "x*0.9", diff --git a/UnitsNet/Scripts/UnitDefinitions/Frequency.json b/UnitsNet/Scripts/UnitDefinitions/Frequency.json index 667f2d7332..d914f63641 100644 --- a/UnitsNet/Scripts/UnitDefinitions/Frequency.json +++ b/UnitsNet/Scripts/UnitDefinitions/Frequency.json @@ -16,7 +16,19 @@ } ] }, - { + { + "SingularName": "RadianPerSecond", + "PluralName": "RadiansPerSecond", + "FromUnitToBaseFunc": "x/6.2831853072", + "FromBaseToUnitFunc": "x*6.2831853072", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["rad/s"] + } + ] + }, + { "SingularName": "CyclePerMinute", "PluralName": "CyclesPerMinute", "FromUnitToBaseFunc": "x*60", diff --git a/UnitsNet/Scripts/UnitDefinitions/Length.json b/UnitsNet/Scripts/UnitDefinitions/Length.json index 9ad60c4a0b..648bab3fde 100644 --- a/UnitsNet/Scripts/UnitDefinitions/Length.json +++ b/UnitsNet/Scripts/UnitDefinitions/Length.json @@ -101,6 +101,22 @@ } ] }, + { + "SingularName": "NauticalMile", + "PluralName": "NauticalMiles", + "FromUnitToBaseFunc": "x*1852", + "FromBaseToUnitFunc": "x/1852", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["NM"] + }, + { + "Culture": "ru-RU", + "Abbreviations": ["мил"] + } + ] + }, { "SingularName": "Microinch", "PluralName": "Microinches", diff --git a/UnitsNet/Scripts/UnitDefinitions/MassFlow.json b/UnitsNet/Scripts/UnitDefinitions/MassFlow.json new file mode 100644 index 0000000000..3645b8a26a --- /dev/null +++ b/UnitsNet/Scripts/UnitDefinitions/MassFlow.json @@ -0,0 +1,31 @@ +{ + "Name": "MassFlow", + "BaseUnit": "KilogramPerSecond", + "XmlDoc": "", + "Units": [ + { + "SingularName": "KilogramPerSecond", + "PluralName": "KilogramsPerSecond", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["kg/s"] + } + ] + }, + { + "SingularName": "TonnePerDay", + "PluralName": "TonnesPerDay", + "FromUnitToBaseFunc": "x/86.4000", + "FromBaseToUnitFunc": "x*86.4000", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["t/d"] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet/Scripts/UnitDefinitions/RotationalSpeed.json b/UnitsNet/Scripts/UnitDefinitions/RotationalSpeed.json index 6834f8fc81..060d65c34c 100644 --- a/UnitsNet/Scripts/UnitDefinitions/RotationalSpeed.json +++ b/UnitsNet/Scripts/UnitDefinitions/RotationalSpeed.json @@ -19,7 +19,19 @@ } ] }, - { + { + "SingularName": "RadianPerSecond", + "PluralName": "RadiansPerSecond", + "FromUnitToBaseFunc": "x/6.2831853072", + "FromBaseToUnitFunc": "x*6.2831853072", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["rad/s"] + } + ] + }, + { "SingularName": "RevolutionPerMinute", "PluralName": "RevolutionsPerMinute", "FromUnitToBaseFunc": "x/60", diff --git a/UnitsNet/Scripts/UnitDefinitions/SpecificEnergy.json b/UnitsNet/Scripts/UnitDefinitions/SpecificEnergy.json new file mode 100644 index 0000000000..8431ee10cc --- /dev/null +++ b/UnitsNet/Scripts/UnitDefinitions/SpecificEnergy.json @@ -0,0 +1,48 @@ +{ + "Name": "SpecificEnergy", + "BaseUnit": "JoulePerKilogram", + "XmlDoc": "The SpecificEnergy", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Specific_energy", + "Units": [ + { + "SingularName": "JoulePerKilogram", + "PluralName": "JoulesPerKilogram", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": ["Kilo","Mega"], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["J/kg"] + } + ] + }, + { + "SingularName": "CaloriePerGram", + "PluralName": "CaloriesPerGram", + "FromUnitToBaseFunc": "x*4.184e3", + "FromBaseToUnitFunc": "x/4.184e3", + "Prefixes": ["Kilo"], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["cal/g"] + } + ] + }, + { + "SingularName": "WattHourPerKilogram", + "PluralName": "WattHoursPerKilogram", + "FromUnitToBaseFunc": "x*3.6e3", + "FromBaseToUnitFunc": "x/3.6e3", + "Prefixes": ["Kilo","Mega"], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["Wh/kg"] + } + ] + } + + ] +} \ No newline at end of file diff --git a/UnitsNet/Scripts/UnitDefinitions/Speed.json b/UnitsNet/Scripts/UnitDefinitions/Speed.json index f9290d3067..9d9d4dd198 100644 --- a/UnitsNet/Scripts/UnitDefinitions/Speed.json +++ b/UnitsNet/Scripts/UnitDefinitions/Speed.json @@ -15,6 +15,18 @@ "Abbreviations": ["m/s"] } ] + }, + { + "SingularName": "MeterPerHour", + "PluralName": "MetersPerHour", + "FromUnitToBaseFunc": "x/3600", + "FromBaseToUnitFunc": "x*3600", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": ["m/h"] + } + ] }, { "SingularName": "FootPerSecond",