Skip to content

Commit e34aaeb

Browse files
author
Erik Ovegard
committed
Added BrakeSpecificFuelConsumption
1 parent 1c81869 commit e34aaeb

13 files changed

+932
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
23+
using NUnit.Framework;
24+
using System;
25+
26+
namespace UnitsNet.Tests.CustomCode
27+
{
28+
public class BrakeSpecificFuelConsumptionTests : BrakeSpecificFuelConsumptionTestsBase
29+
{
30+
protected override double GramsPerKiloWattHourInOneKilogramPerJoule => 3600000000;
31+
32+
protected override double KilogramsPerJouleInOneKilogramPerJoule => 1.0;
33+
34+
protected override double PoundsPerHorsepowerHourInOneKilogramPerJoule => 5918352.5016;
35+
36+
[Test]
37+
public void PowerTimesBrakeSpecificFuelConsumptionEqualsMassFlow()
38+
{
39+
MassFlow massFlow = BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(180.0) * Power.FromKilowatts(20.0 / 24.0 * 1e6 / 180.0);
40+
Assert.AreEqual(20.0, massFlow.TonnesPerDay, 1e-11);
41+
}
42+
43+
[Test]
44+
public void DoubleDividedByBrakeSpecificFuelConsumptionEqualsSpecificEnergy()
45+
{
46+
SpecificEnergy massFlow = 2.0 / BrakeSpecificFuelConsumption.FromKilogramsPerJoule(4.0);
47+
Assert.AreEqual(SpecificEnergy.FromJoulesPerKilogram(0.5), massFlow);
48+
}
49+
}
50+
}

UnitsNet.Tests/CustomCode/MassFlowTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,19 @@ public void TimeSpanTimesMassFlowEqualsMass()
7373
Mass mass = TimeSpan.FromSeconds(4.0)*MassFlow.FromKilogramsPerSecond(20.0);
7474
Assert.AreEqual(mass, Mass.FromKilograms(80.0));
7575
}
76+
77+
[Test]
78+
public void MassFlowDividedByBrakeSpecificFuelConsumptionEqualsPower()
79+
{
80+
Power power = MassFlow.FromTonnesPerDay(20) / BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(180.0);
81+
Assert.AreEqual(power, Power.FromKilowatts(20.0 / 24.0 * 1e6 / 180.0));
82+
}
83+
84+
[Test]
85+
public void MassFlowDividedByPowerEqualsBrakeSpecificFuelConsumption()
86+
{
87+
BrakeSpecificFuelConsumption bsfc = MassFlow.FromTonnesPerDay(20) / Power.FromKilowatts(20.0 / 24.0 * 1e6 / 180.0);
88+
Assert.AreEqual(bsfc.GramsPerKiloWattHour, 180.0, 1e-11);
89+
}
7690
}
7791
}

UnitsNet.Tests/CustomCode/PowerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,12 @@ public void TimeSpanTimesPowerEqualsEnergy()
106106
Energy energy = TimeSpan.FromSeconds(8.0)*Power.FromWatts(5.0);
107107
Assert.AreEqual(energy, Energy.FromJoules(40.0));
108108
}
109+
110+
[Test]
111+
public void PowerTimesBrakeSpecificFuelConsumptionEqualsMassFlow()
112+
{
113+
MassFlow massFlow = Power.FromKilowatts(20.0 / 24.0 * 1e6 / 180.0) * BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(180.0);
114+
Assert.AreEqual(massFlow.TonnesPerDay, 20.0, 1e-11);
115+
}
109116
}
110117
}

UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@ public void SpecificEnergyTimesMassEqualsEnergy()
5555
Energy energy = SpecificEnergy.FromJoulesPerKilogram(10.0)*Mass.FromKilograms(20.0);
5656
Assert.AreEqual(energy, Energy.FromJoules(200.0));
5757
}
58+
59+
[Test]
60+
public void DoubleDividedBySpecificEnergyEqualsBrakeSpecificFuelConsumption()
61+
{
62+
BrakeSpecificFuelConsumption bsfc = 2.0 / SpecificEnergy.FromJoulesPerKilogram(4.0);
63+
Assert.AreEqual(BrakeSpecificFuelConsumption.FromKilogramsPerJoule(0.5), bsfc);
64+
}
5865
}
5966
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
using System;
23+
using NUnit.Framework;
24+
using UnitsNet.Units;
25+
26+
// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
27+
#pragma warning disable 1718
28+
29+
// ReSharper disable once CheckNamespace
30+
namespace UnitsNet.Tests
31+
{
32+
/// <summary>
33+
/// Test of BrakeSpecificFuelConsumption.
34+
/// </summary>
35+
[TestFixture]
36+
// ReSharper disable once PartialTypeWithSinglePart
37+
public abstract partial class BrakeSpecificFuelConsumptionTestsBase
38+
{
39+
protected abstract double GramsPerKiloWattHourInOneKilogramPerJoule { get; }
40+
protected abstract double KilogramsPerJouleInOneKilogramPerJoule { get; }
41+
protected abstract double PoundsPerHorsepowerHourInOneKilogramPerJoule { get; }
42+
43+
// ReSharper disable VirtualMemberNeverOverriden.Global
44+
protected virtual double GramsPerKiloWattHourTolerance { get { return 1e-5; } }
45+
protected virtual double KilogramsPerJouleTolerance { get { return 1e-5; } }
46+
protected virtual double PoundsPerHorsepowerHourTolerance { get { return 1e-5; } }
47+
// ReSharper restore VirtualMemberNeverOverriden.Global
48+
49+
[Test]
50+
public void KilogramPerJouleToBrakeSpecificFuelConsumptionUnits()
51+
{
52+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
53+
Assert.AreEqual(GramsPerKiloWattHourInOneKilogramPerJoule, kilogramperjoule.GramsPerKiloWattHour, GramsPerKiloWattHourTolerance);
54+
Assert.AreEqual(KilogramsPerJouleInOneKilogramPerJoule, kilogramperjoule.KilogramsPerJoule, KilogramsPerJouleTolerance);
55+
Assert.AreEqual(PoundsPerHorsepowerHourInOneKilogramPerJoule, kilogramperjoule.PoundsPerHorsepowerHour, PoundsPerHorsepowerHourTolerance);
56+
}
57+
58+
[Test]
59+
public void FromValueAndUnit()
60+
{
61+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour).GramsPerKiloWattHour, GramsPerKiloWattHourTolerance);
62+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule).KilogramsPerJoule, KilogramsPerJouleTolerance);
63+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.PoundPerHorsepowerHour).PoundsPerHorsepowerHour, PoundsPerHorsepowerHourTolerance);
64+
}
65+
66+
[Test]
67+
public void As()
68+
{
69+
var kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
70+
Assert.AreEqual(GramsPerKiloWattHourInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour), GramsPerKiloWattHourTolerance);
71+
Assert.AreEqual(KilogramsPerJouleInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule), KilogramsPerJouleTolerance);
72+
Assert.AreEqual(PoundsPerHorsepowerHourInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.PoundPerHorsepowerHour), PoundsPerHorsepowerHourTolerance);
73+
}
74+
75+
[Test]
76+
public void ConversionRoundTrip()
77+
{
78+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
79+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(kilogramperjoule.GramsPerKiloWattHour).KilogramsPerJoule, GramsPerKiloWattHourTolerance);
80+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.FromKilogramsPerJoule(kilogramperjoule.KilogramsPerJoule).KilogramsPerJoule, KilogramsPerJouleTolerance);
81+
Assert.AreEqual(1, BrakeSpecificFuelConsumption.FromPoundsPerHorsepowerHour(kilogramperjoule.PoundsPerHorsepowerHour).KilogramsPerJoule, PoundsPerHorsepowerHourTolerance);
82+
}
83+
84+
[Test]
85+
public void ArithmeticOperators()
86+
{
87+
BrakeSpecificFuelConsumption v = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
88+
Assert.AreEqual(-1, -v.KilogramsPerJoule, KilogramsPerJouleTolerance);
89+
Assert.AreEqual(2, (BrakeSpecificFuelConsumption.FromKilogramsPerJoule(3)-v).KilogramsPerJoule, KilogramsPerJouleTolerance);
90+
Assert.AreEqual(2, (v + v).KilogramsPerJoule, KilogramsPerJouleTolerance);
91+
Assert.AreEqual(10, (v*10).KilogramsPerJoule, KilogramsPerJouleTolerance);
92+
Assert.AreEqual(10, (10*v).KilogramsPerJoule, KilogramsPerJouleTolerance);
93+
Assert.AreEqual(2, (BrakeSpecificFuelConsumption.FromKilogramsPerJoule(10)/5).KilogramsPerJoule, KilogramsPerJouleTolerance);
94+
Assert.AreEqual(2, BrakeSpecificFuelConsumption.FromKilogramsPerJoule(10)/BrakeSpecificFuelConsumption.FromKilogramsPerJoule(5), KilogramsPerJouleTolerance);
95+
}
96+
97+
[Test]
98+
public void ComparisonOperators()
99+
{
100+
BrakeSpecificFuelConsumption oneKilogramPerJoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
101+
BrakeSpecificFuelConsumption twoKilogramsPerJoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(2);
102+
103+
Assert.True(oneKilogramPerJoule < twoKilogramsPerJoule);
104+
Assert.True(oneKilogramPerJoule <= twoKilogramsPerJoule);
105+
Assert.True(twoKilogramsPerJoule > oneKilogramPerJoule);
106+
Assert.True(twoKilogramsPerJoule >= oneKilogramPerJoule);
107+
108+
Assert.False(oneKilogramPerJoule > twoKilogramsPerJoule);
109+
Assert.False(oneKilogramPerJoule >= twoKilogramsPerJoule);
110+
Assert.False(twoKilogramsPerJoule < oneKilogramPerJoule);
111+
Assert.False(twoKilogramsPerJoule <= oneKilogramPerJoule);
112+
}
113+
114+
[Test]
115+
public void CompareToIsImplemented()
116+
{
117+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
118+
Assert.AreEqual(0, kilogramperjoule.CompareTo(kilogramperjoule));
119+
Assert.Greater(kilogramperjoule.CompareTo(BrakeSpecificFuelConsumption.Zero), 0);
120+
Assert.Less(BrakeSpecificFuelConsumption.Zero.CompareTo(kilogramperjoule), 0);
121+
}
122+
123+
[Test]
124+
[ExpectedException(typeof(ArgumentException))]
125+
public void CompareToThrowsOnTypeMismatch()
126+
{
127+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
128+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
129+
kilogramperjoule.CompareTo(new object());
130+
}
131+
132+
[Test]
133+
[ExpectedException(typeof(ArgumentNullException))]
134+
public void CompareToThrowsOnNull()
135+
{
136+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
137+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
138+
kilogramperjoule.CompareTo(null);
139+
}
140+
141+
142+
[Test]
143+
public void EqualityOperators()
144+
{
145+
BrakeSpecificFuelConsumption a = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
146+
BrakeSpecificFuelConsumption b = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(2);
147+
148+
// ReSharper disable EqualExpressionComparison
149+
Assert.True(a == a);
150+
Assert.True(a != b);
151+
152+
Assert.False(a == b);
153+
Assert.False(a != a);
154+
// ReSharper restore EqualExpressionComparison
155+
}
156+
157+
[Test]
158+
public void EqualsIsImplemented()
159+
{
160+
BrakeSpecificFuelConsumption v = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
161+
Assert.IsTrue(v.Equals(BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1)));
162+
Assert.IsFalse(v.Equals(BrakeSpecificFuelConsumption.Zero));
163+
}
164+
165+
[Test]
166+
public void EqualsReturnsFalseOnTypeMismatch()
167+
{
168+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
169+
Assert.IsFalse(kilogramperjoule.Equals(new object()));
170+
}
171+
172+
[Test]
173+
public void EqualsReturnsFalseOnNull()
174+
{
175+
BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1);
176+
Assert.IsFalse(kilogramperjoule.Equals(null));
177+
}
178+
}
179+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright(c) 2007 Andreas Gullberg Larsen
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
namespace UnitsNet
23+
{
24+
public partial struct BrakeSpecificFuelConsumption
25+
{
26+
public static MassFlow operator *(BrakeSpecificFuelConsumption bsfc, Power power)
27+
{
28+
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule * power.Watts);
29+
}
30+
31+
public static SpecificEnergy operator /(double value, BrakeSpecificFuelConsumption bsfc)
32+
{
33+
return SpecificEnergy.FromJoulesPerKilogram(value / bsfc.KilogramsPerJoule);
34+
}
35+
}
36+
}

