Skip to content

Commit b7da253

Browse files
committed
Changed to add values for Imperial gallon and US gallon.
1 parent 5412d21 commit b7da253

File tree

7 files changed

+155
-49
lines changed

7 files changed

+155
-49
lines changed

UnitsNet.Tests/CustomCode/DensityTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public class DensityTests : DensityTestsBase
4949

5050
protected override double PoundsPerCubicInchInOneKilogramPerCubicMeter => 3.61272923e-5;
5151

52-
protected override double PoundsPerGallonInOneKilogramPerCubicMeter => 8.3454045e-3;
52+
protected override double PoundsPerUSGallonInOneKilogramPerCubicMeter => 8.3454045e-3;
53+
protected override double PoundsPerImperialGallonInOneKilogramPerCubicMeter => 1.002241e-2;
5354

5455
protected override double TonnesPerCubicCentimeterInOneKilogramPerCubicMeter => 1e-9;
5556

UnitsNet.Tests/GeneratedCode/DensityTestsBase.g.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public abstract partial class DensityTestsBase
8484
protected abstract double PicogramsPerMilliliterInOneKilogramPerCubicMeter { get; }
8585
protected abstract double PoundsPerCubicFootInOneKilogramPerCubicMeter { get; }
8686
protected abstract double PoundsPerCubicInchInOneKilogramPerCubicMeter { get; }
87-
protected abstract double PoundsPerGallonInOneKilogramPerCubicMeter { get; }
87+
protected abstract double PoundsPerImperialGallonInOneKilogramPerCubicMeter { get; }
88+
protected abstract double PoundsPerUSGallonInOneKilogramPerCubicMeter { get; }
8889
protected abstract double SlugsPerCubicFootInOneKilogramPerCubicMeter { get; }
8990
protected abstract double TonnesPerCubicCentimeterInOneKilogramPerCubicMeter { get; }
9091
protected abstract double TonnesPerCubicMeterInOneKilogramPerCubicMeter { get; }
@@ -123,7 +124,8 @@ public abstract partial class DensityTestsBase
123124
protected virtual double PicogramsPerMilliliterTolerance { get { return 1e-5; } }
124125
protected virtual double PoundsPerCubicFootTolerance { get { return 1e-5; } }
125126
protected virtual double PoundsPerCubicInchTolerance { get { return 1e-5; } }
126-
protected virtual double PoundsPerGallonTolerance { get { return 1e-5; } }
127+
protected virtual double PoundsPerImperialGallonTolerance { get { return 1e-5; } }
128+
protected virtual double PoundsPerUSGallonTolerance { get { return 1e-5; } }
127129
protected virtual double SlugsPerCubicFootTolerance { get { return 1e-5; } }
128130
protected virtual double TonnesPerCubicCentimeterTolerance { get { return 1e-5; } }
129131
protected virtual double TonnesPerCubicMeterTolerance { get { return 1e-5; } }
@@ -166,7 +168,8 @@ public void KilogramPerCubicMeterToDensityUnits()
166168
AssertEx.EqualTolerance(PicogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance);
167169
AssertEx.EqualTolerance(PoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerCubicFoot, PoundsPerCubicFootTolerance);
168170
AssertEx.EqualTolerance(PoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerCubicInch, PoundsPerCubicInchTolerance);
169-
AssertEx.EqualTolerance(PoundsPerGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerGallon, PoundsPerGallonTolerance);
171+
AssertEx.EqualTolerance(PoundsPerImperialGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance);
172+
AssertEx.EqualTolerance(PoundsPerUSGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerUSGallon, PoundsPerUSGallonTolerance);
170173
AssertEx.EqualTolerance(SlugsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.SlugsPerCubicFoot, SlugsPerCubicFootTolerance);
171174
AssertEx.EqualTolerance(TonnesPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance);
172175
AssertEx.EqualTolerance(TonnesPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance);
@@ -208,7 +211,8 @@ public void FromValueAndUnit()
208211
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PicogramPerMilliliter).PicogramsPerMilliliter, PicogramsPerMilliliterTolerance);
209212
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerCubicFoot).PoundsPerCubicFoot, PoundsPerCubicFootTolerance);
210213
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerCubicInch).PoundsPerCubicInch, PoundsPerCubicInchTolerance);
211-
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerGallon).PoundsPerGallon, PoundsPerGallonTolerance);
214+
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerImperialGallon).PoundsPerImperialGallon, PoundsPerImperialGallonTolerance);
215+
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerUSGallon).PoundsPerUSGallon, PoundsPerUSGallonTolerance);
212216
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.SlugPerCubicFoot).SlugsPerCubicFoot, SlugsPerCubicFootTolerance);
213217
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.TonnePerCubicCentimeter).TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance);
214218
AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.TonnePerCubicMeter).TonnesPerCubicMeter, TonnesPerCubicMeterTolerance);
@@ -251,7 +255,8 @@ public void As()
251255
AssertEx.EqualTolerance(PicogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PicogramPerMilliliter), PicogramsPerMilliliterTolerance);
252256
AssertEx.EqualTolerance(PoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerCubicFoot), PoundsPerCubicFootTolerance);
253257
AssertEx.EqualTolerance(PoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerCubicInch), PoundsPerCubicInchTolerance);
254-
AssertEx.EqualTolerance(PoundsPerGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerGallon), PoundsPerGallonTolerance);
258+
AssertEx.EqualTolerance(PoundsPerImperialGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerImperialGallon), PoundsPerImperialGallonTolerance);
259+
AssertEx.EqualTolerance(PoundsPerUSGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerUSGallon), PoundsPerUSGallonTolerance);
255260
AssertEx.EqualTolerance(SlugsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.SlugPerCubicFoot), SlugsPerCubicFootTolerance);
256261
AssertEx.EqualTolerance(TonnesPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicCentimeter), TonnesPerCubicCentimeterTolerance);
257262
AssertEx.EqualTolerance(TonnesPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicMeter), TonnesPerCubicMeterTolerance);
@@ -294,7 +299,8 @@ public void ConversionRoundTrip()
294299
AssertEx.EqualTolerance(1, Density.FromPicogramsPerMilliliter(kilogrampercubicmeter.PicogramsPerMilliliter).KilogramsPerCubicMeter, PicogramsPerMilliliterTolerance);
295300
AssertEx.EqualTolerance(1, Density.FromPoundsPerCubicFoot(kilogrampercubicmeter.PoundsPerCubicFoot).KilogramsPerCubicMeter, PoundsPerCubicFootTolerance);
296301
AssertEx.EqualTolerance(1, Density.FromPoundsPerCubicInch(kilogrampercubicmeter.PoundsPerCubicInch).KilogramsPerCubicMeter, PoundsPerCubicInchTolerance);
297-
AssertEx.EqualTolerance(1, Density.FromPoundsPerGallon(kilogrampercubicmeter.PoundsPerGallon).KilogramsPerCubicMeter, PoundsPerGallonTolerance);
302+
AssertEx.EqualTolerance(1, Density.FromPoundsPerImperialGallon(kilogrampercubicmeter.PoundsPerImperialGallon).KilogramsPerCubicMeter, PoundsPerImperialGallonTolerance);
303+
AssertEx.EqualTolerance(1, Density.FromPoundsPerUSGallon(kilogrampercubicmeter.PoundsPerUSGallon).KilogramsPerCubicMeter, PoundsPerUSGallonTolerance);
298304
AssertEx.EqualTolerance(1, Density.FromSlugsPerCubicFoot(kilogrampercubicmeter.SlugsPerCubicFoot).KilogramsPerCubicMeter, SlugsPerCubicFootTolerance);
299305
AssertEx.EqualTolerance(1, Density.FromTonnesPerCubicCentimeter(kilogrampercubicmeter.TonnesPerCubicCentimeter).KilogramsPerCubicMeter, TonnesPerCubicCentimeterTolerance);
300306
AssertEx.EqualTolerance(1, Density.FromTonnesPerCubicMeter(kilogrampercubicmeter.TonnesPerCubicMeter).KilogramsPerCubicMeter, TonnesPerCubicMeterTolerance);

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

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,37 +1132,71 @@ public static class NumberToDensityExtensions
11321132

