Skip to content

Commit 5028699

Browse files
tmilnthorpangularsen
authored andcommitted
Add centiampere (#464)
1 parent 46a96df commit 5028699

File tree

8 files changed

+83
-2
lines changed

8 files changed

+83
-2
lines changed

Common/GeneratedCode/Quantities/ElectricCurrent.Common.g.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public static BaseDimensions BaseDimensions
163163
/// </summary>
164164
public double Amperes => As(ElectricCurrentUnit.Ampere);
165165

166+
/// <summary>
167+
/// Get ElectricCurrent in Centiamperes.
168+
/// </summary>
169+
public double Centiamperes => As(ElectricCurrentUnit.Centiampere);
170+
166171
/// <summary>
167172
/// Get ElectricCurrent in Kiloamperes.
168173
/// </summary>
@@ -213,6 +218,20 @@ public static ElectricCurrent FromAmperes(QuantityValue amperes)
213218
return new ElectricCurrent(value, ElectricCurrentUnit.Ampere);
214219
}
215220

221+
/// <summary>
222+
/// Get ElectricCurrent from Centiamperes.
223+
/// </summary>
224+
#if WINDOWS_UWP
225+
[Windows.Foundation.Metadata.DefaultOverload]
226+
public static ElectricCurrent FromCentiamperes(double centiamperes)
227+
#else
228+
public static ElectricCurrent FromCentiamperes(QuantityValue centiamperes)
229+
#endif
230+
{
231+
double value = (double) centiamperes;
232+
return new ElectricCurrent(value, ElectricCurrentUnit.Centiampere);
233+
}
234+
216235
/// <summary>
217236
/// Get ElectricCurrent from Kiloamperes.
218237
/// </summary>
@@ -495,6 +514,7 @@ private double AsBaseUnit()
495514
switch(Unit)
496515
{
497516
case ElectricCurrentUnit.Ampere: return _value;
517+
case ElectricCurrentUnit.Centiampere: return (_value) * 1e-2d;
498518
case ElectricCurrentUnit.Kiloampere: return (_value) * 1e3d;
499519
case ElectricCurrentUnit.Megaampere: return (_value) * 1e6d;
500520
case ElectricCurrentUnit.Microampere: return (_value) * 1e-6d;
@@ -516,6 +536,7 @@ private double AsBaseNumericType(ElectricCurrentUnit unit)
516536
switch(unit)
517537
{
518538
case ElectricCurrentUnit.Ampere: return baseUnitValue;
539+
case ElectricCurrentUnit.Centiampere: return (baseUnitValue) / 1e-2d;
519540
case ElectricCurrentUnit.Kiloampere: return (baseUnitValue) / 1e3d;
520541
case ElectricCurrentUnit.Megaampere: return (baseUnitValue) / 1e6d;
521542
case ElectricCurrentUnit.Microampere: return (baseUnitValue) / 1e-6d;

Common/UnitDefinitions/ElectricCurrent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"PluralName": "Amperes",
1212
"FromUnitToBaseFunc": "x",
1313
"FromBaseToUnitFunc": "x",
14-
"Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ],
14+
"Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Kilo", "Mega" ],
1515
"Localization": [
1616
{
1717
"Culture": "en-US",

UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public class ElectricCurrentTests : ElectricCurrentTestsBase
3333

3434
protected override double MilliamperesInOneAmpere => 1e3;
3535

36+
protected override double CentiamperesInOneAmpere => 1e2;
37+
3638
protected override double AmperesInOneAmpere => 1;
3739

3840
protected override double KiloamperesInOneAmpere => 1e-3;
3941

4042
protected override double MegaamperesInOneAmpere => 1e-6;
4143

4244
}
43-
}
45+
}

