Functional Weave
Code in Rust

units.convert@1.0.0

vectors.json

3,644 bytes · view raw

[
  { "name": "one inch is 25.4 mm exactly", "args": ["1", "in", "mm", 6], "expect": "25.4" },
  { "name": "one foot is 0.3048 m exactly", "args": ["1", "ft", "m", 12], "expect": "0.3048" },
  { "name": "100 lb is 45.359237 kg exactly", "args": ["100", "lb", "kg", 8], "expect": "45.359237" },
  { "name": "a half at the last place rounds away from zero, where float multiplication gets 19.049999999999997", "args": ["0.75", "in", "mm", 1], "expect": "19.1" },
  { "name": "an exact half rounds away from zero, not to even", "args": ["1.25", "cm", "mm", 0], "expect": "13" },
  { "name": "a negative exact half rounds away from zero", "args": ["-1.25", "cm", "mm", 0], "expect": "-13" },
  { "name": "a small negative result that rounds to zero is 0, not -0", "args": ["-0.4", "mm", "m", 0], "expect": "0" },
  { "name": "minus 40 is the same in Celsius and Fahrenheit", "args": ["-40", "degC", "degF", 6], "expect": "-40" },
  { "name": "absolute zero in Celsius", "args": ["0", "K", "degC", 2], "expect": "-273.15" },
  { "name": "absolute zero in Fahrenheit", "args": ["0", "K", "degF", 2], "expect": "-459.67" },
  { "name": "boiling water in Fahrenheit", "args": ["100", "degC", "degF", 0], "expect": "212" },
  { "name": "98.6 F is exactly 37 C", "args": ["98.6", "degF", "degC", 3], "expect": "37" },
  { "name": "Rankine to Kelvin is a plain 5/9", "args": ["491.67", "degR", "K", 2], "expect": "273.15" },
  { "name": "US gallon is 3.785411784 L exactly", "args": ["1", "gal_us", "L", 9], "expect": "3.785411784" },
  { "name": "US gallon to 6 places rounds up", "args": ["1", "gal_us", "L", 6], "expect": "3.785412" },
  { "name": "imperial gallon in US gallons", "args": ["1", "gal_imp", "gal_us", 5], "expect": "1.20095" },
  { "name": "international acre in square metres", "args": ["1", "acre", "m2", 7], "expect": "4046.8564224" },
  { "name": "a square mile is 640 acres", "args": ["1", "mi2", "acre", 0], "expect": "640" },
  { "name": "a stone is 14 pounds", "args": ["1", "st", "lb", 3], "expect": "14" },
  { "name": "kilowatt hour in IT British thermal units", "args": ["1", "kWh", "Btu", 3], "expect": "3412.142" },
  { "name": "a thermochemical kilocalorie is 4184 J", "args": ["1", "kcal", "J", 0], "expect": "4184" },
  { "name": "the largest factor in the table at full input precision stays exact", "args": ["999999999999999", "MWh", "Btu", 2], "expect": "3412141633127938507904.39" },
  { "name": "trailing zeros in the input do not count as digits", "args": ["12.500000000000000000", "m", "cm", 0], "expect": "1250" },
  { "name": "thousands separators are refused", "args": ["1,200", "m", "km", 3], "expectError": "value must be a plain decimal like \"12.5\", received \"1,200\"" },
  { "name": "exponents are refused", "args": ["1e3", "m", "km", 3], "expectError": "value must be a plain decimal" },
  { "name": "more than 15 significant digits is refused", "args": ["1234567890123456", "m", "km", 3], "expectError": "has too many digits" },
  { "name": "an ambiguous gallon is an unknown unit", "args": ["1", "gal", "L", 3], "expectError": "unknown unit \"gal\"" },
  { "name": "symbols are case-sensitive", "args": ["1", "MM", "m", 3], "expectError": "unknown unit \"MM\"" },
  { "name": "mass cannot become length", "args": ["1", "kg", "m", 3], "expectError": "cannot convert kg (mass) to m (length)" },
  { "name": "decimals above 12 are refused", "args": ["1", "m", "cm", 13], "expectError": "decimals must be a whole number from 0 to 12, received 13" },
  { "name": "negative decimals are refused", "args": ["1", "m", "cm", -1], "expectError": "decimals must be a whole number from 0 to 12, received -1" }
]