Skip to content

Commit 7c8a9e2

Browse files
baxcodersangularsen
authored andcommitted
Add ApparentEnergy: VoltamperesHour (VAh) + k,M prefixes (#382)
1 parent 44fe85b commit 7c8a9e2

File tree

8 files changed

+1257
-0
lines changed

8 files changed

+1257
-0
lines changed
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\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 ApparentEnergyTests : ApparentEnergyTestsBase
48+
{
49+
protected override double VoltampereHoursInOneVoltampereHour => 1;
50+
51+
protected override double KilovoltampereHoursInOneVoltampereHour => 1E-3;
52+
53+
protected override double MegavoltampereHoursInOneVoltampereHour => 1E-6;
54+
}
55+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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 ApparentEnergy.
51+
/// </summary>
52+
// ReSharper disable once PartialTypeWithSinglePart
53+
public abstract partial class ApparentEnergyTestsBase
54+
{
55+
protected abstract double KilovoltampereHoursInOneVoltampereHour { get; }
56+
protected abstract double MegavoltampereHoursInOneVoltampereHour { get; }
57+
protected abstract double VoltampereHoursInOneVoltampereHour { get; }
58+
59+
// ReSharper disable VirtualMemberNeverOverriden.Global
60+
protected virtual double KilovoltampereHoursTolerance { get { return 1e-5; } }
61+
protected virtual double MegavoltampereHoursTolerance { get { return 1e-5; } }
62+
protected virtual double VoltampereHoursTolerance { get { return 1e-5; } }
63+
// ReSharper restore VirtualMemberNeverOverriden.Global
64+
65+
[Fact]
66+
public void VoltampereHourToApparentEnergyUnits()
67+
{
68+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
69+
AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.KilovoltampereHours, KilovoltampereHoursTolerance);
70+
AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.MegavoltampereHours, MegavoltampereHoursTolerance);
71+
AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.VoltampereHours, VoltampereHoursTolerance);
72+
}
73+
74+
[Fact]
75+
public void FromValueAndUnit()
76+
{
77+
AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.KilovoltampereHour).KilovoltampereHours, KilovoltampereHoursTolerance);
78+
AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.MegavoltampereHour).MegavoltampereHours, MegavoltampereHoursTolerance);
79+
AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.VoltampereHour).VoltampereHours, VoltampereHoursTolerance);
80+
}
81+
82+
[Fact]
83+
public void As()
84+
{
85+
var voltamperehour = ApparentEnergy.FromVoltampereHours(1);
86+
AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.KilovoltampereHour), KilovoltampereHoursTolerance);
87+
AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.MegavoltampereHour), MegavoltampereHoursTolerance);
88+
AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.VoltampereHour), VoltampereHoursTolerance);
89+
}
90+
91+
[Fact]
92+
public void ConversionRoundTrip()
93+
{
94+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
95+
AssertEx.EqualTolerance(1, ApparentEnergy.FromKilovoltampereHours(voltamperehour.KilovoltampereHours).VoltampereHours, KilovoltampereHoursTolerance);
96+
AssertEx.EqualTolerance(1, ApparentEnergy.FromMegavoltampereHours(voltamperehour.MegavoltampereHours).VoltampereHours, MegavoltampereHoursTolerance);
97+
AssertEx.EqualTolerance(1, ApparentEnergy.FromVoltampereHours(voltamperehour.VoltampereHours).VoltampereHours, VoltampereHoursTolerance);
98+
}
99+
100+
[Fact]
101+
public void ArithmeticOperators()
102+
{
103+
ApparentEnergy v = ApparentEnergy.FromVoltampereHours(1);
104+
AssertEx.EqualTolerance(-1, -v.VoltampereHours, VoltampereHoursTolerance);
105+
AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(3)-v).VoltampereHours, VoltampereHoursTolerance);
106+
AssertEx.EqualTolerance(2, (v + v).VoltampereHours, VoltampereHoursTolerance);
107+
AssertEx.EqualTolerance(10, (v*10).VoltampereHours, VoltampereHoursTolerance);
108+
AssertEx.EqualTolerance(10, (10*v).VoltampereHours, VoltampereHoursTolerance);
109+
AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(10)/5).VoltampereHours, VoltampereHoursTolerance);
110+
AssertEx.EqualTolerance(2, ApparentEnergy.FromVoltampereHours(10)/ApparentEnergy.FromVoltampereHours(5), VoltampereHoursTolerance);
111+
}
112+
113+
[Fact]
114+
public void ComparisonOperators()
115+
{
116+
ApparentEnergy oneVoltampereHour = ApparentEnergy.FromVoltampereHours(1);
117+
ApparentEnergy twoVoltampereHours = ApparentEnergy.FromVoltampereHours(2);
118+
119+
Assert.True(oneVoltampereHour < twoVoltampereHours);
120+
Assert.True(oneVoltampereHour <= twoVoltampereHours);
121+
Assert.True(twoVoltampereHours > oneVoltampereHour);
122+
Assert.True(twoVoltampereHours >= oneVoltampereHour);
123+
124+
Assert.False(oneVoltampereHour > twoVoltampereHours);
125+
Assert.False(oneVoltampereHour >= twoVoltampereHours);
126+
Assert.False(twoVoltampereHours < oneVoltampereHour);
127+
Assert.False(twoVoltampereHours <= oneVoltampereHour);
128+
}
129+
130+
[Fact]
131+
public void CompareToIsImplemented()
132+
{
133+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
134+
Assert.Equal(0, voltamperehour.CompareTo(voltamperehour));
135+
Assert.True(voltamperehour.CompareTo(ApparentEnergy.Zero) > 0);
136+
Assert.True(ApparentEnergy.Zero.CompareTo(voltamperehour) < 0);
137+
}
138+
139+
[Fact]
140+
public void CompareToThrowsOnTypeMismatch()
141+
{
142+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
143+
Assert.Throws<ArgumentException>(() => voltamperehour.CompareTo(new object()));
144+
}
145+
146+
[Fact]
147+
public void CompareToThrowsOnNull()
148+
{
149+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
150+
Assert.Throws<ArgumentNullException>(() => voltamperehour.CompareTo(null));
151+
}
152+
153+
154+
[Fact]
155+
public void EqualityOperators()
156+
{
157+
ApparentEnergy a = ApparentEnergy.FromVoltampereHours(1);
158+
ApparentEnergy b = ApparentEnergy.FromVoltampereHours(2);
159+
160+
// ReSharper disable EqualExpressionComparison
161+
Assert.True(a == a);
162+
Assert.True(a != b);
163+
164+
Assert.False(a == b);
165+
Assert.False(a != a);
166+
// ReSharper restore EqualExpressionComparison
167+
}
168+
169+
[Fact]
170+
public void EqualsIsImplemented()
171+
{
172+
ApparentEnergy v = ApparentEnergy.FromVoltampereHours(1);
173+
Assert.True(v.Equals(ApparentEnergy.FromVoltampereHours(1), ApparentEnergy.FromVoltampereHours(VoltampereHoursTolerance)));
174+
Assert.False(v.Equals(ApparentEnergy.Zero, ApparentEnergy.FromVoltampereHours(VoltampereHoursTolerance)));
175+
}
176+
177+
[Fact]
178+
public void EqualsReturnsFalseOnTypeMismatch()
179+
{
180+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
181+
Assert.False(voltamperehour.Equals(new object()));
182+
}
183+
184+
[Fact]
185+
public void EqualsReturnsFalseOnNull()
186+
{
187+
ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1);
188+
Assert.False(voltamperehour.Equals(null));
189+
}
190+
}
191+
}

0 commit comments

Comments
 (0)