Skip to content

Commit d88e2e7

Browse files
committed
UnitSystem equality, BaseUnits for BaseUnitSystem + tests
- UnitSystem/BaseUnitSystem Equality contract based on the base (default) unit for each quantity - BaseUnits for BaseUnitSystem created from the provided unit associations - added unit system associations for all SI base types (Length, Mass, Duration etc.) - tests for the UnitSystem construction/derivation
1 parent d71900e commit d88e2e7

File tree

20 files changed

+1070
-104
lines changed

20 files changed

+1070
-104
lines changed

Common/UnitDefinitions/AmountOfSubstance.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"FromUnitToBaseFunc": "x*453.59237",
3333
"FromBaseToUnitFunc": "x/453.59237",
34-
"UnitSystems": [ "BI", "USC" ],
34+
"UnitSystems": [ "BI", "EE", "FPS", "USC" ],
3535
"Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Kilo" ],
3636
"Localization": [
3737
{
@@ -54,6 +54,14 @@
5454
"UnitSystem": "BI",
5555
"BaseUnit": "PoundMole"
5656
},
57+
{
58+
"UnitSystem": "EE",
59+
"BaseUnit": "PoundMole"
60+
},
61+
{
62+
"UnitSystem": "FPS",
63+
"BaseUnit": "PoundMole"
64+
},
5765
{
5866
"UnitSystem": "USC",
5967
"BaseUnit": "PoundMole"

Common/UnitDefinitions/Duration.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"FromUnitToBaseFunc": "x*365*24*3600",
1616
"FromBaseToUnitFunc": "x/(365*24*3600)",
17+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS" ],
1718
"Localization": [
1819
{
1920
"Culture": "en-US",
@@ -33,6 +34,7 @@
3334
},
3435
"FromUnitToBaseFunc": "x*30*24*3600",
3536
"FromBaseToUnitFunc": "x/(30*24*3600)",
37+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS" ],
3638
"Localization": [
3739
{
3840
"Culture": "en-US",
@@ -52,6 +54,7 @@
5254
},
5355
"FromUnitToBaseFunc": "x*7*24*3600",
5456
"FromBaseToUnitFunc": "x/(7*24*3600)",
57+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS" ],
5558
"Localization": [
5659
{
5760
"Culture": "en-US",
@@ -71,6 +74,7 @@
7174
},
7275
"FromUnitToBaseFunc": "x*24*3600",
7376
"FromBaseToUnitFunc": "x/(24*3600)",
77+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS" ],
7478
"Localization": [
7579
{
7680
"Culture": "en-US",
@@ -90,6 +94,7 @@
9094
},
9195
"FromUnitToBaseFunc": "x*3600",
9296
"FromBaseToUnitFunc": "x/3600",
97+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS", "Astronomical" ],
9398
"Localization": [
9499
{
95100
"Culture": "en-US",
@@ -109,6 +114,7 @@
109114
},
110115
"FromUnitToBaseFunc": "x*60",
111116
"FromBaseToUnitFunc": "x/60",
117+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS", "Astronomical" ],
112118
"Localization": [
113119
{
114120
"Culture": "en-US",
@@ -128,6 +134,7 @@
128134
},
129135
"FromUnitToBaseFunc": "x",
130136
"FromBaseToUnitFunc": "x",
137+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS", "Astronomical" ],
131138
"Prefixes": [ "Nano", "Micro", "Milli" ],
132139
"Localization": [
133140
{
@@ -140,5 +147,35 @@
140147
}
141148
]
142149
}
150+
],
151+
"UnitSystems": [
152+
{
153+
"UnitSystem": "SI",
154+
"BaseUnit": "Second"
155+
},
156+
{
157+
"UnitSystem": "CGS",
158+
"BaseUnit": "Second"
159+
},
160+
{
161+
"UnitSystem": "BI",
162+
"BaseUnit": "Second"
163+
},
164+
{
165+
"UnitSystem": "EE",
166+
"BaseUnit": "Second"
167+
},
168+
{
169+
"UnitSystem": "USC",
170+
"BaseUnit": "Second"
171+
},
172+
{
173+
"UnitSystem": "FPS",
174+
"BaseUnit": "Second"
175+
},
176+
{
177+
"UnitSystem": "Astronomical",
178+
"BaseUnit": "Second"
179+
}
143180
]
144181
}

Common/UnitDefinitions/ElectricCurrent.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"PluralName": "Amperes",
1212
"FromUnitToBaseFunc": "x",
1313
"FromBaseToUnitFunc": "x",
14+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS" ],
1415
"BaseUnits": {
1516
"I": "Ampere"
1617
},
@@ -22,5 +23,31 @@
2223
}
2324
]
2425
}
26+
],
27+
"UnitSystems": [
28+
{
29+
"UnitSystem": "SI",
30+
"BaseUnit": "Ampere"
31+
},
32+
{
33+
"UnitSystem": "CGS",
34+
"BaseUnit": "Ampere"
35+
},
36+
{
37+
"UnitSystem": "BI",
38+
"BaseUnit": "Ampere"
39+
},
40+
{
41+
"UnitSystem": "EE",
42+
"BaseUnit": "Ampere"
43+
},
44+
{
45+
"UnitSystem": "USC",
46+
"BaseUnit": "Ampere"
47+
},
48+
{
49+
"UnitSystem": "FPS",
50+
"BaseUnit": "Ampere"
51+
}
2552
]
2653
}

