Skip to content

Commit 139fb65

Browse files
gratestasFerit Tunçer
authored and
Ferit Tunçer
committed
New Quantity: SpecificEntropy (#322)
implemented new quantity SpecificEntropy
1 parent c4de80f commit 139fb65

File tree

8 files changed

+1751
-0
lines changed

8 files changed

+1751
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\MyUnit.extra.cs files to add code to generated quantities.
15+
// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
16+
// Add UnitDefinitions\MyUnit.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 SpecificEntropyTests : SpecificEntropyTestsBase
48+
{
49+
protected override double JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin => 1e0;
50+
protected override double JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin => 1e0;
51+
protected override double KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin => 1e-3;
52+
protected override double KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin => 1e-3;
53+
protected override double MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin => 1e-6;
54+
protected override double MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin => 1e-6;
55+
protected override double CaloriesPerGramKelvinInOneJoulePerKilogramKelvin => 2.390057e-4;
56+
protected override double KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin => 2.390057e-7;
57+
}
58+
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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\MyUnit.extra.cs files to add code to generated quantities.
12+
// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
13+
// Add UnitDefinitions\MyUnit.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 UnitsNet.Units;
41+
using Xunit;
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 SpecificEntropy.
51+
/// </summary>
52+
// ReSharper disable once PartialTypeWithSinglePart
53+
public abstract partial class SpecificEntropyTestsBase
54+
{
55+
protected abstract double CaloriesPerGramKelvinInOneJoulePerKilogramKelvin { get; }
56+
protected abstract double JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; }
57+
protected abstract double JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; }
58+
protected abstract double KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin { get; }
59+
protected abstract double KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; }
60+
protected abstract double KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; }
61+
protected abstract double MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; }
62+
protected abstract double MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; }
63+
64+
// ReSharper disable VirtualMemberNeverOverriden.Global
65+
protected virtual double CaloriesPerGramKelvinTolerance { get { return 1e-5; } }
66+
protected virtual double JoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } }
67+
protected virtual double JoulesPerKilogramKelvinTolerance { get { return 1e-5; } }
68+
protected virtual double KilocaloriesPerGramKelvinTolerance { get { return 1e-5; } }
69+
protected virtual double KilojoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } }
70+
protected virtual double KilojoulesPerKilogramKelvinTolerance { get { return 1e-5; } }
71+
protected virtual double MegajoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } }
72+
protected virtual double MegajoulesPerKilogramKelvinTolerance { get { return 1e-5; } }
73+
// ReSharper restore VirtualMemberNeverOverriden.Global
74+
75+
[Fact]
76+
public void JoulePerKilogramKelvinToSpecificEntropyUnits()
77+
{
78+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
79+
AssertEx.EqualTolerance(CaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance);
80+
AssertEx.EqualTolerance(JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance);
81+
AssertEx.EqualTolerance(JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
82+
AssertEx.EqualTolerance(KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance);
83+
AssertEx.EqualTolerance(KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance);
84+
AssertEx.EqualTolerance(KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance);
85+
AssertEx.EqualTolerance(MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance);
86+
AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance);
87+
}
88+
89+
[Fact]
90+
public void FromValueAndUnit()
91+
{
92+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.CaloriePerGramKelvin).CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance);
93+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.JoulePerKilogramDegreeCelsius).JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance);
94+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.JoulePerKilogramKelvin).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
95+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilocaloriePerGramKelvin).KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance);
96+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius).KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance);
97+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilojoulePerKilogramKelvin).KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance);
98+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius).MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance);
99+
AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.MegajoulePerKilogramKelvin).MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance);
100+
}
101+
102+
[Fact]
103+
public void As()
104+
{
105+
var jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
106+
AssertEx.EqualTolerance(CaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.CaloriePerGramKelvin), CaloriesPerGramKelvinTolerance);
107+
AssertEx.EqualTolerance(JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius), JoulesPerKilogramDegreeCelsiusTolerance);
108+
AssertEx.EqualTolerance(JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.JoulePerKilogramKelvin), JoulesPerKilogramKelvinTolerance);
109+
AssertEx.EqualTolerance(KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilocaloriePerGramKelvin), KilocaloriesPerGramKelvinTolerance);
110+
AssertEx.EqualTolerance(KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius), KilojoulesPerKilogramDegreeCelsiusTolerance);
111+
AssertEx.EqualTolerance(KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilojoulePerKilogramKelvin), KilojoulesPerKilogramKelvinTolerance);
112+
AssertEx.EqualTolerance(MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius), MegajoulesPerKilogramDegreeCelsiusTolerance);
113+
AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.MegajoulePerKilogramKelvin), MegajoulesPerKilogramKelvinTolerance);
114+
}
115+
116+
[Fact]
117+
public void ConversionRoundTrip()
118+
{
119+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
120+
AssertEx.EqualTolerance(1, SpecificEntropy.FromCaloriesPerGramKelvin(jouleperkilogramkelvin.CaloriesPerGramKelvin).JoulesPerKilogramKelvin, CaloriesPerGramKelvinTolerance);
121+
AssertEx.EqualTolerance(1, SpecificEntropy.FromJoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.JoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, JoulesPerKilogramDegreeCelsiusTolerance);
122+
AssertEx.EqualTolerance(1, SpecificEntropy.FromJoulesPerKilogramKelvin(jouleperkilogramkelvin.JoulesPerKilogramKelvin).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
123+
AssertEx.EqualTolerance(1, SpecificEntropy.FromKilocaloriesPerGramKelvin(jouleperkilogramkelvin.KilocaloriesPerGramKelvin).JoulesPerKilogramKelvin, KilocaloriesPerGramKelvinTolerance);
124+
AssertEx.EqualTolerance(1, SpecificEntropy.FromKilojoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.KilojoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, KilojoulesPerKilogramDegreeCelsiusTolerance);
125+
AssertEx.EqualTolerance(1, SpecificEntropy.FromKilojoulesPerKilogramKelvin(jouleperkilogramkelvin.KilojoulesPerKilogramKelvin).JoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance);
126+
AssertEx.EqualTolerance(1, SpecificEntropy.FromMegajoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.MegajoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, MegajoulesPerKilogramDegreeCelsiusTolerance);
127+
AssertEx.EqualTolerance(1, SpecificEntropy.FromMegajoulesPerKilogramKelvin(jouleperkilogramkelvin.MegajoulesPerKilogramKelvin).JoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance);
128+
}
129+
130+
[Fact]
131+
public void ArithmeticOperators()
132+
{
133+
SpecificEntropy v = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
134+
AssertEx.EqualTolerance(-1, -v.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
135+
AssertEx.EqualTolerance(2, (SpecificEntropy.FromJoulesPerKilogramKelvin(3)-v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
136+
AssertEx.EqualTolerance(2, (v + v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
137+
AssertEx.EqualTolerance(10, (v*10).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
138+
AssertEx.EqualTolerance(10, (10*v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
139+
AssertEx.EqualTolerance(2, (SpecificEntropy.FromJoulesPerKilogramKelvin(10)/5).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance);
140+
AssertEx.EqualTolerance(2, SpecificEntropy.FromJoulesPerKilogramKelvin(10)/SpecificEntropy.FromJoulesPerKilogramKelvin(5), JoulesPerKilogramKelvinTolerance);
141+
}
142+
143+
[Fact]
144+
public void ComparisonOperators()
145+
{
146+
SpecificEntropy oneJoulePerKilogramKelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
147+
SpecificEntropy twoJoulesPerKilogramKelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(2);
148+
149+
Assert.True(oneJoulePerKilogramKelvin < twoJoulesPerKilogramKelvin);
150+
Assert.True(oneJoulePerKilogramKelvin <= twoJoulesPerKilogramKelvin);
151+
Assert.True(twoJoulesPerKilogramKelvin > oneJoulePerKilogramKelvin);
152+
Assert.True(twoJoulesPerKilogramKelvin >= oneJoulePerKilogramKelvin);
153+
154+
Assert.False(oneJoulePerKilogramKelvin > twoJoulesPerKilogramKelvin);
155+
Assert.False(oneJoulePerKilogramKelvin >= twoJoulesPerKilogramKelvin);
156+
Assert.False(twoJoulesPerKilogramKelvin < oneJoulePerKilogramKelvin);
157+
Assert.False(twoJoulesPerKilogramKelvin <= oneJoulePerKilogramKelvin);
158+
}
159+
160+
[Fact]
161+
public void CompareToIsImplemented()
162+
{
163+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
164+
Assert.Equal(0, jouleperkilogramkelvin.CompareTo(jouleperkilogramkelvin));
165+
Assert.True(jouleperkilogramkelvin.CompareTo(SpecificEntropy.Zero) > 0);
166+
Assert.True(SpecificEntropy.Zero.CompareTo(jouleperkilogramkelvin) < 0);
167+
}
168+
169+
[Fact]
170+
public void CompareToThrowsOnTypeMismatch()
171+
{
172+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
173+
Assert.Throws<ArgumentException>(() => jouleperkilogramkelvin.CompareTo(new object()));
174+
}
175+
176+
[Fact]
177+
public void CompareToThrowsOnNull()
178+
{
179+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
180+
Assert.Throws<ArgumentNullException>(() => jouleperkilogramkelvin.CompareTo(null));
181+
}
182+
183+
184+
[Fact]
185+
public void EqualityOperators()
186+
{
187+
SpecificEntropy a = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
188+
SpecificEntropy b = SpecificEntropy.FromJoulesPerKilogramKelvin(2);
189+
190+
// ReSharper disable EqualExpressionComparison
191+
Assert.True(a == a);
192+
Assert.True(a != b);
193+
194+
Assert.False(a == b);
195+
Assert.False(a != a);
196+
// ReSharper restore EqualExpressionComparison
197+
}
198+
199+
[Fact]
200+
public void EqualsIsImplemented()
201+
{
202+
SpecificEntropy v = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
203+
Assert.True(v.Equals(SpecificEntropy.FromJoulesPerKilogramKelvin(1)));
204+
Assert.False(v.Equals(SpecificEntropy.Zero));
205+
}
206+
207+
[Fact]
208+
public void EqualsReturnsFalseOnTypeMismatch()
209+
{
210+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
211+
Assert.False(jouleperkilogramkelvin.Equals(new object()));
212+
}
213+
214+
[Fact]
215+
public void EqualsReturnsFalseOnNull()
216+
{
217+
SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1);
218+
Assert.False(jouleperkilogramkelvin.Equals(null));
219+
}
220+
}
221+
}

0 commit comments

Comments
 (0)