11331133
#endregion
11341134

1135-
#region PoundPerGallon
1135+
#region PoundPerImperialGallon
11361136

1137-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double)"/>
1138-
public static Density PoundsPerGallon(this int value) => Density.FromPoundsPerGallon(value);
1137+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double)"/>
1138+
public static Density PoundsPerImperialGallon(this int value) => Density.FromPoundsPerImperialGallon(value);
11391139

1140-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double?)"/>
1141-
public static Density? PoundsPerGallon(this int? value) => Density.FromPoundsPerGallon(value);
1140+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double?)"/>
1141+
public static Density? PoundsPerImperialGallon(this int? value) => Density.FromPoundsPerImperialGallon(value);
11421142

1143-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double)"/>
1144-
public static Density PoundsPerGallon(this long value) => Density.FromPoundsPerGallon(value);
1143+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double)"/>
1144+
public static Density PoundsPerImperialGallon(this long value) => Density.FromPoundsPerImperialGallon(value);
11451145

1146-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double?)"/>
1147-
public static Density? PoundsPerGallon(this long? value) => Density.FromPoundsPerGallon(value);
1146+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double?)"/>
1147+
public static Density? PoundsPerImperialGallon(this long? value) => Density.FromPoundsPerImperialGallon(value);
11481148

1149-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double)"/>
1150-
public static Density PoundsPerGallon(this double value) => Density.FromPoundsPerGallon(value);
1149+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double)"/>
1150+
public static Density PoundsPerImperialGallon(this double value) => Density.FromPoundsPerImperialGallon(value);
11511151

