Skip to content

Commit 6faecdc

Browse files
authored
Merge pull request #408 from baxcoders/MassFlow
Added TonnePerHour (t/h) for MassFlow
2 parents ba307b5 + cc52519 commit 6faecdc

File tree

7 files changed

+108
-1
lines changed

7 files changed

+108
-1
lines changed

UnitsNet.Tests/CustomCode/MassFlowTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class MassFlowTests : MassFlowTestsBase
3434

3535
protected override double KilogramsPerHourInOneGramPerSecond => 3.6;
3636

37+
protected override double TonnesPerHourInOneGramPerSecond => 3.6E-3;
38+
3739
protected override double KilogramsPerSecondInOneGramPerSecond => 1E-3;
3840

3941
protected override double MegapoundsPerHourInOneGramPerSecond => 7.93664e-6;
@@ -117,4 +119,4 @@ public void MassFlowDividedByMassFluxEqualsArea()
117119
Assert.Equal(10, area.SquareMeters);
118120
}
119121
}
120-
}
122+
}

UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract partial class MassFlowTestsBase
6666
protected abstract double PoundsPerHourInOneGramPerSecond { get; }
6767
protected abstract double ShortTonsPerHourInOneGramPerSecond { get; }
6868
protected abstract double TonnesPerDayInOneGramPerSecond { get; }
69+
protected abstract double TonnesPerHourInOneGramPerSecond { get; }
6970

7071
// ReSharper disable VirtualMemberNeverOverriden.Global
7172
protected virtual double CentigramsPerSecondTolerance { get { return 1e-5; } }
@@ -82,6 +83,7 @@ public abstract partial class MassFlowTestsBase
8283
protected virtual double PoundsPerHourTolerance { get { return 1e-5; } }
8384
protected virtual double ShortTonsPerHourTolerance { get { return 1e-5; } }
8485
protected virtual double TonnesPerDayTolerance { get { return 1e-5; } }
86+
protected virtual double TonnesPerHourTolerance { get { return 1e-5; } }
8587
// ReSharper restore VirtualMemberNeverOverriden.Global
8688

8789
[Fact]
@@ -102,6 +104,7 @@ public void GramPerSecondToMassFlowUnits()
102104
AssertEx.EqualTolerance(PoundsPerHourInOneGramPerSecond, grampersecond.PoundsPerHour, PoundsPerHourTolerance);
103105
AssertEx.EqualTolerance(ShortTonsPerHourInOneGramPerSecond, grampersecond.ShortTonsPerHour, ShortTonsPerHourTolerance);
104106
AssertEx.EqualTolerance(TonnesPerDayInOneGramPerSecond, grampersecond.TonnesPerDay, TonnesPerDayTolerance);
107+
AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, grampersecond.TonnesPerHour, TonnesPerHourTolerance);
105108
}
106109

107110
[Fact]
@@ -121,6 +124,7 @@ public void FromValueAndUnit()
121124
AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.PoundPerHour).PoundsPerHour, PoundsPerHourTolerance);
122125
AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.ShortTonPerHour).ShortTonsPerHour, ShortTonsPerHourTolerance);
123126
AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.TonnePerDay).TonnesPerDay, TonnesPerDayTolerance);
127+
AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.TonnePerHour).TonnesPerHour, TonnesPerHourTolerance);
124128
}
125129

126130
[Fact]
@@ -141,6 +145,7 @@ public void As()
141145
AssertEx.EqualTolerance(PoundsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.PoundPerHour), PoundsPerHourTolerance);
142146
AssertEx.EqualTolerance(ShortTonsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.ShortTonPerHour), ShortTonsPerHourTolerance);
143147
AssertEx.EqualTolerance(TonnesPerDayInOneGramPerSecond, grampersecond.As(MassFlowUnit.TonnePerDay), TonnesPerDayTolerance);
148+
AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.TonnePerHour), TonnesPerHourTolerance);
144149
}
145150

146151
[Fact]
@@ -161,6 +166,7 @@ public void ConversionRoundTrip()
161166
AssertEx.EqualTolerance(1, MassFlow.FromPoundsPerHour(grampersecond.PoundsPerHour).GramsPerSecond, PoundsPerHourTolerance);
162167
AssertEx.EqualTolerance(1, MassFlow.FromShortTonsPerHour(grampersecond.ShortTonsPerHour).GramsPerSecond, ShortTonsPerHourTolerance);
163168
AssertEx.EqualTolerance(1, MassFlow.FromTonnesPerDay(grampersecond.TonnesPerDay).GramsPerSecond, TonnesPerDayTolerance);
169+
AssertEx.EqualTolerance(1, MassFlow.FromTonnesPerHour(grampersecond.TonnesPerHour).GramsPerSecond, TonnesPerHourTolerance);
164170
}
165171

166172
[Fact]

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,40 @@ public static class NumberToMassFlowExtensions
520520

521521
#endregion
522522

