Skip to content

Commit fa38b43

Browse files
authoredJan 19, 2025··
Changing the Dimensions and BaseUnit for the FuelEfficiency (#1489)
Changing the `Dimensions` and `BaseUnit` for the `FuelEfficiency`: - `BaseUnit` changed from `LiterPer100Kilometers` (defaults to `+Infinity`) to `KilometersPerLiter` (defaults to `0`) - added `Dimensions` of `"L": -2` (was previously treated as a dimensionless quantity) - updated the relevant tests - skipped all SI-related tests
1 parent f7b4edb commit fa38b43

File tree

5 files changed

+306
-203
lines changed

5 files changed

+306
-203
lines changed
 
+50-38
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,67 @@
11
{
2-
"Name": "FuelEfficiency",
3-
"BaseUnit": "LiterPer100Kilometers",
4-
"XmlDocSummary": "Fuel efficiency is a form of thermal efficiency, meaning the ratio from effort to result of a process that converts chemical potential energy contained in a carrier (fuel) into kinetic energy or work. Fuel economy is stated as \"fuel consumption\" in liters per 100 kilometers (L/100 km). In countries using non-metric system, fuel economy is expressed in miles per gallon (mpg) (imperial galon or US galon).",
5-
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Fuel_efficiency",
6-
"Units": [{
7-
"SingularName": "LiterPer100Kilometers",
8-
"PluralName": "LitersPer100Kilometers",
9-
"FromUnitToBaseFunc": "{x}",
10-
"FromBaseToUnitFunc": "{x}",
11-
"Localization": [{
2+
"Name": "FuelEfficiency",
3+
"BaseUnit": "KilometerPerLiter",
4+
"XmlDocSummary": "In the context of transport, fuel economy is the energy efficiency of a particular vehicle, given as a ratio of distance traveled per unit of fuel consumed. In most countries, using the metric system, fuel economy is stated as \"fuel consumption\" in liters per 100 kilometers (L/100 km) or kilometers per liter (km/L or kmpl). In countries using non-metric system, fuel economy is expressed in miles per gallon (mpg) (imperial galon or US galon).",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Fuel_efficiency",
6+
"BaseDimensions": {
7+
"L": -2
8+
},
9+
"Units": [
10+
{
11+
"SingularName": "LiterPer100Kilometers",
12+
"PluralName": "LitersPer100Kilometers",
13+
"FromUnitToBaseFunc": "100 / {x}",
14+
"FromBaseToUnitFunc": "100 / {x}",
15+
"Localization": [
16+
{
1217
"Culture": "en-US",
1318
"Abbreviations": [
1419
"l/100km"
1520
]
16-
}]
17-
},
18-
{
19-
"SingularName": "MilePerUsGallon",
20-
"PluralName": "MilesPerUsGallon",
21-
"FromUnitToBaseFunc": "(100 * 3.785411784) / (1.609344 * {x})",
22-
"FromBaseToUnitFunc": "(100 * 3.785411784) / (1.609344 * {x})",
23-
"Localization": [{
21+
}
22+
]
23+
},
24+
{
25+
"SingularName": "MilePerUsGallon",
26+
"PluralName": "MilesPerUsGallon",
27+
"FromUnitToBaseFunc": "{x} * 1.609344 / 3.785411784",
28+
"FromBaseToUnitFunc": "{x} * 3.785411784 / 1.609344",
29+
"Localization": [
30+
{
2431
"Culture": "en-US",
2532
"Abbreviations": [
2633
"mpg (U.S.)"
2734
]
28-
}]
29-
},
30-
{
31-
"SingularName": "MilePerUkGallon",
32-
"PluralName": "MilesPerUkGallon",
33-
"FromUnitToBaseFunc": "(100 * 4.54609188) / (1.609344 * {x})",
34-
"FromBaseToUnitFunc": "(100 * 4.54609188) / (1.609344 * {x})",
35-
"Localization": [{
35+
}
36+
]
37+
},
38+
{
39+
"SingularName": "MilePerUkGallon",
40+
"PluralName": "MilesPerUkGallon",
41+
"FromUnitToBaseFunc": "{x} * 1.609344 / 4.54609",
42+
"FromBaseToUnitFunc": "{x} * 4.54609 / 1.609344",
43+
"Localization": [
44+
{
3645
"Culture": "en-US",
3746
"Abbreviations": [
3847
"mpg (imp.)"
3948
]
40-
}]
41-
},
42-
{
43-
"SingularName": "KilometerPerLiter",
44-
"PluralName": "KilometersPerLiter",
45-
"FromUnitToBaseFunc": "100 / {x}",
46-
"FromBaseToUnitFunc": "100 / {x}",
47-
"Localization": [{
49+
}
50+
]
51+
},
52+
{
53+
"SingularName": "KilometerPerLiter",
54+
"PluralName": "KilometersPerLiter",
55+
"FromUnitToBaseFunc": "{x}",
56+
"FromBaseToUnitFunc": "{x}",
57+
"Localization": [
58+
{
4859
"Culture": "en-US",
4960
"Abbreviations": [
5061
"km/l"
5162
]
52-
}]
53-
}
54-
]
55-
}
63+
}
64+
]
65+
}
66+
]
67+
}

‎UnitsNet.NanoFramework/GeneratedCode/Quantities/FuelEfficiency.g.cs

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs

+27-10
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,42 @@
1717
// Licensed under MIT No Attribution, see LICENSE file at the root.
1818
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.
1919

20-
using System;
21-
using UnitsNet.Units;
2220
using Xunit;
2321

2422
namespace UnitsNet.Tests.CustomCode
2523
{
2624
public class FuelEfficiencyTests : FuelEfficiencyTestsBase
2725
{
2826
protected override bool SupportsSIUnitSystem => false;
29-
protected override double KilometersPerLiterInOneLiterPer100Kilometers => 100;
30-
protected override double LitersPer100KilometersInOneLiterPer100Kilometers => 1;
31-
protected override double MilesPerUkGallonInOneLiterPer100Kilometers => 282.4809363;
32-
protected override double MilesPerUsGallonInOneLiterPer100Kilometers => 235.2145833;
3327

34-
[Theory(Skip = "Conversion from 0 km/L results in infinity")]
35-
[MemberData(nameof(UnitTypes))]
36-
public override void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(FuelEfficiencyUnit unit)
28+
protected override double KilometersPerLiterInOneKilometerPerLiter => 1;
29+
protected override double LitersPer100KilometersInOneKilometerPerLiter => 100;
30+
protected override double MilesPerUkGallonInOneKilometerPerLiter => 2.824809363318222;
31+
protected override double MilesPerUsGallonInOneKilometerPerLiter => 2.352145833333333;
32+
33+
34+
[Fact(Skip = "The SI unit would have to be MeterPerCubicMeter")]
35+
public override void BaseUnit_HasSIBase()
36+
{
37+
base.BaseUnit_HasSIBase();
38+
}
39+
40+
[Fact(Skip = "NoThe SI unit would have to be MeterPerCubicMeter")]
41+
public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits()
42+
{
43+
base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits();
44+
}
45+
46+
[Fact(Skip = "NoThe SI unit would have to be MeterPerCubicMeter")]
47+
public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits()
48+
{
49+
base.As_UnitSystem_SI_ReturnsQuantityInSIUnits();
50+
}
51+
52+
[Fact(Skip = "NoThe SI unit would have to be MeterPerCubicMeter")]
53+
public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
3754
{
38-
base.ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(unit);
55+
base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits();
3956
}
4057
}
4158
}

0 commit comments

Comments
 (0)
Please sign in to comment.