1152-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double?)"/>
1153-
public static Density? PoundsPerGallon(this double? value) => Density.FromPoundsPerGallon(value);
1152+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double?)"/>
1153+
public static Density? PoundsPerImperialGallon(this double? value) => Density.FromPoundsPerImperialGallon(value);
11541154

1155-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double)"/>
1156-
public static Density PoundsPerGallon(this float value) => Density.FromPoundsPerGallon(value);
1155+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double)"/>
1156+
public static Density PoundsPerImperialGallon(this float value) => Density.FromPoundsPerImperialGallon(value);
11571157

1158-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double?)"/>
1159-
public static Density? PoundsPerGallon(this float? value) => Density.FromPoundsPerGallon(value);
1158+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double?)"/>
1159+
public static Density? PoundsPerImperialGallon(this float? value) => Density.FromPoundsPerImperialGallon(value);
11601160

1161-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double)"/>
1162-
public static Density PoundsPerGallon(this decimal value) => Density.FromPoundsPerGallon(Convert.ToDouble(value));
1161+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double)"/>
1162+
public static Density PoundsPerImperialGallon(this decimal value) => Density.FromPoundsPerImperialGallon(Convert.ToDouble(value));
11631163

1164-
/// <inheritdoc cref="Density.FromPoundsPerGallon(double?)"/>
1165-
public static Density? PoundsPerGallon(this decimal? value) => Density.FromPoundsPerGallon(value == null ? (double?)null : Convert.ToDouble(value.Value));
1164+
/// <inheritdoc cref="Density.FromPoundsPerImperialGallon(double?)"/>
1165+
public static Density? PoundsPerImperialGallon(this decimal? value) => Density.FromPoundsPerImperialGallon(value == null ? (double?)null : Convert.ToDouble(value.Value));
1166+
1167+
#endregion
1168+
1169+
#region PoundPerUSGallon
1170+
1171+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double)"/>
1172+
public static Density PoundsPerUSGallon(this int value) => Density.FromPoundsPerUSGallon(value);
1173+
1174+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double?)"/>
1175+
public static Density? PoundsPerUSGallon(this int? value) => Density.FromPoundsPerUSGallon(value);
1176+
1177+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double)"/>
1178+
public static Density PoundsPerUSGallon(this long value) => Density.FromPoundsPerUSGallon(value);
1179+
1180+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double?)"/>
1181+
public static Density? PoundsPerUSGallon(this long? value) => Density.FromPoundsPerUSGallon(value);
1182+
1183+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double)"/>
1184+
public static Density PoundsPerUSGallon(this double value) => Density.FromPoundsPerUSGallon(value);
1185+
1186+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double?)"/>
1187+
public static Density? PoundsPerUSGallon(this double? value) => Density.FromPoundsPerUSGallon(value);
1188+
1189+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double)"/>
1190+
public static Density PoundsPerUSGallon(this float value) => Density.FromPoundsPerUSGallon(value);
1191+
1192+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double?)"/>
1193+
public static Density? PoundsPerUSGallon(this float? value) => Density.FromPoundsPerUSGallon(value);
1194+
1195+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double)"/>
1196+
public static Density PoundsPerUSGallon(this decimal value) => Density.FromPoundsPerUSGallon(Convert.ToDouble(value));
1197+
1198+
/// <inheritdoc cref="Density.FromPoundsPerUSGallon(double?)"/>
1199+
public static Density? PoundsPerUSGallon(this decimal? value) => Density.FromPoundsPerUSGallon(value == null ? (double?)null : Convert.ToDouble(value.Value));
11661200

