Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/v6' into relations
Browse files Browse the repository at this point in the history
  • Loading branch information
angularsen committed Feb 4, 2024
2 parents f4231c1 + fb828d1 commit 70a4eb7
Show file tree
Hide file tree
Showing 277 changed files with 3,595 additions and 2,378 deletions.
10 changes: 2 additions & 8 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ private void GenerateInstanceConstructors()
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
public {_quantity.Name}({_quantity.ValueType} value, {_unitEnumName} unit)
{{");
Writer.WL(_quantity.ValueType == "double"
? @"
_value = Guard.EnsureValidNumber(value, nameof(value));"
: @"
Writer.WL(@"
_value = value;");
Writer.WL($@"
_unit = unit;
Expand All @@ -236,10 +233,7 @@ private void GenerateInstanceConstructors()
var firstUnitInfo = unitInfos.FirstOrDefault();
");

Writer.WL(_quantity.ValueType == "double"
? @"
_value = Guard.EnsureValidNumber(value, nameof(value));"
: @"
Writer.WL(@"
_value = value;");
Writer.WL($@"
_unit = firstUnitInfo?.Value ?? throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
Expand Down
30 changes: 20 additions & 10 deletions CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,21 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
");
if (_quantity.ValueType == "double") Writer.WL($@"
[Fact]
public void Ctor_WithInfinityValue_ThrowsArgumentException()
public void Ctor_WithInfinityValue_DoNotThrowsArgumentException()
{{
Assert.Throws<ArgumentException>(() => new {_quantity.Name}(double.PositiveInfinity, {_baseUnitFullName}));
Assert.Throws<ArgumentException>(() => new {_quantity.Name}(double.NegativeInfinity, {_baseUnitFullName}));
var exception1 = Record.Exception(() => new {_quantity.Name}(double.PositiveInfinity, {_baseUnitFullName}));
var exception2 = Record.Exception(() => new {_quantity.Name}(double.NegativeInfinity, {_baseUnitFullName}));
Assert.Null(exception1);
Assert.Null(exception2);
}}
[Fact]
public void Ctor_WithNaNValue_ThrowsArgumentException()
public void Ctor_WithNaNValue_DoNotThrowsArgumentException()
{{
Assert.Throws<ArgumentException>(() => new {_quantity.Name}(double.NaN, {_baseUnitFullName}));
var exception = Record.Exception(() => new {_quantity.Name}(double.NaN, {_baseUnitFullName}));
Assert.Null(exception);
}}
"); Writer.WL($@"
Expand Down Expand Up @@ -248,16 +253,21 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
");
if (_quantity.ValueType == "double") Writer.WL($@"
[Fact]
public void From{_baseUnit.PluralName}_WithInfinityValue_ThrowsArgumentException()
public void From{_baseUnit.PluralName}_WithInfinityValue_DoNotThrowsArgumentException()
{{
Assert.Throws<ArgumentException>(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.PositiveInfinity));
Assert.Throws<ArgumentException>(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.NegativeInfinity));
var exception1 = Record.Exception(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.PositiveInfinity));
var exception2 = Record.Exception(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.NegativeInfinity));
Assert.Null(exception1);
Assert.Null(exception2);
}}
[Fact]
public void From{_baseUnit.PluralName}_WithNanValue_ThrowsArgumentException()
public void From{_baseUnit.PluralName}_WithNanValue_DoNotThrowsArgumentException()
{{
Assert.Throws<ArgumentException>(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.NaN));
var exception = Record.Exception(() => {_quantity.Name}.From{_baseUnit.PluralName}(double.NaN));
Assert.Null(exception);
}}
"); Writer.WL($@"
Expand Down
2 changes: 1 addition & 1 deletion Common/UnitDefinitions/Density.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
},
{
"SingularName": "GramPerDeciliter",
"PluralName": "GramsPerDeciLiter",
"PluralName": "GramsPerDeciliter",
"FromUnitToBaseFunc": "{x} / 1e-1",
"FromBaseToUnitFunc": "{x} * 1e-1",
"Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ],
Expand Down
8 changes: 4 additions & 4 deletions Common/UnitDefinitions/ElectricPotentialChangeRate.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Units": [
{
"SingularName": "VoltPerSecond",
"PluralName": "VoltsPerSeconds",
"PluralName": "VoltsPerSecond",
"BaseUnits": {
"L": "Meter",
"M": "Kilogram",
Expand All @@ -30,7 +30,7 @@
},
{
"SingularName": "VoltPerMicrosecond",
"PluralName": "VoltsPerMicroseconds",
"PluralName": "VoltsPerMicrosecond",
"BaseUnits": {
"L": "Meter",
"M": "Kilogram",
Expand All @@ -49,7 +49,7 @@
},
{
"SingularName": "VoltPerMinute",
"PluralName": "VoltsPerMinutes",
"PluralName": "VoltsPerMinute",
"BaseUnits": {
"L": "Meter",
"M": "Kilogram",
Expand All @@ -68,7 +68,7 @@
},
{
"SingularName": "VoltPerHour",
"PluralName": "VoltsPerHours",
"PluralName": "VoltsPerHour",
"BaseUnits": {
"L": "Meter",
"M": "Kilogram",
Expand Down
2 changes: 1 addition & 1 deletion Common/UnitDefinitions/FuelEfficiency.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
"SingularName": "KilometerPerLiter",
"PluralName": "KilometersPerLiters",
"PluralName": "KilometersPerLiter",
"FromUnitToBaseFunc": "100 / {x}",
"FromBaseToUnitFunc": "100 / {x}",
"Localization": [{
Expand Down
2 changes: 1 addition & 1 deletion Common/UnitDefinitions/Speed.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"SingularName": "MeterPerMinute",
"PluralName": "MetersPerMinutes",
"PluralName": "MetersPerMinute",
"BaseUnits": {
"L": "Meter",
"T": "Minute"
Expand Down
4 changes: 2 additions & 2 deletions Common/UnitDefinitions/TemperatureGradient.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
{
"SingularName": "DegreeCelsiusPerMeter",
"PluralName": "DegreesCelciusPerMeter",
"PluralName": "DegreesCelsiusPerMeter",
"BaseUnits": {
"L": "Meter",
"Θ": "DegreeCelsius"
Expand Down Expand Up @@ -57,7 +57,7 @@
},
{
"SingularName": "DegreeCelsiusPerKilometer",
"PluralName": "DegreesCelciusPerKilometer",
"PluralName": "DegreesCelsiusPerKilometer",
"BaseUnits": {
"L": "Kilometer",
"Θ": "DegreeCelsius"
Expand Down
32 changes: 16 additions & 16 deletions UnitsNet.NanoFramework/GeneratedCode/Quantities/Density.g.cs

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

Loading

0 comments on commit 70a4eb7

Please sign in to comment.