Skip to content

Commit b6a1863

Browse files
baxcodersangularsen
authored andcommitted
Add Irradiance: WattPerSquareMeter (W/m²) + prefixes k (#385)
1 parent 7c8a9e2 commit b6a1863

File tree

8 files changed

+1168
-0
lines changed

8 files changed

+1168
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 (andreas.larsen84@gmail.com).
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 IrradianceTests : IrradianceTestsBase
48+
{
49+
/// <summary>
50+
/// Gets the kilowatt per square meter in one watt per square meter.
51+
/// </summary>
52+
protected override double KilowattsPerSquareMeterInOneWattPerSquareMeter => 1E-3;
53+
54+
/// <summary>
55+
/// Gets the watt per square meter in one watt per square meter.
56+
/// </summary>
57+
protected override double WattsPerSquareMeterInOneWattPerSquareMeter => 1;
58+
}
59+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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 (andreas.larsen84@gmail.com).
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 Irradiance.
51+
/// </summary>
52+
// ReSharper disable once PartialTypeWithSinglePart
53+
public abstract partial class IrradianceTestsBase
54+
{
55+
protected abstract double KilowattsPerSquareMeterInOneWattPerSquareMeter { get; }
56+
protected abstract double WattsPerSquareMeterInOneWattPerSquareMeter { get; }
57+
58+
// ReSharper disable VirtualMemberNeverOverriden.Global
59+
protected virtual double KilowattsPerSquareMeterTolerance { get { return 1e-5; } }
60+
protected virtual double WattsPerSquareMeterTolerance { get { return 1e-5; } }
61+
// ReSharper restore VirtualMemberNeverOverriden.Global
62+
63+
[Fact]
64+
public void WattPerSquareMeterToIrradianceUnits()
65+
{
66+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
67+
AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance);
68+
AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.WattsPerSquareMeter, WattsPerSquareMeterTolerance);
69+
}
70+
71+
[Fact]
72+
public void FromValueAndUnit()
73+
{
74+
AssertEx.EqualTolerance(1, Irradiance.From(1, IrradianceUnit.KilowattPerSquareMeter).KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance);
75+
AssertEx.EqualTolerance(1, Irradiance.From(1, IrradianceUnit.WattPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
76+
}
77+
78+
[Fact]
79+
public void As()
80+
{
81+
var wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
82+
AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(IrradianceUnit.KilowattPerSquareMeter), KilowattsPerSquareMeterTolerance);
83+
AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(IrradianceUnit.WattPerSquareMeter), WattsPerSquareMeterTolerance);
84+
}
85+
86+
[Fact]
87+
public void ConversionRoundTrip()
88+
{
89+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
90+
AssertEx.EqualTolerance(1, Irradiance.FromKilowattsPerSquareMeter(wattpersquaremeter.KilowattsPerSquareMeter).WattsPerSquareMeter, KilowattsPerSquareMeterTolerance);
91+
AssertEx.EqualTolerance(1, Irradiance.FromWattsPerSquareMeter(wattpersquaremeter.WattsPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
92+
}
93+
94+
[Fact]
95+
public void ArithmeticOperators()
96+
{
97+
Irradiance v = Irradiance.FromWattsPerSquareMeter(1);
98+
AssertEx.EqualTolerance(-1, -v.WattsPerSquareMeter, WattsPerSquareMeterTolerance);
99+
AssertEx.EqualTolerance(2, (Irradiance.FromWattsPerSquareMeter(3)-v).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
100+
AssertEx.EqualTolerance(2, (v + v).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
101+
AssertEx.EqualTolerance(10, (v*10).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
102+
AssertEx.EqualTolerance(10, (10*v).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
103+
AssertEx.EqualTolerance(2, (Irradiance.FromWattsPerSquareMeter(10)/5).WattsPerSquareMeter, WattsPerSquareMeterTolerance);
104+
AssertEx.EqualTolerance(2, Irradiance.FromWattsPerSquareMeter(10)/Irradiance.FromWattsPerSquareMeter(5), WattsPerSquareMeterTolerance);
105+
}
106+
107+
[Fact]
108+
public void ComparisonOperators()
109+
{
110+
Irradiance oneWattPerSquareMeter = Irradiance.FromWattsPerSquareMeter(1);
111+
Irradiance twoWattsPerSquareMeter = Irradiance.FromWattsPerSquareMeter(2);
112+
113+
Assert.True(oneWattPerSquareMeter < twoWattsPerSquareMeter);
114+
Assert.True(oneWattPerSquareMeter <= twoWattsPerSquareMeter);
115+
Assert.True(twoWattsPerSquareMeter > oneWattPerSquareMeter);
116+
Assert.True(twoWattsPerSquareMeter >= oneWattPerSquareMeter);
117+
118+
Assert.False(oneWattPerSquareMeter > twoWattsPerSquareMeter);
119+
Assert.False(oneWattPerSquareMeter >= twoWattsPerSquareMeter);
120+
Assert.False(twoWattsPerSquareMeter < oneWattPerSquareMeter);
121+
Assert.False(twoWattsPerSquareMeter <= oneWattPerSquareMeter);
122+
}
123+
124+
[Fact]
125+
public void CompareToIsImplemented()
126+
{
127+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
128+
Assert.Equal(0, wattpersquaremeter.CompareTo(wattpersquaremeter));
129+
Assert.True(wattpersquaremeter.CompareTo(Irradiance.Zero) > 0);
130+
Assert.True(Irradiance.Zero.CompareTo(wattpersquaremeter) < 0);
131+
}
132+
133+
[Fact]
134+
public void CompareToThrowsOnTypeMismatch()
135+
{
136+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
137+
Assert.Throws<ArgumentException>(() => wattpersquaremeter.CompareTo(new object()));
138+
}
139+
140+
[Fact]
141+
public void CompareToThrowsOnNull()
142+
{
143+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
144+
Assert.Throws<ArgumentNullException>(() => wattpersquaremeter.CompareTo(null));
145+
}
146+
147+
148+
[Fact]
149+
public void EqualityOperators()
150+
{
151+
Irradiance a = Irradiance.FromWattsPerSquareMeter(1);
152+
Irradiance b = Irradiance.FromWattsPerSquareMeter(2);
153+
154+
// ReSharper disable EqualExpressionComparison
155+
Assert.True(a == a);
156+
Assert.True(a != b);
157+
158+
Assert.False(a == b);
159+
Assert.False(a != a);
160+
// ReSharper restore EqualExpressionComparison
161+
}
162+
163+
[Fact]
164+
public void EqualsIsImplemented()
165+
{
166+
Irradiance v = Irradiance.FromWattsPerSquareMeter(1);
167+
Assert.True(v.Equals(Irradiance.FromWattsPerSquareMeter(1), Irradiance.FromWattsPerSquareMeter(WattsPerSquareMeterTolerance)));
168+
Assert.False(v.Equals(Irradiance.Zero, Irradiance.FromWattsPerSquareMeter(WattsPerSquareMeterTolerance)));
169+
}
170+
171+
[Fact]
172+
public void EqualsReturnsFalseOnTypeMismatch()
173+
{
174+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
175+
Assert.False(wattpersquaremeter.Equals(new object()));
176+
}
177+
178+
[Fact]
179+
public void EqualsReturnsFalseOnNull()
180+
{
181+
Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1);
182+
Assert.False(wattpersquaremeter.Equals(null));
183+
}
184+
}
185+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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 (andreas.larsen84@gmail.com).
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.NumberToIrradiance
44+
{
45+
public static class NumberToIrradianceExtensions
46+
{
47+
#region KilowattPerSquareMeter
48+
49+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double)"/>
50+
public static Irradiance KilowattsPerSquareMeter(this int value) => Irradiance.FromKilowattsPerSquareMeter(value);
51+
52+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double?)"/>
53+
public static Irradiance? KilowattsPerSquareMeter(this int? value) => Irradiance.FromKilowattsPerSquareMeter(value);
54+
55+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double)"/>
56+
public static Irradiance KilowattsPerSquareMeter(this long value) => Irradiance.FromKilowattsPerSquareMeter(value);
57+
58+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double?)"/>
59+
public static Irradiance? KilowattsPerSquareMeter(this long? value) => Irradiance.FromKilowattsPerSquareMeter(value);
60+
61+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double)"/>
62+
public static Irradiance KilowattsPerSquareMeter(this double value) => Irradiance.FromKilowattsPerSquareMeter(value);
63+
64+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double?)"/>
65+
public static Irradiance? KilowattsPerSquareMeter(this double? value) => Irradiance.FromKilowattsPerSquareMeter(value);
66+
67+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double)"/>
68+
public static Irradiance KilowattsPerSquareMeter(this float value) => Irradiance.FromKilowattsPerSquareMeter(value);
69+
70+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double?)"/>
71+
public static Irradiance? KilowattsPerSquareMeter(this float? value) => Irradiance.FromKilowattsPerSquareMeter(value);
72+
73+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double)"/>
74+
public static Irradiance KilowattsPerSquareMeter(this decimal value) => Irradiance.FromKilowattsPerSquareMeter(Convert.ToDouble(value));
75+
76+
/// <inheritdoc cref="Irradiance.FromKilowattsPerSquareMeter(double?)"/>
77+
public static Irradiance? KilowattsPerSquareMeter(this decimal? value) => Irradiance.FromKilowattsPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
78+
79+
#endregion
80+
81+
#region WattPerSquareMeter
82+
83+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double)"/>
84+
public static Irradiance WattsPerSquareMeter(this int value) => Irradiance.FromWattsPerSquareMeter(value);
85+
86+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double?)"/>
87+
public static Irradiance? WattsPerSquareMeter(this int? value) => Irradiance.FromWattsPerSquareMeter(value);
88+
89+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double)"/>
90+
public static Irradiance WattsPerSquareMeter(this long value) => Irradiance.FromWattsPerSquareMeter(value);
91+
92+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double?)"/>
93+
public static Irradiance? WattsPerSquareMeter(this long? value) => Irradiance.FromWattsPerSquareMeter(value);
94+
95+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double)"/>
96+
public static Irradiance WattsPerSquareMeter(this double value) => Irradiance.FromWattsPerSquareMeter(value);
97+
98+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double?)"/>
99+
public static Irradiance? WattsPerSquareMeter(this double? value) => Irradiance.FromWattsPerSquareMeter(value);
100+
101+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double)"/>
102+
public static Irradiance WattsPerSquareMeter(this float value) => Irradiance.FromWattsPerSquareMeter(value);
103+
104+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double?)"/>
105+
public static Irradiance? WattsPerSquareMeter(this float? value) => Irradiance.FromWattsPerSquareMeter(value);
106+
107+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double)"/>
108+
public static Irradiance WattsPerSquareMeter(this decimal value) => Irradiance.FromWattsPerSquareMeter(Convert.ToDouble(value));
109+
110+
/// <inheritdoc cref="Irradiance.FromWattsPerSquareMeter(double?)"/>
111+
public static Irradiance? WattsPerSquareMeter(this decimal? value) => Irradiance.FromWattsPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
112+
113+
#endregion
114+
115+
}
116+
}
117+
#endif

0 commit comments

Comments
 (0)