UnitsNet.Tests/GeneratedCode/ElectricCurrentTestsBase.g.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace UnitsNet.Tests
5353
public abstract partial class ElectricCurrentTestsBase
5454
{
5555
protected abstract double AmperesInOneAmpere { get; }
56+
protected abstract double CentiamperesInOneAmpere { get; }
5657
protected abstract double KiloamperesInOneAmpere { get; }
5758
protected abstract double MegaamperesInOneAmpere { get; }
5859
protected abstract double MicroamperesInOneAmpere { get; }
@@ -62,6 +63,7 @@ public abstract partial class ElectricCurrentTestsBase
6263

6364
// ReSharper disable VirtualMemberNeverOverriden.Global
6465
protected virtual double AmperesTolerance { get { return 1e-5; } }
66+
protected virtual double CentiamperesTolerance { get { return 1e-5; } }
6567
protected virtual double KiloamperesTolerance { get { return 1e-5; } }
6668
protected virtual double MegaamperesTolerance { get { return 1e-5; } }
6769
protected virtual double MicroamperesTolerance { get { return 1e-5; } }
@@ -75,6 +77,7 @@ public void AmpereToElectricCurrentUnits()
7577
{
7678
ElectricCurrent ampere = ElectricCurrent.FromAmperes(1);
7779
AssertEx.EqualTolerance(AmperesInOneAmpere, ampere.Amperes, AmperesTolerance);
80+
AssertEx.EqualTolerance(CentiamperesInOneAmpere, ampere.Centiamperes, CentiamperesTolerance);
7881
AssertEx.EqualTolerance(KiloamperesInOneAmpere, ampere.Kiloamperes, KiloamperesTolerance);
7982
AssertEx.EqualTolerance(MegaamperesInOneAmpere, ampere.Megaamperes, MegaamperesTolerance);
8083
AssertEx.EqualTolerance(MicroamperesInOneAmpere, ampere.Microamperes, MicroamperesTolerance);
@@ -87,6 +90,7 @@ public void AmpereToElectricCurrentUnits()
8790
public void FromValueAndUnit()
8891
{
8992
AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Ampere).Amperes, AmperesTolerance);
93+
AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Centiampere).Centiamperes, CentiamperesTolerance);
9094
AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Kiloampere).Kiloamperes, KiloamperesTolerance);
9195
AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Megaampere).Megaamperes, MegaamperesTolerance);
9296
AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Microampere).Microamperes, MicroamperesTolerance);
@@ -100,6 +104,7 @@ public void As()
100104
{
101105
var ampere = ElectricCurrent.FromAmperes(1);
102106
AssertEx.EqualTolerance(AmperesInOneAmpere, ampere.As(ElectricCurrentUnit.Ampere), AmperesTolerance);
107+
AssertEx.EqualTolerance(CentiamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Centiampere), CentiamperesTolerance);
103108
AssertEx.EqualTolerance(KiloamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Kiloampere), KiloamperesTolerance);
104109
AssertEx.EqualTolerance(MegaamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Megaampere), MegaamperesTolerance);
105110
AssertEx.EqualTolerance(MicroamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Microampere), MicroamperesTolerance);
@@ -117,6 +122,10 @@ public void ToUnit()
117122
AssertEx.EqualTolerance(AmperesInOneAmpere, (double)ampereQuantity.Value, AmperesTolerance);
118123
Assert.Equal(ElectricCurrentUnit.Ampere, ampereQuantity.Unit);
119124

