From f1a55cbf97799f4d41354684530e7590aa645b40 Mon Sep 17 00:00:00 2001 From: tongbong Date: Thu, 21 Jan 2016 09:55:51 +0100 Subject: [PATCH] Add unit TemperatureChangeRate --- .../CustomCode/TemperatureChangeRateTests.cs | 74 +++ .../TemperatureChangeRateTestsBase.g.cs | 215 +++++++ .../Enums/TemperatureChangeRateUnit.g.cs | 38 ++ .../UnitClasses/TemperatureChangeRate.g.cs | 552 ++++++++++++++++++ .../GeneratedCode/UnitSystem.Default.g.cs | 49 ++ .../TemperatureChangeRate.json | 20 + 6 files changed, 948 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Enums/TemperatureChangeRateUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs create mode 100644 UnitsNet/Scripts/UnitDefinitions/TemperatureChangeRate.json diff --git a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs new file mode 100644 index 0000000000..7ed6ab9efd --- /dev/null +++ b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs @@ -0,0 +1,74 @@ +// 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 TemperatureChangeRateTests : TemperatureChangeRateTestsBase + { + protected override double DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1; } + } + + protected override double DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E-1; } + } + + protected override double HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E-2; } + } + + protected override double KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E-3; } + } + + protected override double DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E1; } + } + + protected override double CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E2; } + } + + protected override double MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E3; } + } + + protected override double MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E6; } + } + + protected override double NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond + { + get { return 1E9; } + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs new file mode 100644 index 0000000000..ee645e65cb --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs @@ -0,0 +1,215 @@ +// 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 TemperatureChangeRate. + /// + [TestFixture] +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class TemperatureChangeRateTestsBase + { + protected abstract double CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + protected abstract double NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double CentidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double DecadegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double DecidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double DegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double HectodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double KilodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double MicrodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double MillidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } + protected virtual double NanodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Test] + public void DegreeCelsiusPerSecondToTemperatureChangeRateUnits() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.AreEqual(CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); + } + + [Test] + public void FromValueAndUnit() + { + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond).CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond).DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond).DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond).HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond).KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond).MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond).MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond).NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); + } + + [Test] + public void As() + { + var degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.AreEqual(CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond), CentidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond), DecadegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond), DecidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DegreeCelsiusPerSecond), DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond), HectodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond), KilodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond), MicrodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond), MillidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond), NanodegreesCelsiusPerSecondTolerance); + } + + [Test] + public void ConversionRoundTrip() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.AreEqual(1, TemperatureChangeRate.FromCentidegreesCelsiusPerSecond(degreecelsiuspersecond.CentidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromDecadegreesCelsiusPerSecond(degreecelsiuspersecond.DecadegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromDecidegreesCelsiusPerSecond(degreecelsiuspersecond.DecidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromDegreesCelsiusPerSecond(degreecelsiuspersecond.DegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromHectodegreesCelsiusPerSecond(degreecelsiuspersecond.HectodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromKilodegreesCelsiusPerSecond(degreecelsiuspersecond.KilodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromMicrodegreesCelsiusPerSecond(degreecelsiuspersecond.MicrodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromMillidegreesCelsiusPerSecond(degreecelsiuspersecond.MillidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); + Assert.AreEqual(1, TemperatureChangeRate.FromNanodegreesCelsiusPerSecond(degreecelsiuspersecond.NanodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); + } + + [Test] + public void ArithmeticOperators() + { + TemperatureChangeRate v = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.AreEqual(-1, -v.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(2, (TemperatureChangeRate.FromDegreesCelsiusPerSecond(3)-v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(2, (v + v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(10, (v*10).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(10, (10*v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(2, (TemperatureChangeRate.FromDegreesCelsiusPerSecond(10)/5).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); + Assert.AreEqual(2, TemperatureChangeRate.FromDegreesCelsiusPerSecond(10)/TemperatureChangeRate.FromDegreesCelsiusPerSecond(5), DegreesCelsiusPerSecondTolerance); + } + + [Test] + public void ComparisonOperators() + { + TemperatureChangeRate oneDegreeCelsiusPerSecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + TemperatureChangeRate twoDegreesCelsiusPerSecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(2); + + Assert.True(oneDegreeCelsiusPerSecond < twoDegreesCelsiusPerSecond); + Assert.True(oneDegreeCelsiusPerSecond <= twoDegreesCelsiusPerSecond); + Assert.True(twoDegreesCelsiusPerSecond > oneDegreeCelsiusPerSecond); + Assert.True(twoDegreesCelsiusPerSecond >= oneDegreeCelsiusPerSecond); + + Assert.False(oneDegreeCelsiusPerSecond > twoDegreesCelsiusPerSecond); + Assert.False(oneDegreeCelsiusPerSecond >= twoDegreesCelsiusPerSecond); + Assert.False(twoDegreesCelsiusPerSecond < oneDegreeCelsiusPerSecond); + Assert.False(twoDegreesCelsiusPerSecond <= oneDegreeCelsiusPerSecond); + } + + [Test] + public void CompareToIsImplemented() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.AreEqual(0, degreecelsiuspersecond.CompareTo(degreecelsiuspersecond)); + Assert.Greater(degreecelsiuspersecond.CompareTo(TemperatureChangeRate.Zero), 0); + Assert.Less(TemperatureChangeRate.Zero.CompareTo(degreecelsiuspersecond), 0); + } + + [Test] + [ExpectedException(typeof(ArgumentException))] + public void CompareToThrowsOnTypeMismatch() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + degreecelsiuspersecond.CompareTo(new object()); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void CompareToThrowsOnNull() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); +// ReSharper disable once ReturnValueOfPureMethodIsNotUsed + degreecelsiuspersecond.CompareTo(null); + } + + + [Test] + public void EqualityOperators() + { + TemperatureChangeRate a = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + TemperatureChangeRate b = TemperatureChangeRate.FromDegreesCelsiusPerSecond(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() + { + TemperatureChangeRate v = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.IsTrue(v.Equals(TemperatureChangeRate.FromDegreesCelsiusPerSecond(1))); + Assert.IsFalse(v.Equals(TemperatureChangeRate.Zero)); + } + + [Test] + public void EqualsReturnsFalseOnTypeMismatch() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.IsFalse(degreecelsiuspersecond.Equals(new object())); + } + + [Test] + public void EqualsReturnsFalseOnNull() + { + TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); + Assert.IsFalse(degreecelsiuspersecond.Equals(null)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Enums/TemperatureChangeRateUnit.g.cs b/UnitsNet/GeneratedCode/Enums/TemperatureChangeRateUnit.g.cs new file mode 100644 index 0000000000..b0bfc0d70f --- /dev/null +++ b/UnitsNet/GeneratedCode/Enums/TemperatureChangeRateUnit.g.cs @@ -0,0 +1,38 @@ +// 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 TemperatureChangeRateUnit + { + Undefined = 0, + CentidegreeCelsiusPerSecond, + DecadegreeCelsiusPerSecond, + DecidegreeCelsiusPerSecond, + DegreeCelsiusPerSecond, + HectodegreeCelsiusPerSecond, + KilodegreeCelsiusPerSecond, + MicrodegreeCelsiusPerSecond, + MillidegreeCelsiusPerSecond, + NanodegreeCelsiusPerSecond, + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs new file mode 100644 index 0000000000..25ee4e4140 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs @@ -0,0 +1,552 @@ +// 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 +{ + /// + /// Temperature change rate is the ratio of the temperature change to the time during which the change occurred (value of temperature changes per unit time). + /// + // ReSharper disable once PartialTypeWithSinglePart + public partial struct TemperatureChangeRate : IComparable, IComparable + { + /// + /// Base unit of TemperatureChangeRate. + /// + private readonly double _degreesCelsiusPerSecond; + + public TemperatureChangeRate(double degreescelsiuspersecond) : this() + { + _degreesCelsiusPerSecond = degreescelsiuspersecond; + } + + #region Properties + + public static TemperatureChangeRateUnit BaseUnit + { + get { return TemperatureChangeRateUnit.DegreeCelsiusPerSecond; } + } + + /// + /// Get TemperatureChangeRate in CentidegreesCelsiusPerSecond. + /// + public double CentidegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e-2d; } + } + + /// + /// Get TemperatureChangeRate in DecadegreesCelsiusPerSecond. + /// + public double DecadegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e1d; } + } + + /// + /// Get TemperatureChangeRate in DecidegreesCelsiusPerSecond. + /// + public double DecidegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e-1d; } + } + + /// + /// Get TemperatureChangeRate in DegreesCelsiusPerSecond. + /// + public double DegreesCelsiusPerSecond + { + get { return _degreesCelsiusPerSecond; } + } + + /// + /// Get TemperatureChangeRate in HectodegreesCelsiusPerSecond. + /// + public double HectodegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e2d; } + } + + /// + /// Get TemperatureChangeRate in KilodegreesCelsiusPerSecond. + /// + public double KilodegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e3d; } + } + + /// + /// Get TemperatureChangeRate in MicrodegreesCelsiusPerSecond. + /// + public double MicrodegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e-6d; } + } + + /// + /// Get TemperatureChangeRate in MillidegreesCelsiusPerSecond. + /// + public double MillidegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e-3d; } + } + + /// + /// Get TemperatureChangeRate in NanodegreesCelsiusPerSecond. + /// + public double NanodegreesCelsiusPerSecond + { + get { return (_degreesCelsiusPerSecond) / 1e-9d; } + } + + #endregion + + #region Static + + public static TemperatureChangeRate Zero + { + get { return new TemperatureChangeRate(); } + } + + /// + /// Get TemperatureChangeRate from CentidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromCentidegreesCelsiusPerSecond(double centidegreescelsiuspersecond) + { + return new TemperatureChangeRate((centidegreescelsiuspersecond) * 1e-2d); + } + + /// + /// Get TemperatureChangeRate from DecadegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromDecadegreesCelsiusPerSecond(double decadegreescelsiuspersecond) + { + return new TemperatureChangeRate((decadegreescelsiuspersecond) * 1e1d); + } + + /// + /// Get TemperatureChangeRate from DecidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromDecidegreesCelsiusPerSecond(double decidegreescelsiuspersecond) + { + return new TemperatureChangeRate((decidegreescelsiuspersecond) * 1e-1d); + } + + /// + /// Get TemperatureChangeRate from DegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromDegreesCelsiusPerSecond(double degreescelsiuspersecond) + { + return new TemperatureChangeRate(degreescelsiuspersecond); + } + + /// + /// Get TemperatureChangeRate from HectodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromHectodegreesCelsiusPerSecond(double hectodegreescelsiuspersecond) + { + return new TemperatureChangeRate((hectodegreescelsiuspersecond) * 1e2d); + } + + /// + /// Get TemperatureChangeRate from KilodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromKilodegreesCelsiusPerSecond(double kilodegreescelsiuspersecond) + { + return new TemperatureChangeRate((kilodegreescelsiuspersecond) * 1e3d); + } + + /// + /// Get TemperatureChangeRate from MicrodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromMicrodegreesCelsiusPerSecond(double microdegreescelsiuspersecond) + { + return new TemperatureChangeRate((microdegreescelsiuspersecond) * 1e-6d); + } + + /// + /// Get TemperatureChangeRate from MillidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromMillidegreesCelsiusPerSecond(double millidegreescelsiuspersecond) + { + return new TemperatureChangeRate((millidegreescelsiuspersecond) * 1e-3d); + } + + /// + /// Get TemperatureChangeRate from NanodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate FromNanodegreesCelsiusPerSecond(double nanodegreescelsiuspersecond) + { + return new TemperatureChangeRate((nanodegreescelsiuspersecond) * 1e-9d); + } + + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// TemperatureChangeRate unit value. + public static TemperatureChangeRate From(double value, TemperatureChangeRateUnit fromUnit) + { + switch (fromUnit) + { + case TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond: + return FromCentidegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond: + return FromDecadegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond: + return FromDecidegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.DegreeCelsiusPerSecond: + return FromDegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond: + return FromHectodegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond: + return FromKilodegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond: + return FromMicrodegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond: + return FromMillidegreesCelsiusPerSecond(value); + case TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond: + return FromNanodegreesCelsiusPerSecond(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(TemperatureChangeRateUnit unit, CultureInfo culture = null) + { + return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit); + } + + #endregion + + #region Arithmetic Operators + + public static TemperatureChangeRate operator -(TemperatureChangeRate right) + { + return new TemperatureChangeRate(-right._degreesCelsiusPerSecond); + } + + public static TemperatureChangeRate operator +(TemperatureChangeRate left, TemperatureChangeRate right) + { + return new TemperatureChangeRate(left._degreesCelsiusPerSecond + right._degreesCelsiusPerSecond); + } + + public static TemperatureChangeRate operator -(TemperatureChangeRate left, TemperatureChangeRate right) + { + return new TemperatureChangeRate(left._degreesCelsiusPerSecond - right._degreesCelsiusPerSecond); + } + + public static TemperatureChangeRate operator *(double left, TemperatureChangeRate right) + { + return new TemperatureChangeRate(left*right._degreesCelsiusPerSecond); + } + + public static TemperatureChangeRate operator *(TemperatureChangeRate left, double right) + { + return new TemperatureChangeRate(left._degreesCelsiusPerSecond*(double)right); + } + + public static TemperatureChangeRate operator /(TemperatureChangeRate left, double right) + { + return new TemperatureChangeRate(left._degreesCelsiusPerSecond/(double)right); + } + + public static double operator /(TemperatureChangeRate left, TemperatureChangeRate right) + { + return Convert.ToDouble(left._degreesCelsiusPerSecond/right._degreesCelsiusPerSecond); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is TemperatureChangeRate)) throw new ArgumentException("Expected type TemperatureChangeRate.", "obj"); + return CompareTo((TemperatureChangeRate) obj); + } + + public int CompareTo(TemperatureChangeRate other) + { + return _degreesCelsiusPerSecond.CompareTo(other._degreesCelsiusPerSecond); + } + + public static bool operator <=(TemperatureChangeRate left, TemperatureChangeRate right) + { + return left._degreesCelsiusPerSecond <= right._degreesCelsiusPerSecond; + } + + public static bool operator >=(TemperatureChangeRate left, TemperatureChangeRate right) + { + return left._degreesCelsiusPerSecond >= right._degreesCelsiusPerSecond; + } + + public static bool operator <(TemperatureChangeRate left, TemperatureChangeRate right) + { + return left._degreesCelsiusPerSecond < right._degreesCelsiusPerSecond; + } + + public static bool operator >(TemperatureChangeRate left, TemperatureChangeRate right) + { + return left._degreesCelsiusPerSecond > right._degreesCelsiusPerSecond; + } + + public static bool operator ==(TemperatureChangeRate left, TemperatureChangeRate right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._degreesCelsiusPerSecond == right._degreesCelsiusPerSecond; + } + + public static bool operator !=(TemperatureChangeRate left, TemperatureChangeRate right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._degreesCelsiusPerSecond != right._degreesCelsiusPerSecond; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _degreesCelsiusPerSecond.Equals(((TemperatureChangeRate) obj)._degreesCelsiusPerSecond); + } + + public override int GetHashCode() + { + return _degreesCelsiusPerSecond.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(TemperatureChangeRateUnit unit) + { + switch (unit) + { + case TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond: + return CentidegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond: + return DecadegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond: + return DecidegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.DegreeCelsiusPerSecond: + return DegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond: + return HectodegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond: + return KilodegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond: + return MicrodegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond: + return MillidegreesCelsiusPerSecond; + case TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond: + return NanodegreesCelsiusPerSecond; + + 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 TemperatureChangeRate 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 + { + TemperatureChangeRateUnit 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 TemperatureChangeRateUnit 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 == TemperatureChangeRateUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized TemperatureChangeRateUnit."); + 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(TemperatureChangeRateUnit.DegreeCelsiusPerSecond); + } + + /// + /// 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(TemperatureChangeRateUnit 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(TemperatureChangeRateUnit 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/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 84de974690..719c20a097 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1606,6 +1606,55 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "K"), }), }), + new UnitLocalization(typeof (TemperatureChangeRateUnit), + new[] + { + new CulturesForEnumValue((int) TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "c°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "da°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "d°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.DegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "h°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "k°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "μ°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "m°C/s"), + }), + new CulturesForEnumValue((int) TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "n°C/s"), + }), + }), new UnitLocalization(typeof (TorqueUnit), new[] { diff --git a/UnitsNet/Scripts/UnitDefinitions/TemperatureChangeRate.json b/UnitsNet/Scripts/UnitDefinitions/TemperatureChangeRate.json new file mode 100644 index 0000000000..4f96ac4c00 --- /dev/null +++ b/UnitsNet/Scripts/UnitDefinitions/TemperatureChangeRate.json @@ -0,0 +1,20 @@ +{ + "Name": "TemperatureChangeRate", + "BaseUnit": "DegreeCelsiusPerSecond", + "XmlDoc": "Temperature change rate is the ratio of the temperature change to the time during which the change occurred (value of temperature changes per unit time).", + "Units": [ + { + "SingularName": "DegreeCelsiusPerSecond", + "PluralName": "DegreesCelsiusPerSecond", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "°C/s" ] + } + ] + } + ] +} \ No newline at end of file