11671201
#endregion
11681202

UnitsNet/GeneratedCode/Quantities/Density.g.cs

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,17 @@ public double PoundsPerCubicInch
386386
}
387387

388388
/// <summary>
389-
/// Get Density in PoundsPerGallon.
389+
/// Get Density in PoundsPerImperialGallon.
390390
/// </summary>
391-
public double PoundsPerGallon
391+
public double PoundsPerImperialGallon
392+
{
393+
get { return _kilogramsPerCubicMeter/9.9776398e1; }
394+
}
395+
396+
/// <summary>
397+
/// Get Density in PoundsPerUSGallon.
398+
/// </summary>
399+
public double PoundsPerUSGallon
392400
{
393401
get { return _kilogramsPerCubicMeter/1.19826427e2; }
394402
}
@@ -1011,19 +1019,37 @@ public static Density FromPoundsPerCubicInch(QuantityValue poundspercubicinch)
10111019
#endif
10121020

10131021
/// <summary>
1014-
/// Get Density from PoundsPerGallon.
1022+
/// Get Density from PoundsPerImperialGallon.
10151023
/// </summary>
10161024
#if WINDOWS_UWP
10171025
[Windows.Foundation.Metadata.DefaultOverload]
1018-
public static Density FromPoundsPerGallon(double poundspergallon)
1026+
public static Density FromPoundsPerImperialGallon(double poundsperimperialgallon)
1027+
{
1028+
double value = (double) poundsperimperialgallon;
1029+
return new Density(value*9.9776398e1);
1030+
}
1031+
#else
1032+
public static Density FromPoundsPerImperialGallon(QuantityValue poundsperimperialgallon)
10191033
{
1020-
double value = (double) poundspergallon;
1034+
double value = (double) poundsperimperialgallon;
1035+
return new Density((value*9.9776398e1));
1036+
}
1037+
#endif
1038+
1039+
/// <summary>
1040+
/// Get Density from PoundsPerUSGallon.
1041+
/// </summary>
1042+
#if WINDOWS_UWP
1043+
[Windows.Foundation.Metadata.DefaultOverload]
1044+
public static Density FromPoundsPerUSGallon(double poundsperusgallon)
1045+
{
1046+
double value = (double) poundsperusgallon;
10211047
return new Density(value*1.19826427e2);
10221048
}
10231049
#else
1024-
public static Density FromPoundsPerGallon(QuantityValue poundspergallon)
1050+
public static Density FromPoundsPerUSGallon(QuantityValue poundsperusgallon)
10251051
{
1026-
double value = (double) poundspergallon;
1052+
double value = (double) poundsperusgallon;
10271053
return new Density((value*1.19826427e2));
10281054
}
10291055
#endif
@@ -1583,13 +1609,28 @@ public static Density FromTonnesPerCubicMillimeter(QuantityValue tonnespercubicm
15831609
}
15841610