125+
var centiampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Centiampere);
126+
AssertEx.EqualTolerance(CentiamperesInOneAmpere, (double)centiampereQuantity.Value, CentiamperesTolerance);
127+
Assert.Equal(ElectricCurrentUnit.Centiampere, centiampereQuantity.Unit);
128+
120129
var kiloampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Kiloampere);
121130
AssertEx.EqualTolerance(KiloamperesInOneAmpere, (double)kiloampereQuantity.Value, KiloamperesTolerance);
122131
Assert.Equal(ElectricCurrentUnit.Kiloampere, kiloampereQuantity.Unit);
@@ -147,6 +156,7 @@ public void ConversionRoundTrip()
147156
{
148157
ElectricCurrent ampere = ElectricCurrent.FromAmperes(1);
149158
AssertEx.EqualTolerance(1, ElectricCurrent.FromAmperes(ampere.Amperes).Amperes, AmperesTolerance);
159+
AssertEx.EqualTolerance(1, ElectricCurrent.FromCentiamperes(ampere.Centiamperes).Amperes, CentiamperesTolerance);
150160
AssertEx.EqualTolerance(1, ElectricCurrent.FromKiloamperes(ampere.Kiloamperes).Amperes, KiloamperesTolerance);
151161
AssertEx.EqualTolerance(1, ElectricCurrent.FromMegaamperes(ampere.Megaamperes).Amperes, MegaamperesTolerance);
152162
AssertEx.EqualTolerance(1, ElectricCurrent.FromMicroamperes(ampere.Microamperes).Amperes, MicroamperesTolerance);

UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentExtensions.g.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,40 @@ public static class NumberToElectricCurrentExtensions
7878

7979
#endregion
8080

81+
#region Centiampere
82+
83+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
84+
public static ElectricCurrent Centiamperes(this int value) => ElectricCurrent.FromCentiamperes(value);
85+
86+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
87+
public static ElectricCurrent? Centiamperes(this int? value) => ElectricCurrent.FromCentiamperes(value);
88+
89+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
90+
public static ElectricCurrent Centiamperes(this long value) => ElectricCurrent.FromCentiamperes(value);
91+
92+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
93+
public static ElectricCurrent? Centiamperes(this long? value) => ElectricCurrent.FromCentiamperes(value);
94+
95+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
96+
public static ElectricCurrent Centiamperes(this double value) => ElectricCurrent.FromCentiamperes(value);
97+
98+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
99+
public static ElectricCurrent? Centiamperes(this double? value) => ElectricCurrent.FromCentiamperes(value);
100+
101+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
102+
public static ElectricCurrent Centiamperes(this float value) => ElectricCurrent.FromCentiamperes(value);
103+
104+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
105+
public static ElectricCurrent? Centiamperes(this float? value) => ElectricCurrent.FromCentiamperes(value);
106+
107+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
108+
public static ElectricCurrent Centiamperes(this decimal value) => ElectricCurrent.FromCentiamperes(Convert.ToDouble(value));
109+
110+
/// <inheritdoc cref="ElectricCurrent.FromCentiamperes(UnitsNet.QuantityValue)" />
111+
public static ElectricCurrent? Centiamperes(this decimal? value) => ElectricCurrent.FromCentiamperes(value == null ? (double?)null : Convert.ToDouble(value.Value));
112+
113+
#endregion
114+
81115
#region Kiloampere
82116

83117
/// <inheritdoc cref="ElectricCurrent.FromKiloamperes(UnitsNet.QuantityValue)" />

UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ public partial struct ElectricCurrent : IComparable, IComparable<ElectricCurrent
7070
return amperes.HasValue ? FromAmperes(amperes.Value) : default(ElectricCurrent?);
7171
}
7272

73+
/// <summary>
74+
/// Get nullable ElectricCurrent from nullable Centiamperes.
75+
/// </summary>
76+
public static ElectricCurrent? FromCentiamperes(QuantityValue? centiamperes)
77+
{
78+
return centiamperes.HasValue ? FromCentiamperes(centiamperes.Value) : default(ElectricCurrent?);
79+
}
80+
7381
/// <summary>
7482
/// Get nullable ElectricCurrent from nullable Kiloamperes.
7583
/// </summary>

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
10161016
{
10171017
new AbbreviationsForCulture("en-US", "A"),
10181018
}),
1019+
new CulturesForEnumValue((int) ElectricCurrentUnit.Centiampere,
1020+
new[]
1021+
{
1022+
new AbbreviationsForCulture("en-US", "cA"),
1023+
}),
10191024
new CulturesForEnumValue((int) ElectricCurrentUnit.Kiloampere,
10201025
new[]
10211026
{

UnitsNet/GeneratedCode/Units/ElectricCurrentUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum ElectricCurrentUnit
4343
{
4444
Undefined = 0,
4545
Ampere,
46+
Centiampere,
4647
Kiloampere,
4748
Megaampere,
4849
Microampere,

0 commit comments

Comments
 (0)