Skip to content

Commit

Permalink
CLDR-15269 Fix dalton, regenerate tests, and do a bit of code cleanup. (
Browse files Browse the repository at this point in the history
#3162)

* CLDR-15269 Fix dalton, regenerate tests, and do a bit of code cleanup.

* CLDR-15269 Retract changes to TestCoverageLevel (mistakenly included), spotless

* CLDR-15269 Fix formats in TestExampleGenerator
  • Loading branch information
macchiati authored Aug 9, 2023
1 parent 72bbd2e commit b371089
Show file tree
Hide file tree
Showing 11 changed files with 582 additions and 414 deletions.
3 changes: 2 additions & 1 deletion common/supplemental/units.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For terms of use, see http://www.unicode.org/copyright.html
<unitConstant constant="gravity" value="9.80665"/>
<unitConstant constant="PI" value="411557987 / 131002976" status='approximate'/>
<unitConstant constant="G" value="6.67408E-11" status='approximate' description="https://arxiv.org/pdf/1510.07674.pdf see 2014 CODATA"/>
<unitConstant constant="AMU" value="1.66053878283E-27" status='approximate' description="https://www.nist.gov/pml/special-publication-811/nist-guide-si-chapter-5-units-outside-si#table7"/>
</unitConstants>
<unitQuantities>
<!-- NB: quantity ordering is used in canonical order of derived units. -->
Expand Down Expand Up @@ -120,6 +121,7 @@ For terms of use, see http://www.unicode.org/copyright.html
<convertUnit source='candela' baseUnit='candela' systems="si metric prefixable"/>

<!-- mass -->
<convertUnit source='dalton' baseUnit='kilogram' factor='AMU' systems="si_acceptable metric prefixable"/>
<convertUnit source='grain' baseUnit='kilogram' factor='lb_to_kg/7000' systems="ussystem uksystem"/>
<convertUnit source='carat' baseUnit='kilogram' factor='0.0002' systems="metric_adjacent"/>
<convertUnit source='gram' baseUnit='kilogram' factor='0.001' systems="si metric prefixable"/>
Expand Down Expand Up @@ -260,7 +262,6 @@ For terms of use, see http://www.unicode.org/copyright.html

<!-- energy -->
<convertUnit source='electronvolt' baseUnit='kilogram-square-meter-per-square-second' factor='1.602177E-19' systems='si_acceptable metric_adjacent'/>
<convertUnit source='dalton' baseUnit='kilogram-square-meter-per-square-second' factor='1.49241808560E-10' systems="si_acceptable metric prefixable"/>
<convertUnit source='joule' baseUnit='kilogram-square-meter-per-square-second' systems="si metric prefixable"/>
<convertUnit source='calorie' baseUnit='kilogram-square-meter-per-square-second' factor='4.184' systems="metric_adjacent prefixable"/> <!-- th -->
<convertUnit source='calorie-it' baseUnit='kilogram-square-meter-per-square-second' factor='4.1868' systems="metric_adjacent prefixable"/> <!-- th -->
Expand Down
689 changes: 386 additions & 303 deletions common/testData/units/unitPreferencesTest.txt

Large diffs are not rendered by default.

57 changes: 48 additions & 9 deletions common/testData/units/unitsTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,36 @@
# round to 4 decimal digits before comparing.
# Note that certain conversions are approximate, such as degrees to radians
#
# Generation: Set GENERATE_TESTS in TestUnits.java, and look at TestParseUnit results.
# Generation: Set GENERATE_TESTS in TestUnits.java to regenerate unitsTest.txt.

acceleration ; meter-per-square-second ; meter-per-square-second ; 1 * x ; 1,000.00
acceleration ; g-force ; meter-per-square-second ; 9.80665 * x ; 9806.65
angle ; arc-second ; revolution ; 0.0000625/81 * x ; 7.716049E-4
angle ; arc-minute ; revolution ; 0.00125/27 * x ; 0.0462963
angle ; degree ; revolution ; 0.025/9 * x ; 2.777778
angle ; radian ; revolution ; 65,501,488/411,557,987 * x ; 159.1549
angle ; radian ; revolution ; 65,501,488/411557987 * x ; 159.1549
angle ; revolution ; revolution ; 1 * x ; 1,000.00
area ; square-centimeter ; square-meter ; 0.0001 * x ; 0.1
area ; square-inch ; square-meter ; 0.00064516 * x ; 0.64516
area ; square-foot ; square-meter ; 0.09290304 * x ; 92.90304
area ; square-yard ; square-meter ; 0.83612736 * x ; 836.1274
area ; square-meter ; square-meter ; 1 * x ; 1,000.00
area ; bu-jp ; square-meter ; 400/121 * x ; 3305.785
area ; se-jp ; square-meter ; 12,000/121 * x ; 99173.55
area ; dunam ; square-meter ; 1,000 * x ; 1000000.0
area ; acre ; square-meter ; 4,046.8564224 * x ; 4046856.0
area ; cho ; square-meter ; 1,200,000/121 * x ; 9917355.0
area ; hectare ; square-meter ; 10,000 * x ; 1.0E7
area ; square-kilometer ; square-meter ; 1,000,000 * x ; 1.0E9
area ; square-mile ; square-meter ; 2,589,988.110336 * x ; 2.589988E9
concentration ; milligram-ofglucose-per-deciliter ; kilogram-item-per-kilogram-cubic-meter ; 60,221,407,600,000,000,000,000,000,000/1,801,557 * x ; 3.342742E25
catalytic-activity ; katal ; item-per-second ; 602,214,076,000,000,000,000,000 * x ; 6.022141E26
concentration ; milligram-ofglucose-per-deciliter ; kilogram-item-per-kilogram-cubic-meter ; 60,221,407,600,000,000,000,000,000,000/1801557 * x ; 3.342742E25
concentration ; millimole-per-liter ; item-per-cubic-meter ; 602,214,076,000,000,000,000,000 * x ; 6.022141E26
concentration-mass ; ofglucose ; item-per-kilogram ; 6,022,140,760,000,000,000,000,000,000,000/1,801,557 * x ; 3.342742E27
concentration-mass ; ofglucose ; item-per-kilogram ; 6,022,140,760,000,000,000,000,000,000,000/1801557 * x ; 3.342742E27
consumption ; liter-per-100-kilometer ; cubic-meter-per-meter ; 0.00000001 * x ; 1.0E-5
consumption ; liter-per-kilometer ; cubic-meter-per-meter ; 0.000001 * x ; 0.001
consumption-inverse ; mile-per-gallon-imperial ; meter-per-cubic-meter ; 160,934,400,000/454,609 * x ; 3.540062E8
consumption-inverse ; mile-per-gallon ; meter-per-cubic-meter ; 48,000,000,000/112,903 * x ; 4.251437E8
consumption-inverse ; mile-per-gallon-imperial ; meter-per-cubic-meter ; 160,934,400,000/454609 * x ; 3.540062E8
consumption-inverse ; mile-per-gallon ; meter-per-cubic-meter ; 48,000,000,000/112903 * x ; 4.251437E8
digital ; bit ; bit ; 1 * x ; 1,000.00
digital ; byte ; bit ; 8 * x ; 8000.0
digital ; kilobit ; bit ; 1,000 * x ; 1000000.0
Expand All @@ -59,23 +63,30 @@ duration ; day ; second ; 86,400 * x ; 8.64E7
duration ; day-person ; second ; 86,400 * x ; 8.64E7
duration ; week ; second ; 604,800 * x ; 6.048E8
duration ; week-person ; second ; 604,800 * x ; 6.048E8
duration ; fortnight ; second ; 1,209,600 * x ; 1.2096E9
electric-capacitance ; farad ; pow4-second-square-ampere-per-kilogram-square-meter ; 1 * x ; 1000.0
electric-charge ; coulomb ; second-ampere ; 1 * x ; 1000.0
electric-conductance ; siemens ; cubic-second-square-ampere-per-kilogram-square-meter ; 1 * x ; 1000.0
electric-current ; milliampere ; ampere ; 0.001 * x ; 1.0
electric-current ; ampere ; ampere ; 1 * x ; 1,000.00
electric-inductance ; henry ; kilogram-square-meter-per-square-second-square-ampere ; 1 * x ; 1000.0
electric-resistance ; ohm ; kilogram-square-meter-per-cubic-second-square-ampere ; 1 * x ; 1000.0
energy ; electronvolt ; kilogram-square-meter-per-square-second ; 0.0000000000000000001602177 * x ; 1.602177E-16
energy ; dalton ; kilogram-square-meter-per-square-second ; 0.00000000014924180856 * x ; 1.492418E-7
energy ; joule ; kilogram-square-meter-per-square-second ; 1 * x ; 1000.0
energy ; newton-meter ; kilogram-square-meter-per-square-second ; 1 * x ; 1000.0
energy ; pound-force-foot ; kilogram-square-meter-per-square-second ; 1.3558179483314004 * x ; 1355.818
energy ; calorie ; kilogram-square-meter-per-square-second ; 4.184 * x ; 4184.0
energy ; calorie-it ; kilogram-square-meter-per-square-second ; 4.1868 * x ; 4186.8
energy ; kilojoule ; kilogram-square-meter-per-square-second ; 1,000 * x ; 1000000.0
energy ; british-thermal-unit ; kilogram-square-meter-per-square-second ; 9,489.1523804/9 * x ; 1054350.0
energy ; british-thermal-unit-it ; kilogram-square-meter-per-square-second ; 1,055.05585262 * x ; 1055056.0
energy ; foodcalorie ; kilogram-square-meter-per-square-second ; 4,184 * x ; 4184000.0
energy ; kilocalorie ; kilogram-square-meter-per-square-second ; 4,184 * x ; 4184000.0
energy ; kilowatt-hour ; kilogram-square-meter-second-per-cubic-second ; 3,600,000 * x ; 3.6E9
energy ; therm-us ; kilogram-square-meter-per-square-second ; 105,480,400 * x ; 1.054804E11
force ; newton ; kilogram-meter-per-square-second ; 1 * x ; 1000.0
force ; pound-force ; kilogram-meter-per-square-second ; 4.4482216152605 * x ; 4448.222
force ; kilogram-force ; kilogram-meter-per-square-second ; 9.80665 * x ; 9806.65
force ; kilowatt-hour-per-100-kilometer ; kilogram-square-meter-second-per-meter-cubic-second ; 36 * x ; 36000.0
frequency ; hertz ; revolution-per-second ; 1 * x ; 1000.0
frequency ; kilohertz ; revolution-per-second ; 1,000 * x ; 1000000.0
Expand All @@ -85,19 +96,30 @@ graphics ; dot ; pixel ; 1 * x ; 1000.0
graphics ; pixel ; pixel ; 1 * x ; 1,000.00
graphics ; megapixel ; pixel ; 1,000,000 * x ; 1.0E9
illuminance ; lux ; candela-per-square-meter ; 1 * x ; 1000.0
ionizing-radiation ; gray ; square-meter-per-square-second ; 1 * x ; 1000.0
ionizing-radiation ; sievert ; square-meter-per-square-second ; 1 * x ; 1000.0
length ; picometer ; meter ; 0.000000000001 * x ; 1.0E-9
length ; nanometer ; meter ; 0.000000001 * x ; 1.0E-6
length ; micrometer ; meter ; 0.000001 * x ; 0.001
length ; rin ; meter ; 0.004/121 * x ; 0.03305785
length ; point ; meter ; 0.003175/9 * x ; 0.3527778
length ; millimeter ; meter ; 0.001 * x ; 1.0
length ; sun ; meter ; 0.4/121 * x ; 3.305785
length ; centimeter ; meter ; 0.01 * x ; 10.0
length ; inch ; meter ; 0.0254 * x ; 25.4
length ; shaku-length ; meter ; 4/121 * x ; 33.05785
length ; shaku-cloth ; meter ; 5/121 * x ; 41.32231
length ; decimeter ; meter ; 0.1 * x ; 100.0
length ; ken ; meter ; 24/121 * x ; 198.3471
length ; foot ; meter ; 0.3048 * x ; 304.8
length ; jo-jp ; meter ; 40/121 * x ; 330.5785
length ; yard ; meter ; 0.9144 * x ; 914.4
length ; meter ; meter ; 1 * x ; 1,000.00
length ; fathom ; meter ; 1.8288 * x ; 1828.8
length ; rod ; meter ; 5.0292 * x ; 5029.2
length ; chain ; meter ; 20.1168 * x ; 20116.8
length ; furlong ; meter ; 201.168 * x ; 201168.0
length ; ri-jp ; meter ; 51,840/121 * x ; 428429.8
length ; kilometer ; meter ; 1,000 * x ; 1000000.0
length ; mile ; meter ; 1,609.344 * x ; 1609344.0
length ; nautical-mile ; meter ; 1,852 * x ; 1852000.0
Expand All @@ -107,19 +129,24 @@ length ; earth-radius ; meter ; 6,378,100 * x ; 6.3781E9
length ; solar-radius ; meter ; 695,700,000 * x ; 6.957E11
length ; astronomical-unit ; meter ; 149,597,870,700 * x ; 1.495979E14
length ; light-year ; meter ; 9,460,730,472,580,800 * x ; 9.46073E18
length ; parsec ; meter ; 12,699,352,539,696,155,673,600,000/411,557,987 * x ; 3.085678E19
length ; parsec ; meter ; 12,699,352,539,696,155,673,600,000/411557987 * x ; 3.085678E19
luminous-flux ; lumen ; candela-square-meter-per-square-meter ; 1 * x ; 1000.0
luminous-intensity ; candela ; candela ; 1 * x ; 1,000.00
magnetic-flux ; weber ; kilogram-square-meter-per-square-second-ampere ; 1 * x ; 1000.0
magnetic-induction ; tesla ; kilogram-per-square-second-ampere ; 1 * x ; 1000.0
mass ; dalton ; kilogram ; 0.00000000000000000000000000166053878283 * x ; 1.660539E-24
mass ; microgram ; kilogram ; 0.000000001 * x ; 1.0E-6
mass ; milligram ; kilogram ; 0.000001 * x ; 0.001
mass ; grain ; kilogram ; 0.00006479891 * x ; 0.06479891
mass ; carat ; kilogram ; 0.0002 * x ; 0.2
mass ; fun ; kilogram ; 0.000375 * x ; 0.375
mass ; gram ; kilogram ; 0.001 * x ; 1.0
mass ; ounce ; kilogram ; 0.028349523125 * x ; 28.34952
mass ; ounce-troy ; kilogram ; 0.03110348 * x ; 31.10348
mass ; pound ; kilogram ; 0.45359237 * x ; 453.5924
mass ; kilogram ; kilogram ; 1 * x ; 1,000.00
mass ; stone ; kilogram ; 6.35029318 * x ; 6350.293
mass ; slug ; kilogram ; 5,560.277019075625/381 * x ; 14593.9
mass ; ton ; kilogram ; 907.18474 * x ; 907184.7
mass ; tonne ; kilogram ; 1,000 * x ; 1000000.0
mass ; earth-mass ; kilogram ; 5,972,200,000,000,000,000,000,000 * x ; 5.9722E27
Expand All @@ -143,21 +170,25 @@ pressure ; millibar ; kilogram-per-meter-square-second ; 100 * x ; 100000.0
pressure ; millimeter-ofhg ; kilogram-meter-per-square-meter-square-second ; 133.322387415 * x ; 133322.4
pressure ; kilopascal ; kilogram-per-meter-square-second ; 1,000 * x ; 1000000.0
pressure ; inch-ofhg ; kilogram-meter-per-square-meter-square-second ; 3,386.388640341 * x ; 3386389.0
pressure ; pound-force-per-square-inch ; kilogram-meter-per-square-meter-square-second ; 111,205,540.3815125/16,129 * x ; 6894757.0
pressure ; pound-force-per-square-inch ; kilogram-meter-per-square-meter-square-second ; 111,205,540.3815125/16129 * x ; 6894757.0
pressure ; bar ; kilogram-per-meter-square-second ; 100,000 * x ; 1.0E8
pressure ; atmosphere ; kilogram-per-meter-square-second ; 101,325 * x ; 1.01325E8
pressure ; megapascal ; kilogram-per-meter-square-second ; 1,000,000 * x ; 1.0E9
pressure ; gasoline-equivalent ; kilogram-per-meter-square-second ; 722,250,000,000,000,000/22532213 * x ; 3.205411E13
pressure-per-length ; ofhg ; kilogram-per-square-meter-square-second ; 133,322.387415 * x ; 1.333224E8
radioactivity ; becquerel ; per-second ; 1 * x ; 1000.0
resolution ; dot-per-inch ; pixel-per-meter ; 5,000/127 * x ; 39370.08
resolution ; pixel-per-inch ; pixel-per-meter ; 5,000/127 * x ; 39370.08
resolution ; dot-per-centimeter ; pixel-per-meter ; 100 * x ; 100000.0
resolution ; pixel-per-centimeter ; pixel-per-meter ; 100 * x ; 100000.0
solid-angle ; steradian ; square-revolution ; 4,290,444,930,214,144/169379976663492169 * x ; 25.3303
speed ; kilometer-per-hour ; meter-per-second ; 2.5/9 * x ; 277.7778
speed ; mile-per-hour ; meter-per-second ; 0.44704 * x ; 447.04
speed ; knot ; meter-per-second ; 4.63/9 * x ; 514.4444
speed ; meter-per-second ; meter-per-second ; 1 * x ; 1,000.00
substance-amount ; item ; item ; 1 * x ; 1,000.00
substance-amount ; mole ; item ; 602,214,076,000,000,000,000,000 * x ; 6.022141E26
temperature ; rankine ; kelvin ; 5/9 * x ; 555.5556
temperature ; fahrenheit ; kelvin ; 5/9 * x - 2,298.35/9 ; 810.9278
temperature ; kelvin ; kelvin ; 1 * x ; 1,000.00
temperature ; celsius ; kelvin ; 1 * x - 273.15 ; 1273.15
Expand All @@ -167,30 +198,38 @@ volume ; drop ; cubic-meter ; 0.0000001540287998046875/3 * x ; 5.134293E-5
volume ; pinch ; cubic-meter ; 0.00000023104319970703125 * x ; 2.310432E-4
volume ; cubic-centimeter ; cubic-meter ; 0.000001 * x ; 0.001
volume ; milliliter ; cubic-meter ; 0.000001 * x ; 0.001
volume ; sai ; cubic-meter ; 0.002401/1331 * x ; 0.001803907
volume ; dessert-spoon ; cubic-meter ; 0.00000184834559765625 * x ; 0.001848346
volume ; dessert-spoon-imperial ; cubic-meter ; 0.0000022197705078125 * x ; 0.002219771
volume ; dram ; cubic-meter ; 0.0000036966911953125 * x ; 0.003696691
volume ; teaspoon ; cubic-meter ; 0.00000492892159375 * x ; 0.004928922
volume ; kosaji ; cubic-meter ; 0.000005 * x ; 0.005
volume ; centiliter ; cubic-meter ; 0.00001 * x ; 0.01
volume ; tablespoon ; cubic-meter ; 0.00001478676478125 * x ; 0.01478676
volume ; osaji ; cubic-meter ; 0.000015 * x ; 0.015
volume ; cubic-inch ; cubic-meter ; 0.000016387064 * x ; 0.01638706
volume ; shaku ; cubic-meter ; 0.02401/1331 * x ; 0.01803907
volume ; fluid-ounce-imperial ; cubic-meter ; 0.0000284130625 * x ; 0.02841306
volume ; fluid-ounce ; cubic-meter ; 0.0000295735295625 * x ; 0.02957353
volume ; jigger ; cubic-meter ; 0.00004436029434375 * x ; 0.04436029
volume ; cup-jp ; cubic-meter ; 0.0001 * x ; 0.1
volume ; deciliter ; cubic-meter ; 0.0001 * x ; 0.1
volume ; cup ; cubic-meter ; 0.0002365882365 * x ; 0.2365882
volume ; cup-metric ; cubic-meter ; 0.00025 * x ; 0.25
volume ; pint ; cubic-meter ; 0.000473176473 * x ; 0.4731765
volume ; pint-metric ; cubic-meter ; 0.0005 * x ; 0.5
volume ; pint-imperial ; cubic-meter ; 0.00056826125 * x ; 0.5682612
volume ; quart ; cubic-meter ; 0.000946352946 * x ; 0.9463529
volume ; liter ; cubic-meter ; 0.001 * x ; 1.0
volume ; quart-imperial ; cubic-meter ; 0.0011365225 * x ; 1.136522
volume ; gallon ; cubic-meter ; 0.003785411784 * x ; 3.785412
volume ; gallon-imperial ; cubic-meter ; 0.00454609 * x ; 4.54609
volume ; to-jp ; cubic-meter ; 24.01/1331 * x ; 18.03907
volume ; cubic-foot ; cubic-meter ; 0.028316846592 * x ; 28.31685
volume ; bushel ; cubic-meter ; 0.03523907016688 * x ; 35.23907
volume ; hectoliter ; cubic-meter ; 0.1 * x ; 100.0
volume ; barrel ; cubic-meter ; 0.158987294928 * x ; 158.9873
volume ; koku ; cubic-meter ; 240.1/1331 * x ; 180.3907
volume ; cubic-yard ; cubic-meter ; 0.764554857984 * x ; 764.5549
volume ; cubic-meter ; cubic-meter ; 1 * x ; 1,000.00
volume ; megaliter ; cubic-meter ; 1,000 * x ; 1000000.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ private String handleFormatUnit(XPathParts parts, String unitPattern) {
String relatedUnit = relatedUnitInfo.getValue();
Set<UnitSystem> systems = UNIT_CONVERTER.getSystemsEnum(relatedUnit);
String relation = "≡";
String relatedValueDisplay = relatedValue.toString(FormatStyle.basic);
String relatedValueDisplay = relatedValue.toString(FormatStyle.approx);
if (relatedValueDisplay.startsWith("~")) {
relation = "≈";
relatedValueDisplay = relatedValueDisplay.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
UnitSystem sortingSystem = systems.iterator().next();
switch (sortingSystem) {
case si:
case si_acceptable:
sortingSystem = UnitSystem.metric;
break;
case uksystem:
Expand All @@ -141,7 +142,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {

final String repeatingFactor =
targetInfo.unitInfo.factor.toString(FormatStyle.repeating);
final String basicFactor = targetInfo.unitInfo.factor.toString(FormatStyle.basic);
final String basicFactor = targetInfo.unitInfo.factor.toString(FormatStyle.approx);
final String repeatingOffset =
targetInfo.unitInfo.offset.equals(Rational.ZERO)
? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void main(String[] args) {
String reducedUnit = uc.getReducedUnit(metricUnit.value);
String standardUnit = uc.getStandardUnit(metricUnit.value);
System.out.println(
toValue.toString(FormatStyle.simple)
toValue.toString(FormatStyle.formatted)
+ "\t"
+ metricUnit
+ (reducedUnit.equals(metricUnit.value) ? "" : "\t≡ " + reducedUnit)
Expand All @@ -82,7 +82,7 @@ public static void main(String[] args) {
return;
}
System.out.println(
newRational.toString(FormatStyle.simple)
newRational.toString(FormatStyle.formatted)
+ "\t"
+ toString
+ "\t≡ "
Expand Down
Loading

0 comments on commit b371089

Please sign in to comment.