Skip to content

Commit dda6a62

Browse files
tmilnthorpangularsen
authored andcommitted
Adding units for coefficient of thermal expansion (#543)
* Adding units for coefficient of thermal expansion * Adding Degree for InverseDegreeCelsius and InverseDegreeFahrenheit to make them consistent with other UnitsNet temperature units. Adding 1/K, 1/°C, and 1/°F abbreviations also.
1 parent b7fcf4b commit dda6a62

File tree

10 files changed

+1615
-0
lines changed

10 files changed

+1615
-0
lines changed

Common/GeneratedCode/Quantities/CoefficientOfThermalExpansion.Common.g.cs

Lines changed: 532 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Name": "CoefficientOfThermalExpansion",
3+
"BaseUnit": "InverseKelvin",
4+
"XmlDoc": "A unit that represents a fractional change in size in response to a change in temperature.",
5+
"BaseDimensions": {
6+
"Θ": -1
7+
},
8+
"Units": [
9+
{
10+
"SingularName": "InverseKelvin",
11+
"PluralName": "InverseKelvin",
12+
"FromUnitToBaseFunc": "x",
13+
"FromBaseToUnitFunc": "x",
14+
"Localization": [
15+
{
16+
"Culture": "en-US",
17+
"Abbreviations": [ "K⁻¹", "1/K" ]
18+
}
19+
]
20+
},
21+
{
22+
"SingularName": "InverseDegreeCelsius",
23+
"PluralName": "InverseDegreeCelsius",
24+
"FromUnitToBaseFunc": "x",
25+
"FromBaseToUnitFunc": "x",
26+
"Localization": [
27+
{
28+
"Culture": "en-US",
29+
"Abbreviations": [ "°C⁻¹", "1/°C" ]
30+
}
31+
]
32+
},
33+
{
34+
"SingularName": "InverseDegreeFahrenheit",
35+
"PluralName": "InverseDegreeFahrenheit",
36+
"FromUnitToBaseFunc": "x*5/9",
37+
"FromBaseToUnitFunc": "x*9/5",
38+
"Localization": [
39+
{
40+
"Culture": "en-US",
41+
"Abbreviations": [ "°F⁻¹", "1/°F" ]
42+
}
43+
]
44+
}
45+
]
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated (once) by \generate-code.bat, but will not be
4+
// regenerated when it already exists. The purpose of creating this file is to make
5+
// it easier to remember to implement all the unit conversion test cases.
6+
//
7+
// Whenever a new unit is added to this quantity and \generate-code.bat is run,
8+
// the base test class will get a new abstract property and cause a compile error
9+
// in this derived class, reminding the developer to implement the test case
10+
// for the new unit.
11+
//
12+
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
13+
//
14+
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
15+
// Add Extensions\MyQuantityExtensions.cs to decorate quantities with new behavior.
16+
// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
17+
//
18+
// </auto-generated>
19+
//------------------------------------------------------------------------------
20+
21+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
22+
// https://github.com/angularsen/UnitsNet
23+
//
24+
// Permission is hereby granted, free of charge, to any person obtaining a copy
25+
// of this software and associated documentation files (the "Software"), to deal
26+
// in the Software without restriction, including without limitation the rights
27+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28+
// copies of the Software, and to permit persons to whom the Software is
29+
// furnished to do so, subject to the following conditions:
30+
//
31+
// The above copyright notice and this permission notice shall be included in
32+
// all copies or substantial portions of the Software.
33+
//
34+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40+
// THE SOFTWARE.
41+
42+
43+
using System;
44+
45+
namespace UnitsNet.Tests.CustomCode
46+
{
47+
public class CoefficientOfThermalExpansionTests : CoefficientOfThermalExpansionTestsBase
48+
{
49+
protected override double InverseDegreeCelsiusInOneInverseKelvin => 1.0;
50+
51+
protected override double InverseDegreeFahrenheitInOneInverseKelvin => 1.8;
52+
53+
protected override double InverseKelvinInOneInverseKelvin => 1.0;
54+
}
55+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by \generate-code.bat.
4+
//
5+
// Changes to this file will be lost when the code is regenerated.
6+
// The build server regenerates the code before each build and a pre-build
7+
// step will regenerate the code on each local build.
8+
//
9+
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
12+
// Add Extensions\MyQuantityExtensions.cs to decorate quantities with new behavior.
13+
// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
14+
//
15+
// </auto-generated>
16+
//------------------------------------------------------------------------------
17+
18+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
19+
// https://github.com/angularsen/UnitsNet
20+
//
21+
// Permission is hereby granted, free of charge, to any person obtaining a copy
22+
// of this software and associated documentation files (the "Software"), to deal
23+
// in the Software without restriction, including without limitation the rights
24+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
// copies of the Software, and to permit persons to whom the Software is
26+
// furnished to do so, subject to the following conditions:
27+
//
28+
// The above copyright notice and this permission notice shall be included in
29+
// all copies or substantial portions of the Software.
30+
//
31+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37+
// THE SOFTWARE.
38+
39+
using System;
40+
using System.Linq;
41+
using UnitsNet.Units;
42+
using Xunit;
43+
44+
// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
45+
#pragma warning disable 1718
46+
47+
// ReSharper disable once CheckNamespace
48+
namespace UnitsNet.Tests
49+
{
50+
/// <summary>
51+
/// Test of CoefficientOfThermalExpansion.
52+
/// </summary>
53+
// ReSharper disable once PartialTypeWithSinglePart
54+
public abstract partial class CoefficientOfThermalExpansionTestsBase
55+
{
56+
protected abstract double InverseDegreeCelsiusInOneInverseKelvin { get; }
57+
protected abstract double InverseDegreeFahrenheitInOneInverseKelvin { get; }
58+
protected abstract double InverseKelvinInOneInverseKelvin { get; }
59+
60+
// ReSharper disable VirtualMemberNeverOverriden.Global
61+
protected virtual double InverseDegreeCelsiusTolerance { get { return 1e-5; } }
62+
protected virtual double InverseDegreeFahrenheitTolerance { get { return 1e-5; } }
63+
protected virtual double InverseKelvinTolerance { get { return 1e-5; } }
64+
// ReSharper restore VirtualMemberNeverOverriden.Global
65+
66+
[Fact]
67+
public void InverseKelvinToCoefficientOfThermalExpansionUnits()
68+
{
69+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
70+
AssertEx.EqualTolerance(InverseDegreeCelsiusInOneInverseKelvin, inversekelvin.InverseDegreeCelsius, InverseDegreeCelsiusTolerance);
71+
AssertEx.EqualTolerance(InverseDegreeFahrenheitInOneInverseKelvin, inversekelvin.InverseDegreeFahrenheit, InverseDegreeFahrenheitTolerance);
72+
AssertEx.EqualTolerance(InverseKelvinInOneInverseKelvin, inversekelvin.InverseKelvin, InverseKelvinTolerance);
73+
}
74+
75+
[Fact]
76+
public void FromValueAndUnit()
77+
{
78+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.From(1, CoefficientOfThermalExpansionUnit.InverseDegreeCelsius).InverseDegreeCelsius, InverseDegreeCelsiusTolerance);
79+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.From(1, CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit).InverseDegreeFahrenheit, InverseDegreeFahrenheitTolerance);
80+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.From(1, CoefficientOfThermalExpansionUnit.InverseKelvin).InverseKelvin, InverseKelvinTolerance);
81+
}
82+
83+
[Fact]
84+
public void As()
85+
{
86+
var inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
87+
AssertEx.EqualTolerance(InverseDegreeCelsiusInOneInverseKelvin, inversekelvin.As(CoefficientOfThermalExpansionUnit.InverseDegreeCelsius), InverseDegreeCelsiusTolerance);
88+
AssertEx.EqualTolerance(InverseDegreeFahrenheitInOneInverseKelvin, inversekelvin.As(CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit), InverseDegreeFahrenheitTolerance);
89+
AssertEx.EqualTolerance(InverseKelvinInOneInverseKelvin, inversekelvin.As(CoefficientOfThermalExpansionUnit.InverseKelvin), InverseKelvinTolerance);
90+
}
91+
92+
[Fact]
93+
public void ToUnit()
94+
{
95+
var inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
96+
97+
var inversedegreecelsiusQuantity = inversekelvin.ToUnit(CoefficientOfThermalExpansionUnit.InverseDegreeCelsius);
98+
AssertEx.EqualTolerance(InverseDegreeCelsiusInOneInverseKelvin, (double)inversedegreecelsiusQuantity.Value, InverseDegreeCelsiusTolerance);
99+
Assert.Equal(CoefficientOfThermalExpansionUnit.InverseDegreeCelsius, inversedegreecelsiusQuantity.Unit);
100+
101+
var inversedegreefahrenheitQuantity = inversekelvin.ToUnit(CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit);
102+
AssertEx.EqualTolerance(InverseDegreeFahrenheitInOneInverseKelvin, (double)inversedegreefahrenheitQuantity.Value, InverseDegreeFahrenheitTolerance);
103+
Assert.Equal(CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit, inversedegreefahrenheitQuantity.Unit);
104+
105+
var inversekelvinQuantity = inversekelvin.ToUnit(CoefficientOfThermalExpansionUnit.InverseKelvin);
106+
AssertEx.EqualTolerance(InverseKelvinInOneInverseKelvin, (double)inversekelvinQuantity.Value, InverseKelvinTolerance);
107+
Assert.Equal(CoefficientOfThermalExpansionUnit.InverseKelvin, inversekelvinQuantity.Unit);
108+
}
109+
110+
[Fact]
111+
public void ConversionRoundTrip()
112+
{
113+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
114+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.FromInverseDegreeCelsius(inversekelvin.InverseDegreeCelsius).InverseKelvin, InverseDegreeCelsiusTolerance);
115+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.FromInverseDegreeFahrenheit(inversekelvin.InverseDegreeFahrenheit).InverseKelvin, InverseDegreeFahrenheitTolerance);
116+
AssertEx.EqualTolerance(1, CoefficientOfThermalExpansion.FromInverseKelvin(inversekelvin.InverseKelvin).InverseKelvin, InverseKelvinTolerance);
117+
}
118+
119+
[Fact]
120+
public void ArithmeticOperators()
121+
{
122+
CoefficientOfThermalExpansion v = CoefficientOfThermalExpansion.FromInverseKelvin(1);
123+
AssertEx.EqualTolerance(-1, -v.InverseKelvin, InverseKelvinTolerance);
124+
AssertEx.EqualTolerance(2, (CoefficientOfThermalExpansion.FromInverseKelvin(3)-v).InverseKelvin, InverseKelvinTolerance);
125+
AssertEx.EqualTolerance(2, (v + v).InverseKelvin, InverseKelvinTolerance);
126+
AssertEx.EqualTolerance(10, (v*10).InverseKelvin, InverseKelvinTolerance);
127+
AssertEx.EqualTolerance(10, (10*v).InverseKelvin, InverseKelvinTolerance);
128+
AssertEx.EqualTolerance(2, (CoefficientOfThermalExpansion.FromInverseKelvin(10)/5).InverseKelvin, InverseKelvinTolerance);
129+
AssertEx.EqualTolerance(2, CoefficientOfThermalExpansion.FromInverseKelvin(10)/CoefficientOfThermalExpansion.FromInverseKelvin(5), InverseKelvinTolerance);
130+
}
131+
132+
[Fact]
133+
public void ComparisonOperators()
134+
{
135+
CoefficientOfThermalExpansion oneInverseKelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
136+
CoefficientOfThermalExpansion twoInverseKelvin = CoefficientOfThermalExpansion.FromInverseKelvin(2);
137+
138+
Assert.True(oneInverseKelvin < twoInverseKelvin);
139+
Assert.True(oneInverseKelvin <= twoInverseKelvin);
140+
Assert.True(twoInverseKelvin > oneInverseKelvin);
141+
Assert.True(twoInverseKelvin >= oneInverseKelvin);
142+
143+
Assert.False(oneInverseKelvin > twoInverseKelvin);
144+
Assert.False(oneInverseKelvin >= twoInverseKelvin);
145+
Assert.False(twoInverseKelvin < oneInverseKelvin);
146+
Assert.False(twoInverseKelvin <= oneInverseKelvin);
147+
}
148+
149+
[Fact]
150+
public void CompareToIsImplemented()
151+
{
152+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
153+
Assert.Equal(0, inversekelvin.CompareTo(inversekelvin));
154+
Assert.True(inversekelvin.CompareTo(CoefficientOfThermalExpansion.Zero) > 0);
155+
Assert.True(CoefficientOfThermalExpansion.Zero.CompareTo(inversekelvin) < 0);
156+
}
157+
158+
[Fact]
159+
public void CompareToThrowsOnTypeMismatch()
160+
{
161+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
162+
Assert.Throws<ArgumentException>(() => inversekelvin.CompareTo(new object()));
163+
}
164+
165+
[Fact]
166+
public void CompareToThrowsOnNull()
167+
{
168+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
169+
Assert.Throws<ArgumentNullException>(() => inversekelvin.CompareTo(null));
170+
}
171+
172+
173+
[Fact]
174+
public void EqualityOperators()
175+
{
176+
CoefficientOfThermalExpansion a = CoefficientOfThermalExpansion.FromInverseKelvin(1);
177+
CoefficientOfThermalExpansion b = CoefficientOfThermalExpansion.FromInverseKelvin(2);
178+
179+
// ReSharper disable EqualExpressionComparison
180+
Assert.True(a == a);
181+
Assert.True(a != b);
182+
183+
Assert.False(a == b);
184+
Assert.False(a != a);
185+
// ReSharper restore EqualExpressionComparison
186+
}
187+
188+
[Fact]
189+
public void EqualsIsImplemented()
190+
{
191+
CoefficientOfThermalExpansion v = CoefficientOfThermalExpansion.FromInverseKelvin(1);
192+
Assert.True(v.Equals(CoefficientOfThermalExpansion.FromInverseKelvin(1), CoefficientOfThermalExpansion.FromInverseKelvin(InverseKelvinTolerance)));
193+
Assert.False(v.Equals(CoefficientOfThermalExpansion.Zero, CoefficientOfThermalExpansion.FromInverseKelvin(InverseKelvinTolerance)));
194+
}
195+
196+
[Fact]
197+
public void EqualsReturnsFalseOnTypeMismatch()
198+
{
199+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
200+
Assert.False(inversekelvin.Equals(new object()));
201+
}
202+
203+
[Fact]
204+
public void EqualsReturnsFalseOnNull()
205+
{
206+
CoefficientOfThermalExpansion inversekelvin = CoefficientOfThermalExpansion.FromInverseKelvin(1);
207+
Assert.False(inversekelvin.Equals(null));
208+
}
209+
210+
[Fact]
211+
public void UnitsDoesNotContainUndefined()
212+
{
213+
Assert.DoesNotContain(CoefficientOfThermalExpansionUnit.Undefined, CoefficientOfThermalExpansion.Units);
214+
}
215+
216+
}
217+
}

0 commit comments

Comments
 (0)