Common/UnitDefinitions/Length.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
"PluralName": "AstronomicalUnits",
307307
"FromUnitToBaseFunc": "x * 1.4959787070e11",
308308
"FromBaseToUnitFunc": "x / 1.4959787070e11",
309+
"UnitSystems": [ "Astronomical" ],
309310
"XmlDocSummary": "One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth.",
310311
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Astronomical_unit",
311312
"Localization": [
@@ -320,6 +321,7 @@
320321
"PluralName": "Parsecs",
321322
"FromUnitToBaseFunc": "x * 3.08567758128e16",
322323
"FromBaseToUnitFunc": "x / 3.08567758128e16",
324+
"UnitSystems": [ "Astronomical" ],
323325
"XmlDocSummary": "A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond.",
324326
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Parsec",
325327
"Prefixes": [ "Kilo", "Mega" ],
@@ -335,6 +337,7 @@
335337
"PluralName": "LightYears",
336338
"FromUnitToBaseFunc": "x * 9.46073047258e15",
337339
"FromBaseToUnitFunc": "x / 9.46073047258e15",
340+
"UnitSystems": [ "Astronomical" ],
338341
"XmlDocSummary": "A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days.",
339342
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Light-year",
340343
"Prefixes": [ "Kilo", "Mega" ],
@@ -350,6 +353,7 @@
350353
"PluralName": "SolarRadiuses",
351354
"FromUnitToBaseFunc": "x * 6.95510000E+08",
352355
"FromBaseToUnitFunc": "x / 6.95510000E+08",
356+
"UnitSystems": [ "Astronomical" ],
353357
"XmlDocSummary": "Solar radius is a ratio unit to the radius of the solar system star, the sun.",
354358
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Stellar_classification",
355359
"Localization": [
@@ -369,9 +373,21 @@
369373
"UnitSystem": "CGS",
370374
"BaseUnit": "Centimeter"
371375
},
376+
{
377+
"UnitSystem": "BI",
378+
"BaseUnit": "Yard"
379+
},
372380
{
373381
"UnitSystem": "EE",
374382
"BaseUnit": "Foot"
383+
},
384+
{
385+
"UnitSystem": "UCS",
386+
"BaseUnit": "Yard"
387+
},
388+
{
389+
"UnitSystem": "Astronomical",
390+
"BaseUnit": "LightYear"
375391
}
376392
]
377393
}

