Skip to content

Commit bc9df72

Browse files
committed
Adding power density units
1 parent 3c6e4ed commit bc9df72

File tree

8 files changed

+1196
-0
lines changed

8 files changed

+1196
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 PowerDensityTests : PowerDensityTestsBase
48+
{
49+
protected override double WattsPerCubicMeterInOneWattPerCubicMeter => 1;
50+
}
51+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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 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 PowerDensity.
51+
/// </summary>
52+
// ReSharper disable once PartialTypeWithSinglePart
53+
public abstract partial class PowerDensityTestsBase
54+
{
55+
protected abstract double WattsPerCubicMeterInOneWattPerCubicMeter { get; }
56+
57+
// ReSharper disable VirtualMemberNeverOverriden.Global
58+
protected virtual double WattsPerCubicMeterTolerance { get { return 1e-5; } }
59+
// ReSharper restore VirtualMemberNeverOverriden.Global
60+
61+
[Fact]
62+
public void WattPerCubicMeterToPowerDensityUnits()
63+
{
64+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
65+
AssertEx.EqualTolerance(WattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.WattsPerCubicMeter, WattsPerCubicMeterTolerance);
66+
}
67+
68+
[Fact]
69+
public void FromValueAndUnit()
70+
{
71+
AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.WattPerCubicMeter).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
72+
}
73+
74+
[Fact]
75+
public void As()
76+
{
77+
var wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
78+
AssertEx.EqualTolerance(WattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerCubicMeter), WattsPerCubicMeterTolerance);
79+
}
80+
81+
[Fact]
82+
public void ConversionRoundTrip()
83+
{
84+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
85+
AssertEx.EqualTolerance(1, PowerDensity.FromWattsPerCubicMeter(wattpercubicmeter.WattsPerCubicMeter).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
86+
}
87+
88+
[Fact]
89+
public void ArithmeticOperators()
90+
{
91+
PowerDensity v = PowerDensity.FromWattsPerCubicMeter(1);
92+
AssertEx.EqualTolerance(-1, -v.WattsPerCubicMeter, WattsPerCubicMeterTolerance);
93+
AssertEx.EqualTolerance(2, (PowerDensity.FromWattsPerCubicMeter(3)-v).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
94+
AssertEx.EqualTolerance(2, (v + v).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
95+
AssertEx.EqualTolerance(10, (v*10).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
96+
AssertEx.EqualTolerance(10, (10*v).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
97+
AssertEx.EqualTolerance(2, (PowerDensity.FromWattsPerCubicMeter(10)/5).WattsPerCubicMeter, WattsPerCubicMeterTolerance);
98+
AssertEx.EqualTolerance(2, PowerDensity.FromWattsPerCubicMeter(10)/PowerDensity.FromWattsPerCubicMeter(5), WattsPerCubicMeterTolerance);
99+
}
100+
101+
[Fact]
102+
public void ComparisonOperators()
103+
{
104+
PowerDensity oneWattPerCubicMeter = PowerDensity.FromWattsPerCubicMeter(1);
105+
PowerDensity twoWattsPerCubicMeter = PowerDensity.FromWattsPerCubicMeter(2);
106+
107+
Assert.True(oneWattPerCubicMeter < twoWattsPerCubicMeter);
108+
Assert.True(oneWattPerCubicMeter <= twoWattsPerCubicMeter);
109+
Assert.True(twoWattsPerCubicMeter > oneWattPerCubicMeter);
110+
Assert.True(twoWattsPerCubicMeter >= oneWattPerCubicMeter);
111+
112+
Assert.False(oneWattPerCubicMeter > twoWattsPerCubicMeter);
113+
Assert.False(oneWattPerCubicMeter >= twoWattsPerCubicMeter);
114+
Assert.False(twoWattsPerCubicMeter < oneWattPerCubicMeter);
115+
Assert.False(twoWattsPerCubicMeter <= oneWattPerCubicMeter);
116+
}
117+
118+
[Fact]
119+
public void CompareToIsImplemented()
120+
{
121+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
122+
Assert.Equal(0, wattpercubicmeter.CompareTo(wattpercubicmeter));
123+
Assert.True(wattpercubicmeter.CompareTo(PowerDensity.Zero) > 0);
124+
Assert.True(PowerDensity.Zero.CompareTo(wattpercubicmeter) < 0);
125+
}
126+
127+
[Fact]
128+
public void CompareToThrowsOnTypeMismatch()
129+
{
130+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
131+
Assert.Throws<ArgumentException>(() => wattpercubicmeter.CompareTo(new object()));
132+
}
133+
134+
[Fact]
135+
public void CompareToThrowsOnNull()
136+
{
137+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
138+
Assert.Throws<ArgumentNullException>(() => wattpercubicmeter.CompareTo(null));
139+
}
140+
141+
142+
[Fact]
143+
public void EqualityOperators()
144+
{
145+
PowerDensity a = PowerDensity.FromWattsPerCubicMeter(1);
146+
PowerDensity b = PowerDensity.FromWattsPerCubicMeter(2);
147+
148+
// ReSharper disable EqualExpressionComparison
149+
Assert.True(a == a);
150+
Assert.True(a != b);
151+
152+
Assert.False(a == b);
153+
Assert.False(a != a);
154+
// ReSharper restore EqualExpressionComparison
155+
}
156+
157+
[Fact]
158+
public void EqualsIsImplemented()
159+
{
160+
PowerDensity v = PowerDensity.FromWattsPerCubicMeter(1);
161+
Assert.True(v.Equals(PowerDensity.FromWattsPerCubicMeter(1), PowerDensity.FromWattsPerCubicMeter(WattsPerCubicMeterTolerance)));
162+
Assert.False(v.Equals(PowerDensity.Zero, PowerDensity.FromWattsPerCubicMeter(WattsPerCubicMeterTolerance)));
163+
}
164+
165+
[Fact]
166+
public void EqualsReturnsFalseOnTypeMismatch()
167+
{
168+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
169+
Assert.False(wattpercubicmeter.Equals(new object()));
170+
}
171+
172+
[Fact]
173+
public void EqualsReturnsFalseOnNull()
174+
{
175+
PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1);
176+
Assert.False(wattpercubicmeter.Equals(null));
177+
}
178+
}
179+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
41+
// Windows Runtime Component does not support extension methods and method overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
42+
#if !WINDOWS_UWP
43+
namespace UnitsNet.Extensions.NumberToPowerDensity
44+
{
45+
public static class NumberToPowerDensityExtensions
46+
{
47+
#region WattPerCubicMeter
48+
49+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
50+
public static PowerDensity WattsPerCubicMeter(this int value) => PowerDensity.FromWattsPerCubicMeter(value);
51+
52+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
53+
public static PowerDensity? WattsPerCubicMeter(this int? value) => PowerDensity.FromWattsPerCubicMeter(value);
54+
55+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
56+
public static PowerDensity WattsPerCubicMeter(this long value) => PowerDensity.FromWattsPerCubicMeter(value);
57+
58+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
59+
public static PowerDensity? WattsPerCubicMeter(this long? value) => PowerDensity.FromWattsPerCubicMeter(value);
60+
61+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
62+
public static PowerDensity WattsPerCubicMeter(this double value) => PowerDensity.FromWattsPerCubicMeter(value);
63+
64+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
65+
public static PowerDensity? WattsPerCubicMeter(this double? value) => PowerDensity.FromWattsPerCubicMeter(value);
66+
67+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
68+
public static PowerDensity WattsPerCubicMeter(this float value) => PowerDensity.FromWattsPerCubicMeter(value);
69+
70+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
71+
public static PowerDensity? WattsPerCubicMeter(this float? value) => PowerDensity.FromWattsPerCubicMeter(value);
72+
73+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
74+
public static PowerDensity WattsPerCubicMeter(this decimal value) => PowerDensity.FromWattsPerCubicMeter(Convert.ToDouble(value));
75+
76+
/// <inheritdoc cref="PowerDensity.FromWattsPerCubicMeter(UnitsNet.QuantityValue)" />
77+
public static PowerDensity? WattsPerCubicMeter(this decimal? value) => PowerDensity.FromWattsPerCubicMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
78+
79+
#endregion
80+
81+
}
82+
}
83+
#endif

0 commit comments

Comments
 (0)