15851611
/// <summary>
1586-
/// Get nullable Density from nullable PoundsPerGallon.
1612+
/// Get nullable Density from nullable PoundsPerImperialGallon.
1613+
/// </summary>
1614+
public static Density? FromPoundsPerImperialGallon(QuantityValue? poundsperimperialgallon)
1615+
{
1616+
if (poundsperimperialgallon.HasValue)
1617+
{
1618+
return FromPoundsPerImperialGallon(poundsperimperialgallon.Value);
1619+
}
1620+
else
1621+
{
1622+
return null;
1623+
}
1624+
}
1625+
1626+
/// <summary>
1627+
/// Get nullable Density from nullable PoundsPerUSGallon.
15871628
/// </summary>
1588-
public static Density? FromPoundsPerGallon(QuantityValue? poundspergallon)
1629+
public static Density? FromPoundsPerUSGallon(QuantityValue? poundsperusgallon)
15891630
{
1590-
if (poundspergallon.HasValue)
1631+
if (poundsperusgallon.HasValue)
15911632
{
1592-
return FromPoundsPerGallon(poundspergallon.Value);
1633+
return FromPoundsPerUSGallon(poundsperusgallon.Value);
15931634
}
15941635
else
15951636
{
@@ -1739,8 +1780,10 @@ public static Density From(QuantityValue value, DensityUnit fromUnit)
17391780
return FromPoundsPerCubicFoot(value);
17401781
case DensityUnit.PoundPerCubicInch:
17411782
return FromPoundsPerCubicInch(value);
1742-
case DensityUnit.PoundPerGallon:
1743-
return FromPoundsPerGallon(value);
1783+
case DensityUnit.PoundPerImperialGallon:
1784+
return FromPoundsPerImperialGallon(value);
1785+
case DensityUnit.PoundPerUSGallon:
1786+
return FromPoundsPerUSGallon(value);
17441787
case DensityUnit.SlugPerCubicFoot:
17451788
return FromSlugsPerCubicFoot(value);
17461789
case DensityUnit.TonnePerCubicCentimeter:
@@ -1835,8 +1878,10 @@ public static Density From(QuantityValue value, DensityUnit fromUnit)
18351878
return FromPoundsPerCubicFoot(value.Value);
18361879
case DensityUnit.PoundPerCubicInch:
18371880
return FromPoundsPerCubicInch(value.Value);
1838-
case DensityUnit.PoundPerGallon:
1839-
return FromPoundsPerGallon(value.Value);
1881+
case DensityUnit.PoundPerImperialGallon:
1882+
return FromPoundsPerImperialGallon(value.Value);
1883+
case DensityUnit.PoundPerUSGallon:
1884+
return FromPoundsPerUSGallon(value.Value);
18401885
case DensityUnit.SlugPerCubicFoot:
18411886
return FromSlugsPerCubicFoot(value.Value);
18421887
case DensityUnit.TonnePerCubicCentimeter:
@@ -2082,8 +2127,10 @@ public double As(DensityUnit unit)
20822127
return PoundsPerCubicFoot;
20832128
case DensityUnit.PoundPerCubicInch:
20842129
return PoundsPerCubicInch;
2085-
case DensityUnit.PoundPerGallon:
2086-
return PoundsPerGallon;
2130+
case DensityUnit.PoundPerImperialGallon:
2131+
return PoundsPerImperialGallon;
2132+
case DensityUnit.PoundPerUSGallon:
2133+
return PoundsPerUSGallon;
20872134
case DensityUnit.SlugPerCubicFoot:
20882135
return SlugsPerCubicFoot;
20892136
case DensityUnit.TonnePerCubicCentimeter:

0 commit comments

Comments
 (0)