Common/UnitDefinitions/LuminousIntensity.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,39 @@
1515
},
1616
"FromUnitToBaseFunc": "x",
1717
"FromBaseToUnitFunc": "x",
18+
"UnitSystems": [ "SI", "CGS", "BI", "EE", "USC", "FPS", "Astronomical" ],
1819
"Localization": [
1920
{
2021
"Culture": "en-US",
2122
"Abbreviations": [ "cd" ]
2223
}
2324
]
2425
}
26+
],
27+
"UnitSystems": [
28+
{
29+
"UnitSystem": "SI",
30+
"BaseUnit": "Candela"
31+
},
32+
{
33+
"UnitSystem": "CGS",
34+
"BaseUnit": "Candela"
35+
},
36+
{
37+
"UnitSystem": "BI",
38+
"BaseUnit": "Candela"
39+
},
40+
{
41+
"UnitSystem": "EE",
42+
"BaseUnit": "Candela"
43+
},
44+
{
45+
"UnitSystem": "USC",
46+
"BaseUnit": "Candela"
47+
},
48+
{
49+
"UnitSystem": "FPS",
50+
"BaseUnit": "Candela"
51+
}
2552
]
2653
}

Common/UnitDefinitions/Mass.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"FromUnitToBaseFunc": "x/1e3",
1616
"FromBaseToUnitFunc": "x*1e3",
17+
"UnitSystems": [ "SI", "CGS", "Astronomical" ],
1718
"Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ],
1819
"Localization": [
1920
{
@@ -34,6 +35,7 @@
3435
},
3536
"FromUnitToBaseFunc": "x*1e3",
3637
"FromBaseToUnitFunc": "x/1e3",
38+
"UnitSystems": [ "SI", "CGS", "Astronomical" ],
3739
"Prefixes": [ "Kilo", "Mega" ],
3840
"Localization": [
3941
{
@@ -54,6 +56,7 @@
5456
},
5557
"FromUnitToBaseFunc": "x*9.0718474e2",
5658
"FromBaseToUnitFunc": "x/9.0718474e2",
59+
"UnitSystems": [ "USC" ],
5760
"XmlDocSummary": "The short ton is a unit of mass equal to 2,000 pounds (907.18474 kg), that is most commonly used in the United States – known there simply as the ton.",
5861
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Short_ton",
5962
"Localization": [
@@ -75,6 +78,7 @@
7578
},
7679
"FromUnitToBaseFunc": "x*1.0160469088e3",
7780
"FromBaseToUnitFunc": "x/1.0160469088e3",
81+
"UnitSystems": [ "BI" ],
7882
"XmlDocSummary": "Long ton (weight ton or Imperial ton) is a unit of mass equal to 2,240 pounds (1,016 kg) and is the name for the unit called the \"ton\" in the avoirdupois or Imperial system of measurements that was used in the United Kingdom and several other Commonwealth countries before metrication.",
7983
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Long_ton",
8084
"Localization": [
@@ -96,6 +100,7 @@
96100
},
97101
"FromUnitToBaseFunc": "x*0.45359237",
98102
"FromBaseToUnitFunc": "x/0.45359237",
103+
"UnitSystems": [ "EE", "BI", "USC" ],
99104
"XmlDocSummary": "The pound or pound-mass (abbreviations: lb, lbm) is a unit of mass used in the imperial, United States customary and other systems of measurement. A number of different definitions have been used, the most common today being the international avoirdupois pound which is legally defined as exactly 0.45359237 kilograms, and which is divided into 16 avoirdupois ounces.",
100105
"Prefixes": [ "Kilo", "Mega" ],
101106
"Localization": [
@@ -117,6 +122,7 @@
117122
},
118123
"FromUnitToBaseFunc": "x/35.2739619",
119124
"FromBaseToUnitFunc": "x*35.2739619",
125+
"UnitSystems": [ "EE", "BI", "USC" ],
120126
"XmlDocSummary": "An ounce (abbreviated oz) is usually the international avoirdupois ounce as used in the United States customary and British imperial systems, which is equal to one-sixteenth of a pound or approximately 28 grams. The abbreviation 'oz' derives from the Italian word onza (now spelled oncia).",
121127
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Ounce",
122128
"Localization": [
@@ -134,6 +140,7 @@
134140
},
135141
"FromUnitToBaseFunc": "x/6.852176556196105e-2",
136142
"FromBaseToUnitFunc": "x*6.852176556196105e-2",
143+
"UnitSystems": [ "FPS" ],
137144
"XmlDocSummary": "The slug (abbreviation slug) is a unit of mass that is accelerated by 1 ft/s² when a force of one pound (lbf) is exerted on it.",
138145
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Slug_(unit)",
139146
"Localization": [
@@ -151,6 +158,7 @@
151158
},
152159
"FromUnitToBaseFunc": "x/0.1574731728702698",
153160
"FromBaseToUnitFunc": "x*0.1574731728702698",
161+
"UnitSystems": [ "BI" ],
154162
"XmlDocSummary": "The stone (abbreviation st) is a unit of mass equal to 14 pounds avoirdupois (about 6.35 kilograms) used in Great Britain and Ireland for measuring human body weight.",
155163
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Stone_(unit)",
156164
"Localization": [
@@ -168,6 +176,7 @@
168176
},
169177
"FromUnitToBaseFunc": "x/0.022046226218487758",
170178
"FromBaseToUnitFunc": "x*0.022046226218487758",
179+
"UnitSystems": [ "USC" ],
171180
"XmlDocSummary": "The short hundredweight (abbreviation cwt) is a unit of mass equal to 100 pounds in US and Canada. In British English, the short hundredweight is referred to as the \"cental\".",
172181
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Hundredweight",
173182
"Localization": [
@@ -185,6 +194,7 @@
185194
},
186195
"FromUnitToBaseFunc": "x/0.01968413055222121",
187196
"FromBaseToUnitFunc": "x*0.01968413055222121",
197+
"UnitSystems": [ "EE", "BI" ],
188198
"XmlDocSummary": "The long or imperial hundredweight (abbreviation cwt) is a unit of mass equal to 112 pounds in US and Canada.",
189199
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Hundredweight",
190200
"Localization": [
@@ -202,6 +212,7 @@
202212
},
203213
"FromUnitToBaseFunc": "x/15432.358352941431",
204214
"FromBaseToUnitFunc": "x*15432.358352941431",
215+
"UnitSystems": [ "BI", "USC" ],
205216
"XmlDocSummary": "A grain is a unit of measurement of mass, and in the troy weight, avoirdupois, and Apothecaries' system, equal to exactly 64.79891 milligrams.",
206217
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Grain_(unit)",
207218
"Localization": [
@@ -219,6 +230,7 @@
219230
},
220231
"FromUnitToBaseFunc": "x * 1.98947e30",
221232
"FromBaseToUnitFunc": "x / 1.98947e30",
233+
"UnitSystems": [ "Astronomical" ],
222234
"XmlDocSummary": "Solar mass is a ratio unit to the mass of the solar system star, the sun.",
223235
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Solar_mass",
224236
"Localization": [
@@ -236,6 +248,7 @@
236248
},
237249
"FromUnitToBaseFunc": "x * 5.9722E+24",
238250
"FromBaseToUnitFunc": "x / 5.9722E+24",
251+
"UnitSystems": [ "Astronomical" ],
239252
"XmlDocSummary": "Earth mass is a ratio unit to the mass of planet Earth.",
240253
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Earth_mass",
241254
"Localization": [
@@ -245,5 +258,35 @@
245258
}
246259
]
247260
}
261+
],
262+
"UnitSystems": [
263+
{
264+
"UnitSystem": "SI",
265+
"BaseUnit": "Kilogram"
266+
},
267+
{
268+
"UnitSystem": "CGS",
269+
"BaseUnit": "Gram"
270+
},
271+
{
272+
"UnitSystem": "BI",
273+
"BaseUnit": "Pound"
274+
},
275+
{
276+
"UnitSystem": "EE",
277+
"BaseUnit": "Pound"
278+
},
279+
{
280+
"UnitSystem": "USC",
281+
"BaseUnit": "Pound"
282+
},
283+
{
284+
"UnitSystem": "FPS",
285+
"BaseUnit": "Pound"
286+
},
287+
{
288+
"UnitSystem": "Astronomical",
289+
"BaseUnit": "Kilogram"
290+
}
248291
]
249292
}

0 commit comments

Comments
 (0)