Skip to content

Commit 7556b7c

Browse files
authored
Ensure that all base quantity units are BaseUnits (#1488)
Ensure that all base quantity units are `BaseUnits`: - introduced a test for each of the base quantities (`Length`, `Mass` etc.) that ensures that all of their units have valid `BaseUnits` definition - fixed some incorrect `BaseUnits` definitions: `Acceleration.StandardGravity` and `Temperature.MillidegreeCelsius` - added missing `BaseUnits` definitions: `Length`, `Temperature` and `TemperatureChangeRate` (removing 3 out of its 4 `[Skip]`-ed tests)
1 parent 4431e85 commit 7556b7c

16 files changed

+122
-55
lines changed

Common/UnitDefinitions/Acceleration.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@
131131
{
132132
"SingularName": "StandardGravity",
133133
"PluralName": "StandardGravity",
134-
"BaseUnits": {
135-
"L": "Meter",
136-
"T": "Second"
137-
},
138134
"FromUnitToBaseFunc": "{x} * 9.80665",
139135
"FromBaseToUnitFunc": "{x} / 9.80665",
140136
"Prefixes": [ "Milli"],

Common/UnitDefinitions/Length.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@
337337
{
338338
"SingularName": "AstronomicalUnit",
339339
"PluralName": "AstronomicalUnits",
340+
"BaseUnits": {
341+
"L": "AstronomicalUnit"
342+
},
340343
"FromUnitToBaseFunc": "{x} * 1.4959787070e11",
341344
"FromBaseToUnitFunc": "{x} / 1.4959787070e11",
342345
"XmlDocSummary": "One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth.",
@@ -351,6 +354,9 @@
351354
{
352355
"SingularName": "Parsec",
353356
"PluralName": "Parsecs",
357+
"BaseUnits": {
358+
"L": "Parsec"
359+
},
354360
"FromUnitToBaseFunc": "{x} * 3.08567758128e16",
355361
"FromBaseToUnitFunc": "{x} / 3.08567758128e16",
356362
"XmlDocSummary": "A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond.",
@@ -366,6 +372,9 @@
366372
{
367373
"SingularName": "LightYear",
368374
"PluralName": "LightYears",
375+
"BaseUnits": {
376+
"L": "LightYear"
377+
},
369378
"FromUnitToBaseFunc": "{x} * 9.46073047258e15",
370379
"FromBaseToUnitFunc": "{x} / 9.46073047258e15",
371380
"XmlDocSummary": "A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days.",
@@ -381,6 +390,9 @@
381390
{
382391
"SingularName": "SolarRadius",
383392
"PluralName": "SolarRadiuses",
393+
"BaseUnits": {
394+
"L": "SolarRadius"
395+
},
384396
"FromUnitToBaseFunc": "{x} * 6.95700e8",
385397
"FromBaseToUnitFunc": "{x} / 6.95700e8",
386398
"XmlDocSummary": "Solar radius is a ratio unit to the radius of the solar system star, the sun.",
@@ -427,6 +439,9 @@
427439
{
428440
"SingularName": "DataMile",
429441
"PluralName": "DataMiles",
442+
"BaseUnits": {
443+
"L": "DataMile"
444+
},
430445
"FromUnitToBaseFunc": "{x} * 1828.8",
431446
"FromBaseToUnitFunc": "{x} / 1828.8",
432447
"XmlDocSummary": "In radar-related subjects and in JTIDS, a data mile is a unit of distance equal to 6000 feet (1.8288 kilometres or 0.987 nautical miles).",

Common/UnitDefinitions/Temperature.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"SingularName": "MillidegreeCelsius",
4242
"PluralName": "MillidegreesCelsius",
4343
"BaseUnits": {
44-
"Θ": "DegreeCelsius"
44+
"Θ": "MillidegreeCelsius"
4545
},
4646
"FromUnitToBaseFunc": "{x} / 1000 + 273.15",
4747
"FromBaseToUnitFunc": "({x} - 273.15) * 1000",
@@ -145,6 +145,9 @@
145145
{
146146
"SingularName": "SolarTemperature",
147147
"PluralName": "SolarTemperatures",
148+
"BaseUnits": {
149+
"Θ": "SolarTemperature"
150+
},
148151
"FromUnitToBaseFunc": "{x} * 5778",
149152
"FromBaseToUnitFunc": "{x} / 5778",
150153
"Localization": [

Common/UnitDefinitions/TemperatureChangeRate.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
{
4444
"SingularName": "DegreeKelvinPerMinute",
4545
"PluralName": "DegreesKelvinPerMinute",
46+
"BaseUnits": {
47+
"Θ": "Kelvin",
48+
"T": "Minute"
49+
},
4650
"FromUnitToBaseFunc": "{x} / 60",
4751
"FromBaseToUnitFunc": "{x} * 60",
4852
"Prefixes": [],
@@ -56,6 +60,10 @@
5660
{
5761
"SingularName": "DegreeFahrenheitPerMinute",
5862
"PluralName": "DegreesFahrenheitPerMinute",
63+
"BaseUnits": {
64+
"Θ": "DegreeFahrenheit",
65+
"T": "Minute"
66+
},
5967
"FromUnitToBaseFunc": "{x} * 5 / 9 / 60",
6068
"FromBaseToUnitFunc": "{x} * 9 / 5 * 60",
6169
"Localization": [
@@ -68,6 +76,10 @@
6876
{
6977
"SingularName": "DegreeFahrenheitPerSecond",
7078
"PluralName": "DegreesFahrenheitPerSecond",
79+
"BaseUnits": {
80+
"Θ": "DegreeFahrenheit",
81+
"T": "Second"
82+
},
7183
"FromUnitToBaseFunc": "{x} * 5 / 9",
7284
"FromBaseToUnitFunc": "{x} * 9 / 5",
7385
"Localization": [
@@ -80,6 +92,10 @@
8092
{
8193
"SingularName": "DegreeKelvinPerSecond",
8294
"PluralName": "DegreesKelvinPerSecond",
95+
"BaseUnits": {
96+
"Θ": "Kelvin",
97+
"T": "Second"
98+
},
8399
"FromUnitToBaseFunc": "{x}",
84100
"FromBaseToUnitFunc": "{x}",
85101
"Prefixes": [],
@@ -93,6 +109,10 @@
93109
{
94110
"SingularName": "DegreeCelsiusPerHour",
95111
"PluralName": "DegreesCelsiusPerHour",
112+
"BaseUnits": {
113+
"Θ": "DegreeCelsius",
114+
"T": "Hour"
115+
},
96116
"FromUnitToBaseFunc": "{x} / 3600",
97117
"FromBaseToUnitFunc": "{x} * 3600",
98118
"Localization": [
@@ -105,6 +125,10 @@
105125
{
106126
"SingularName": "DegreeKelvinPerHour",
107127
"PluralName": "DegreesKelvinPerHour",
128+
"BaseUnits": {
129+
"Θ": "Kelvin",
130+
"T": "Hour"
131+
},
108132
"FromUnitToBaseFunc": "{x} / 3600",
109133
"FromBaseToUnitFunc": "{x} * 3600",
110134
"Prefixes": [],
@@ -118,6 +142,10 @@
118142
{
119143
"SingularName": "DegreeFahrenheitPerHour",
120144
"PluralName": "DegreesFahrenheitPerHour",
145+
"BaseUnits": {
146+
"Θ": "DegreeFahrenheit",
147+
"T": "Hour"
148+
},
121149
"FromUnitToBaseFunc": "{x} * 5 / 9 / 3600",
122150
"FromBaseToUnitFunc": "{x} * 9 / 5 * 3600",
123151
"Localization": [

UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase
4747
protected override double MegamolesInOneMole => 1e-6;
4848
protected override double PicomolesInOneMole => 1e12;
4949
protected override double FemtomolesInOneMole => 1e15;
50+
51+
[Fact]
52+
public void AllBaseQuantityUnitsAreBaseUnits()
53+
{
54+
Assert.All(AmountOfSubstance.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(amount: unitInfo.Value), unitInfo.BaseUnits));
55+
}
5056

5157
[Fact]
5258
public void NumberOfParticlesInOneMoleEqualsAvogadroConstant()

UnitsNet.Tests/CustomCode/DurationTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class DurationTests : DurationTestsBase
3434
protected override double JulianYearsInOneSecond => 3.16880878140289e-08;
3535

3636
protected override double SolsInOneSecond => 1.126440159375963e-5;
37+
38+
[Fact]
39+
public void AllBaseQuantityUnitsAreBaseUnits()
40+
{
41+
Assert.All(Duration.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(time: unitInfo.Value), unitInfo.BaseUnits));
42+
}
3743

3844
[Fact]
3945
public static void ToTimeSpanShouldThrowExceptionOnValuesLargerThanTimeSpanMax()

UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class ElectricCurrentTests : ElectricCurrentTestsBase
2828
protected override double KiloamperesInOneAmpere => 1e-3;
2929

3030
protected override double MegaamperesInOneAmpere => 1e-6;
31+
32+
[Fact]
33+
public void AllBaseQuantityUnitsAreBaseUnits()
34+
{
35+
Assert.All(ElectricCurrent.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(current: unitInfo.Value), unitInfo.BaseUnits));
36+
}
3137

3238
[Theory]
3339
[InlineData(1, 1, 1)]

UnitsNet.Tests/CustomCode/LengthTests.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,44 @@ public class LengthTests : LengthTestsBase
8888

8989
protected override double KilofeetInOneMeter => 3.28083989501e-3;
9090

91-
[ Fact]
91+
[Fact]
92+
public void AllBaseQuantityUnitsAreBaseUnits()
93+
{
94+
Assert.All(Length.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(unitInfo.Value), unitInfo.BaseUnits));
95+
}
96+
97+
[Fact]
9298
public void AreaTimesLengthEqualsVolume()
9399
{
94-
Volume volume = Area.FromSquareMeters(10)*Length.FromMeters(3);
100+
Volume volume = Area.FromSquareMeters(10) * Length.FromMeters(3);
95101
Assert.Equal(volume, Volume.FromCubicMeters(30));
96102
}
97103

98104
[Fact]
99105
public void ForceTimesLengthEqualsTorque()
100106
{
101-
Torque torque = Force.FromNewtons(1)*Length.FromMeters(3);
107+
Torque torque = Force.FromNewtons(1) * Length.FromMeters(3);
102108
Assert.Equal(torque, Torque.FromNewtonMeters(3));
103109
}
104110

105111
[Fact]
106112
public void LengthTimesAreaEqualsVolume()
107113
{
108-
Volume volume = Length.FromMeters(3)*Area.FromSquareMeters(9);
114+
Volume volume = Length.FromMeters(3) * Area.FromSquareMeters(9);
109115
Assert.Equal(volume, Volume.FromCubicMeters(27));
110116
}
111117

112118
[Fact]
113119
public void LengthTimesForceEqualsTorque()
114120
{
115-
Torque torque = Length.FromMeters(3)*Force.FromNewtons(1);
121+
Torque torque = Length.FromMeters(3) * Force.FromNewtons(1);
116122
Assert.Equal(torque, Torque.FromNewtonMeters(3));
117123
}
118124

119125
[Fact]
120126
public void LengthTimesLengthEqualsArea()
121127
{
122-
Area area = Length.FromMeters(10)*Length.FromMeters(2);
128+
Area area = Length.FromMeters(10) * Length.FromMeters(2);
123129
Assert.Equal(area, Area.FromSquareMeters(20));
124130
}
125131

@@ -167,7 +173,7 @@ public void ToStringReturnsCorrectNumberAndUnitWithDefaultUnitWhichIsMeter()
167173
}
168174

169175
[Fact]
170-
public void ToStringReturnsCorrectNumberAndUnitWithCentimeterAsDefualtUnit()
176+
public void ToStringReturnsCorrectNumberAndUnitWithCentimeterAsDefaultUnit()
171177
{
172178
var value = Length.From(2, LengthUnit.Centimeter);
173179
string valueString = value.ToString(CultureInfo.InvariantCulture);

UnitsNet.Tests/CustomCode/LuminousIntensityTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@
2222

2323

2424
using System;
25+
using Xunit;
2526

2627
namespace UnitsNet.Tests.CustomCode
2728
{
2829
public class LuminousIntensityTests : LuminousIntensityTestsBase
2930
{
3031
protected override bool SupportsSIUnitSystem => true;
3132
protected override double CandelaInOneCandela => 1;
33+
34+
[Fact]
35+
public void AllBaseQuantityUnitsAreBaseUnits()
36+
{
37+
Assert.All(LuminousIntensity.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(luminousIntensity: unitInfo.Value), unitInfo.BaseUnits));
38+
}
3239
}
3340
}

UnitsNet.Tests/CustomCode/MassTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,37 @@ public class MassTests : MassTestsBase
6767

6868
protected override double PicogramsInOneKilogram => 1E15;
6969

70+
[Fact]
71+
public void AllBaseQuantityUnitsAreBaseUnits()
72+
{
73+
Assert.All(Mass.Info.UnitInfos, unitInfo => Assert.Equal(new BaseUnits(mass: unitInfo.Value), unitInfo.BaseUnits));
74+
}
75+
7076
[Fact]
7177
public void AccelerationTimesMassEqualsForce()
7278
{
73-
Force force = Acceleration.FromMetersPerSecondSquared(3)*Mass.FromKilograms(18);
79+
Force force = Acceleration.FromMetersPerSecondSquared(3) * Mass.FromKilograms(18);
7480
Assert.Equal(force, Force.FromNewtons(54));
7581
}
7682

7783
[Fact]
7884
public void MassDividedByDurationEqualsMassFlow()
7985
{
80-
MassFlow massFlow = Mass.FromKilograms(18.0)/Duration.FromSeconds(6);
86+
MassFlow massFlow = Mass.FromKilograms(18.0) / Duration.FromSeconds(6);
8187
Assert.Equal(massFlow, MassFlow.FromKilogramsPerSecond(3.0));
8288
}
8389

8490
[Fact]
8591
public void MassDividedByTimeSpanEqualsMassFlow()
8692
{
87-
MassFlow massFlow = Mass.FromKilograms(18.0)/TimeSpan.FromSeconds(6);
93+
MassFlow massFlow = Mass.FromKilograms(18.0) / TimeSpan.FromSeconds(6);
8894
Assert.Equal(massFlow, MassFlow.FromKilogramsPerSecond(3.0));
8995
}
9096

9197
[Fact]
9298
public void MassDividedByVolumeEqualsDensity()
9399
{
94-
Density density = Mass.FromKilograms(18)/Volume.FromCubicMeters(3);
100+
Density density = Mass.FromKilograms(18) / Volume.FromCubicMeters(3);
95101
Assert.Equal(density, Density.FromKilogramsPerCubicMeter(6));
96102
}
97103

@@ -112,7 +118,7 @@ public void MassDividedByAreaDensityEqualsArea()
112118
[Fact]
113119
public void MassTimesAccelerationEqualsForce()
114120
{
115-
Force force = Mass.FromKilograms(18)*Acceleration.FromMetersPerSecondSquared(3);
121+
Force force = Mass.FromKilograms(18) * Acceleration.FromMetersPerSecondSquared(3);
116122
Assert.Equal(force, Force.FromNewtons(54));
117123
}
118124

0 commit comments

Comments
 (0)