Skip to content

Commit a3e6216

Browse files
committed
Add unit class TemperatureDelta
Inherits units from Temperature.
1 parent 5d7e890 commit a3e6216

File tree

8 files changed

+1681
-0
lines changed

8 files changed

+1681
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 unit class 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/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
13+
//
14+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
15+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
16+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
17+
//
18+
// </auto-generated>
19+
//------------------------------------------------------------------------------
20+
21+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
22+
// https://github.com/anjdreas/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+
namespace UnitsNet.Tests.CustomCode
44+
{
45+
public class TemperatureDeltaTests : TemperatureDeltaTestsBase
46+
{
47+
protected override double DegreesCelsiusDeltaInOneKelvinDelta => 1;
48+
protected override double DegreesDelisleDeltaInOneKelvinDelta => -1.5d;
49+
protected override double DegreesFahrenheitDeltaInOneKelvinDelta => 1.8;
50+
protected override double DegreesNewtonDeltaInOneKelvinDelta => 0.33d;
51+
protected override double DegreesRankineDeltaInOneKelvinDelta => 1.8;
52+
protected override double DegreesReaumurDeltaInOneKelvinDelta => 0.8;
53+
protected override double DegreesRoemerDeltaInOneKelvinDelta => 21/40d;
54+
protected override double KelvinsDeltaInOneKelvinDelta => 1;
55+
}
56+
}
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
12+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
13+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
14+
//
15+
// </auto-generated>
16+
//------------------------------------------------------------------------------
17+
18+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
19+
// https://github.com/anjdreas/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 NUnit.Framework;
41+
using UnitsNet.Units;
42+
43+
// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
44+
#pragma warning disable 1718
45+
46+
// ReSharper disable once CheckNamespace
47+
namespace UnitsNet.Tests
48+
{
49+
/// <summary>
50+
/// Test of TemperatureDelta.
51+
/// </summary>
52+
[TestFixture]
53+
// ReSharper disable once PartialTypeWithSinglePart
54+
public abstract partial class TemperatureDeltaTestsBase
55+
{
56+
protected abstract double DegreesCelsiusDeltaInOneKelvinDelta { get; }
57+
protected abstract double DegreesDelisleDeltaInOneKelvinDelta { get; }
58+
protected abstract double DegreesFahrenheitDeltaInOneKelvinDelta { get; }
59+
protected abstract double DegreesNewtonDeltaInOneKelvinDelta { get; }
60+
protected abstract double DegreesRankineDeltaInOneKelvinDelta { get; }
61+
protected abstract double DegreesReaumurDeltaInOneKelvinDelta { get; }
62+
protected abstract double DegreesRoemerDeltaInOneKelvinDelta { get; }
63+
protected abstract double KelvinsDeltaInOneKelvinDelta { get; }
64+
65+
// ReSharper disable VirtualMemberNeverOverriden.Global
66+
protected virtual double DegreesCelsiusDeltaTolerance { get { return 1e-5; } }
67+
protected virtual double DegreesDelisleDeltaTolerance { get { return 1e-5; } }
68+
protected virtual double DegreesFahrenheitDeltaTolerance { get { return 1e-5; } }
69+
protected virtual double DegreesNewtonDeltaTolerance { get { return 1e-5; } }
70+
protected virtual double DegreesRankineDeltaTolerance { get { return 1e-5; } }
71+
protected virtual double DegreesReaumurDeltaTolerance { get { return 1e-5; } }
72+
protected virtual double DegreesRoemerDeltaTolerance { get { return 1e-5; } }
73+
protected virtual double KelvinsDeltaTolerance { get { return 1e-5; } }
74+
// ReSharper restore VirtualMemberNeverOverriden.Global
75+
76+
[Test]
77+
public void KelvinDeltaToTemperatureDeltaUnits()
78+
{
79+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
80+
Assert.AreEqual(DegreesCelsiusDeltaInOneKelvinDelta, kelvindelta.DegreesCelsiusDelta, DegreesCelsiusDeltaTolerance);
81+
Assert.AreEqual(DegreesDelisleDeltaInOneKelvinDelta, kelvindelta.DegreesDelisleDelta, DegreesDelisleDeltaTolerance);
82+
Assert.AreEqual(DegreesFahrenheitDeltaInOneKelvinDelta, kelvindelta.DegreesFahrenheitDelta, DegreesFahrenheitDeltaTolerance);
83+
Assert.AreEqual(DegreesNewtonDeltaInOneKelvinDelta, kelvindelta.DegreesNewtonDelta, DegreesNewtonDeltaTolerance);
84+
Assert.AreEqual(DegreesRankineDeltaInOneKelvinDelta, kelvindelta.DegreesRankineDelta, DegreesRankineDeltaTolerance);
85+
Assert.AreEqual(DegreesReaumurDeltaInOneKelvinDelta, kelvindelta.DegreesReaumurDelta, DegreesReaumurDeltaTolerance);
86+
Assert.AreEqual(DegreesRoemerDeltaInOneKelvinDelta, kelvindelta.DegreesRoemerDelta, DegreesRoemerDeltaTolerance);
87+
Assert.AreEqual(KelvinsDeltaInOneKelvinDelta, kelvindelta.KelvinsDelta, KelvinsDeltaTolerance);
88+
}
89+
90+
[Test]
91+
public void FromValueAndUnit()
92+
{
93+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeCelsiusDelta).DegreesCelsiusDelta, DegreesCelsiusDeltaTolerance);
94+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeDelisleDelta).DegreesDelisleDelta, DegreesDelisleDeltaTolerance);
95+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeFahrenheitDelta).DegreesFahrenheitDelta, DegreesFahrenheitDeltaTolerance);
96+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeNewtonDelta).DegreesNewtonDelta, DegreesNewtonDeltaTolerance);
97+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeRankineDelta).DegreesRankineDelta, DegreesRankineDeltaTolerance);
98+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeReaumurDelta).DegreesReaumurDelta, DegreesReaumurDeltaTolerance);
99+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeRoemerDelta).DegreesRoemerDelta, DegreesRoemerDeltaTolerance);
100+
Assert.AreEqual(1, TemperatureDelta.From(1, TemperatureDeltaUnit.KelvinDelta).KelvinsDelta, KelvinsDeltaTolerance);
101+
}
102+
103+
[Test]
104+
public void As()
105+
{
106+
var kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
107+
Assert.AreEqual(DegreesCelsiusDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeCelsiusDelta), DegreesCelsiusDeltaTolerance);
108+
Assert.AreEqual(DegreesDelisleDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeDelisleDelta), DegreesDelisleDeltaTolerance);
109+
Assert.AreEqual(DegreesFahrenheitDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeFahrenheitDelta), DegreesFahrenheitDeltaTolerance);
110+
Assert.AreEqual(DegreesNewtonDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeNewtonDelta), DegreesNewtonDeltaTolerance);
111+
Assert.AreEqual(DegreesRankineDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeRankineDelta), DegreesRankineDeltaTolerance);
112+
Assert.AreEqual(DegreesReaumurDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeReaumurDelta), DegreesReaumurDeltaTolerance);
113+
Assert.AreEqual(DegreesRoemerDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.DegreeRoemerDelta), DegreesRoemerDeltaTolerance);
114+
Assert.AreEqual(KelvinsDeltaInOneKelvinDelta, kelvindelta.As(TemperatureDeltaUnit.KelvinDelta), KelvinsDeltaTolerance);
115+
}
116+
117+
[Test]
118+
public void ConversionRoundTrip()
119+
{
120+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
121+
Assert.AreEqual(1, TemperatureDelta.FromDegreesCelsiusDelta(kelvindelta.DegreesCelsiusDelta).KelvinsDelta, DegreesCelsiusDeltaTolerance);
122+
Assert.AreEqual(1, TemperatureDelta.FromDegreesDelisleDelta(kelvindelta.DegreesDelisleDelta).KelvinsDelta, DegreesDelisleDeltaTolerance);
123+
Assert.AreEqual(1, TemperatureDelta.FromDegreesFahrenheitDelta(kelvindelta.DegreesFahrenheitDelta).KelvinsDelta, DegreesFahrenheitDeltaTolerance);
124+
Assert.AreEqual(1, TemperatureDelta.FromDegreesNewtonDelta(kelvindelta.DegreesNewtonDelta).KelvinsDelta, DegreesNewtonDeltaTolerance);
125+
Assert.AreEqual(1, TemperatureDelta.FromDegreesRankineDelta(kelvindelta.DegreesRankineDelta).KelvinsDelta, DegreesRankineDeltaTolerance);
126+
Assert.AreEqual(1, TemperatureDelta.FromDegreesReaumurDelta(kelvindelta.DegreesReaumurDelta).KelvinsDelta, DegreesReaumurDeltaTolerance);
127+
Assert.AreEqual(1, TemperatureDelta.FromDegreesRoemerDelta(kelvindelta.DegreesRoemerDelta).KelvinsDelta, DegreesRoemerDeltaTolerance);
128+
Assert.AreEqual(1, TemperatureDelta.FromKelvinsDelta(kelvindelta.KelvinsDelta).KelvinsDelta, KelvinsDeltaTolerance);
129+
}
130+
131+
[Test]
132+
public void ArithmeticOperators()
133+
{
134+
TemperatureDelta v = TemperatureDelta.FromKelvinsDelta(1);
135+
Assert.AreEqual(-1, -v.KelvinsDelta, KelvinsDeltaTolerance);
136+
Assert.AreEqual(2, (TemperatureDelta.FromKelvinsDelta(3)-v).KelvinsDelta, KelvinsDeltaTolerance);
137+
Assert.AreEqual(2, (v + v).KelvinsDelta, KelvinsDeltaTolerance);
138+
Assert.AreEqual(10, (v*10).KelvinsDelta, KelvinsDeltaTolerance);
139+
Assert.AreEqual(10, (10*v).KelvinsDelta, KelvinsDeltaTolerance);
140+
Assert.AreEqual(2, (TemperatureDelta.FromKelvinsDelta(10)/5).KelvinsDelta, KelvinsDeltaTolerance);
141+
Assert.AreEqual(2, TemperatureDelta.FromKelvinsDelta(10)/TemperatureDelta.FromKelvinsDelta(5), KelvinsDeltaTolerance);
142+
}
143+
144+
[Test]
145+
public void ComparisonOperators()
146+
{
147+
TemperatureDelta oneKelvinDelta = TemperatureDelta.FromKelvinsDelta(1);
148+
TemperatureDelta twoKelvinsDelta = TemperatureDelta.FromKelvinsDelta(2);
149+
150+
Assert.True(oneKelvinDelta < twoKelvinsDelta);
151+
Assert.True(oneKelvinDelta <= twoKelvinsDelta);
152+
Assert.True(twoKelvinsDelta > oneKelvinDelta);
153+
Assert.True(twoKelvinsDelta >= oneKelvinDelta);
154+
155+
Assert.False(oneKelvinDelta > twoKelvinsDelta);
156+
Assert.False(oneKelvinDelta >= twoKelvinsDelta);
157+
Assert.False(twoKelvinsDelta < oneKelvinDelta);
158+
Assert.False(twoKelvinsDelta <= oneKelvinDelta);
159+
}
160+
161+
[Test]
162+
public void CompareToIsImplemented()
163+
{
164+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
165+
Assert.AreEqual(0, kelvindelta.CompareTo(kelvindelta));
166+
Assert.Greater(kelvindelta.CompareTo(TemperatureDelta.Zero), 0);
167+
Assert.Less(TemperatureDelta.Zero.CompareTo(kelvindelta), 0);
168+
}
169+
170+
[Test]
171+
[ExpectedException(typeof(ArgumentException))]
172+
public void CompareToThrowsOnTypeMismatch()
173+
{
174+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
175+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
176+
kelvindelta.CompareTo(new object());
177+
}
178+
179+
[Test]
180+
[ExpectedException(typeof(ArgumentNullException))]
181+
public void CompareToThrowsOnNull()
182+
{
183+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
184+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
185+
kelvindelta.CompareTo(null);
186+
}
187+
188+
189+
[Test]
190+
public void EqualityOperators()
191+
{
192+
TemperatureDelta a = TemperatureDelta.FromKelvinsDelta(1);
193+
TemperatureDelta b = TemperatureDelta.FromKelvinsDelta(2);
194+
195+
// ReSharper disable EqualExpressionComparison
196+
Assert.True(a == a);
197+
Assert.True(a != b);
198+
199+
Assert.False(a == b);
200+
Assert.False(a != a);
201+
// ReSharper restore EqualExpressionComparison
202+
}
203+
204+
[Test]
205+
public void EqualsIsImplemented()
206+
{
207+
TemperatureDelta v = TemperatureDelta.FromKelvinsDelta(1);
208+
Assert.IsTrue(v.Equals(TemperatureDelta.FromKelvinsDelta(1)));
209+
Assert.IsFalse(v.Equals(TemperatureDelta.Zero));
210+
}
211+
212+
[Test]
213+
public void EqualsReturnsFalseOnTypeMismatch()
214+
{
215+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
216+
Assert.IsFalse(kelvindelta.Equals(new object()));
217+
}
218+
219+
[Test]
220+
public void EqualsReturnsFalseOnNull()
221+
{
222+
TemperatureDelta kelvindelta = TemperatureDelta.FromKelvinsDelta(1);
223+
Assert.IsFalse(kelvindelta.Equals(null));
224+
}
225+
}
226+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
12+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
13+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
14+
//
15+
// </auto-generated>
16+
//------------------------------------------------------------------------------
17+
18+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
19+
// https://github.com/anjdreas/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+
// ReSharper disable once CheckNamespace
40+
namespace UnitsNet.Units
41+
{
42+
public enum TemperatureDeltaUnit
43+
{
44+
Undefined = 0,
45+
DegreeCelsiusDelta,
46+
DegreeDelisleDelta,
47+
DegreeFahrenheitDelta,
48+
DegreeNewtonDelta,
49+
DegreeRankineDelta,
50+
DegreeReaumurDelta,
51+
DegreeRoemerDelta,
52+
KelvinDelta,
53+
}
54+
}

0 commit comments

Comments
 (0)