UnitsNet/CustomCode/UnitClasses/MassFlow.extra.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,15 @@ public partial struct MassFlow
4444
{
4545
return Mass.FromKilograms(massFlow.KilogramsPerSecond*duration.Seconds);
4646
}
47+
48+
public static Power operator /(MassFlow massFlow, BrakeSpecificFuelConsumption bsfc)
49+
{
50+
return Power.FromWatts(massFlow.KilogramsPerSecond / bsfc.KilogramsPerJoule);
51+
}
52+
53+
public static BrakeSpecificFuelConsumption operator /(MassFlow massFlow, Power power)
54+
{
55+
return BrakeSpecificFuelConsumption.FromKilogramsPerJoule(massFlow.KilogramsPerSecond / power.Watts);
56+
}
4757
}
4858
}

UnitsNet/CustomCode/UnitClasses/Power.extra.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,10 @@ public partial struct Power
6464
{
6565
return RotationalSpeed.FromRadiansPerSecond(power.Watts/torque.NewtonMeters);
6666
}
67+
68+
public static MassFlow operator *(Power power, BrakeSpecificFuelConsumption bsfc)
69+
{
70+
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule * power.Watts);
71+
}
6772
}
6873
}

UnitsNet/CustomCode/UnitClasses/SpecificEnergy.extra.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public partial struct SpecificEnergy
3232
{
3333
return Energy.FromJoules(specificEnergy.JoulesPerKilogram*mass.Kilograms);
3434
}
35+
36+
public static BrakeSpecificFuelConsumption operator /(double value, SpecificEnergy bsfc)
37+
{
38+
return BrakeSpecificFuelConsumption.FromKilogramsPerJoule(value / bsfc.JoulesPerKilogram);
39+
}
3540
}
3641
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
// ReSharper disable once CheckNamespace
23+
namespace UnitsNet.Units
24+
{
25+
public enum BrakeSpecificFuelConsumptionUnit
26+
{
27+
Undefined = 0,
28+
GramPerKiloWattHour,
29+
KilogramPerJoule,
30+
PoundPerHorsepowerHour,
31+
}
32+
}

0 commit comments

Comments
 (0)