Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the Dimensions and BaseUnit for the FuelEfficiency #1489

Merged
merged 6 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 67 additions & 38 deletions Common/UnitDefinitions/FuelEfficiency.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,84 @@
{
"Name": "FuelEfficiency",
"BaseUnit": "LiterPer100Kilometers",
"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).",
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Fuel_efficiency",
"Units": [{
"SingularName": "LiterPer100Kilometers",
"PluralName": "LitersPer100Kilometers",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Localization": [{
"Name": "FuelEfficiency",
"BaseUnit": "KilometerPerLiter",
"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).",
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Fuel_efficiency",
"BaseDimensions": {
"L": -2
},
"Units": [
{
"SingularName": "LiterPer100Kilometers",
"PluralName": "LitersPer100Kilometers",
"FromUnitToBaseFunc": "100 / {x}",
"FromBaseToUnitFunc": "100 / {x}",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [
"l/100km"
]
}]
},
{
"SingularName": "MilePerUsGallon",
"PluralName": "MilesPerUsGallon",
"FromUnitToBaseFunc": "(100 * 3.785411784) / (1.609344 * {x})",
"FromBaseToUnitFunc": "(100 * 3.785411784) / (1.609344 * {x})",
"Localization": [{
}
]
},
{
"SingularName": "MilePerUsGallon",
"PluralName": "MilesPerUsGallon",
"FromUnitToBaseFunc": "{x} * 1.609344 / 3.785411784",
"FromBaseToUnitFunc": "{x} * 3.785411784 / 1.609344",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [
"mpg (U.S.)"
]
}]
},
{
"SingularName": "MilePerUkGallon",
"PluralName": "MilesPerUkGallon",
"FromUnitToBaseFunc": "(100 * 4.54609188) / (1.609344 * {x})",
"FromBaseToUnitFunc": "(100 * 4.54609188) / (1.609344 * {x})",
"Localization": [{
}
]
},
{
"SingularName": "MilePerUkGallon",
"PluralName": "MilesPerUkGallon",
"FromUnitToBaseFunc": "{x} * 1.609344 / 4.54609",
"FromBaseToUnitFunc": "{x} * 4.54609 / 1.609344",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [
"mpg (imp.)"
]
}]
},
{
"SingularName": "KilometerPerLiter",
"PluralName": "KilometersPerLiter",
"FromUnitToBaseFunc": "100 / {x}",
"FromBaseToUnitFunc": "100 / {x}",
"Localization": [{
}
]
},
{
"SingularName": "KilometerPerLiter",
"PluralName": "KilometersPerLiter",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [
"km/l"
]
}]
}
]
}
}
]
},
{
"SingularName": "MeterPerCubicMeter",
"PluralName": "MetersPerCubicMeter",
"BaseUnits": {
"L": "Meter"
},
"FromUnitToBaseFunc": "{x} / 1e6",
"FromBaseToUnitFunc": "{x} * 1e6",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [
"m/m³"
]
}
]
}
]
}
3 changes: 2 additions & 1 deletion Common/UnitEnumValues.g.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@
"KilometerPerLiter": 1,
"LiterPer100Kilometers": 2,
"MilePerUkGallon": 3,
"MilePerUsGallon": 4
"MilePerUsGallon": 4,
"MeterPerCubicMeter": 7
},
"HeatFlux": {
"BtuPerHourSquareFoot": 1,
Expand Down
32 changes: 22 additions & 10 deletions UnitsNet.NanoFramework/GeneratedCode/Quantities/FuelEfficiency.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using System;
using UnitsNet.Units;
using Xunit;

namespace UnitsNet.Tests.CustomCode
{
public class FuelEfficiencyTests : FuelEfficiencyTestsBase
{
protected override bool SupportsSIUnitSystem => false;
protected override double KilometersPerLiterInOneLiterPer100Kilometers => 100;
protected override double LitersPer100KilometersInOneLiterPer100Kilometers => 1;
protected override double MilesPerUkGallonInOneLiterPer100Kilometers => 282.4809363;
protected override double MilesPerUsGallonInOneLiterPer100Kilometers => 235.2145833;

[Theory(Skip = "Conversion from 0 km/L results in infinity")]
[MemberData(nameof(UnitTypes))]
public override void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(FuelEfficiencyUnit unit)
protected override double MetersPerCubicMeterInOneKilometerPerLiter => 1e6;
protected override double KilometersPerLiterInOneKilometerPerLiter => 1;
protected override double LitersPer100KilometersInOneKilometerPerLiter => 100;
protected override double MilesPerUkGallonInOneKilometerPerLiter => 2.824809363318222;
protected override double MilesPerUsGallonInOneKilometerPerLiter => 2.352145833333333;

[Fact(Skip = "See about changing this to MetersPerCubicMeter")]
public override void BaseUnit_HasSIBase()
{
base.ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(unit);
base.BaseUnit_HasSIBase();
}
}
}
Loading