523+
#region TonnePerHour
524+
525+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double)"/>
526+
public static MassFlow TonnesPerHour(this int value) => MassFlow.FromTonnesPerHour(value);
527+
528+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double?)"/>
529+
public static MassFlow? TonnesPerHour(this int? value) => MassFlow.FromTonnesPerHour(value);
530+
531+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double)"/>
532+
public static MassFlow TonnesPerHour(this long value) => MassFlow.FromTonnesPerHour(value);
533+
534+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double?)"/>
535+
public static MassFlow? TonnesPerHour(this long? value) => MassFlow.FromTonnesPerHour(value);
536+
537+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double)"/>
538+
public static MassFlow TonnesPerHour(this double value) => MassFlow.FromTonnesPerHour(value);
539+
540+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double?)"/>
541+
public static MassFlow? TonnesPerHour(this double? value) => MassFlow.FromTonnesPerHour(value);
542+
543+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double)"/>
544+
public static MassFlow TonnesPerHour(this float value) => MassFlow.FromTonnesPerHour(value);
545+
546+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double?)"/>
547+
public static MassFlow? TonnesPerHour(this float? value) => MassFlow.FromTonnesPerHour(value);
548+
549+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double)"/>
550+
public static MassFlow TonnesPerHour(this decimal value) => MassFlow.FromTonnesPerHour(Convert.ToDouble(value));
551+
552+
/// <inheritdoc cref="MassFlow.FromTonnesPerHour(double?)"/>
553+
public static MassFlow? TonnesPerHour(this decimal? value) => MassFlow.FromTonnesPerHour(value == null ? (double?)null : Convert.ToDouble(value.Value));
554+
555+
#endregion
556+
523557
}
524558
}
525559
#endif

UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ public double TonnesPerDay
241241
get { return _gramsPerSecond*0.0864000; }
242242
}
243243

244+
/// <summary>
245+
/// Get MassFlow in TonnesPerHour.
246+
/// </summary>
247+
public double TonnesPerHour
248+
{
249+
get { return _gramsPerSecond*3.6/1000; }
250+
}
251+
244252
#endregion
245253

246254
#region Static
@@ -502,6 +510,24 @@ public static MassFlow FromTonnesPerDay(QuantityValue tonnesperday)
502510
}
503511
#endif
504512

513+
/// <summary>
514+
/// Get MassFlow from TonnesPerHour.
515+
/// </summary>
516+
#if WINDOWS_UWP
517+
[Windows.Foundation.Metadata.DefaultOverload]
518+
public static MassFlow FromTonnesPerHour(double tonnesperhour)
519+
{
520+
double value = (double) tonnesperhour;
521+
return new MassFlow(1000*value/3.6);
522+
}
523+
#else
524+
public static MassFlow FromTonnesPerHour(QuantityValue tonnesperhour)
525+
{
526+
double value = (double) tonnesperhour;
527+
return new MassFlow((1000*value/3.6));
528+
}
529+
#endif
530+
505531
// Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
506532
#if !WINDOWS_UWP
507533
/// <summary>
@@ -714,6 +740,21 @@ public static MassFlow FromTonnesPerDay(QuantityValue tonnesperday)
714740
}
715741
}
716742

743+
/// <summary>
744+
/// Get nullable MassFlow from nullable TonnesPerHour.
745+
/// </summary>
746+
public static MassFlow? FromTonnesPerHour(QuantityValue? tonnesperhour)
747+
{
748+
if (tonnesperhour.HasValue)
749+
{
750+
return FromTonnesPerHour(tonnesperhour.Value);
751+
}
752+
else
753+
{
754+
return null;
755+
}
756+
}
757+
717758
#endif
718759

719760
/// <summary>
@@ -760,6 +801,8 @@ public static MassFlow From(QuantityValue value, MassFlowUnit fromUnit)
760801
return FromShortTonsPerHour(value);
761802
case MassFlowUnit.TonnePerDay:
762803
return FromTonnesPerDay(value);
804+
case MassFlowUnit.TonnePerHour:
805+
return FromTonnesPerHour(value);
763806

764807
default:
765808
throw new NotImplementedException("fromUnit: " + fromUnit);
@@ -810,6 +853,8 @@ public static MassFlow From(QuantityValue value, MassFlowUnit fromUnit)
810853
return FromShortTonsPerHour(value.Value);
811854
case MassFlowUnit.TonnePerDay:
812855
return FromTonnesPerDay(value.Value);
856+
case MassFlowUnit.TonnePerHour:
857+
return FromTonnesPerHour(value.Value);
813858

814859
default:
815860
throw new NotImplementedException("fromUnit: " + fromUnit);
@@ -1011,6 +1056,8 @@ public double As(MassFlowUnit unit)
10111056
return ShortTonsPerHour;
10121057
case MassFlowUnit.TonnePerDay:
10131058
return TonnesPerDay;
1059+
case MassFlowUnit.TonnePerHour:
1060+
return TonnesPerHour;
10141061

10151062
default:
10161063
throw new NotImplementedException("unit: " + unit);

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
23552355
{
23562356
new AbbreviationsForCulture("en-US", "t/d"),
23572357
}),
2358+
new CulturesForEnumValue((int) MassFlowUnit.TonnePerHour,
2359+
new[]
2360+
{
2361+
new AbbreviationsForCulture("en-US", "t/h"),
2362+
}),
23582363
}),
23592364
new UnitLocalization(typeof (MassFluxUnit),
23602365
new[]

UnitsNet/GeneratedCode/Units/MassFlowUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ public enum MassFlowUnit
5656
PoundPerHour,
5757
ShortTonPerHour,
5858
TonnePerDay,
59+
TonnePerHour,
5960
}
6061
}

UnitsNet/UnitDefinitions/MassFlow.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
}
3333
]
3434
},
35+
{
36+
"SingularName": "TonnePerHour",
37+
"PluralName": "TonnesPerHour",
38+
"FromUnitToBaseFunc": "1000*x/3.6",
39+
"FromBaseToUnitFunc": "x*3.6/1000",
40+
"Localization": [
41+
{
42+
"Culture": "en-US",
43+
"Abbreviations": [ "t/h" ]
44+
}
45+
]
46+
},
3547
{
3648
"SingularName": "PoundPerHour",
3749
"PluralName": "PoundsPerHour",

0 commit comments

Comments
 (0)