Add support for short tons
This commit is contained in:
parent
d6e0e95a6a
commit
f69177edca
|
@ -64,6 +64,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
|||
from: pound_from,
|
||||
to: MetricQuantity { amount: 14.0 * pound_to, unit: Metric::Gram },
|
||||
},
|
||||
NonMetric::ShortTon => Conversion {
|
||||
offset: 0.0,
|
||||
from: pound_from,
|
||||
to: MetricQuantity { amount: 2000.0 * pound_to, unit: Metric::Gram },
|
||||
},
|
||||
// Temperature
|
||||
NonMetric::Fahrenheit => Conversion {
|
||||
offset: 32.0,
|
||||
|
@ -184,6 +189,7 @@ mod test {
|
|||
Test(NonMetric::Ounce, 28.349523125),
|
||||
Test(NonMetric::Pound, 453.59237),
|
||||
Test(NonMetric::Stone, 6350.29318),
|
||||
Test(NonMetric::ShortTon, 907184.74),
|
||||
];
|
||||
run_tests(&tests, Metric::Gram);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
|||
NonMetric::Ounce => "ounces",
|
||||
NonMetric::Pound => "pounds",
|
||||
NonMetric::Stone => "stones",
|
||||
NonMetric::ShortTon => "short tons",
|
||||
// Temperature
|
||||
NonMetric::Fahrenheit => "degrees Fahrenheit",
|
||||
// Area
|
||||
|
@ -129,6 +130,7 @@ mod test {
|
|||
assert_eq!(run("1 oz"), Ok("28.35 g".to_string()));
|
||||
assert_eq!(run("1 lb"), Ok("453.6 g".to_string()));
|
||||
assert_eq!(run("1 st"), Ok("6.35 kg".to_string()));
|
||||
assert_eq!(run("1 short ton"), Ok("907.2 kg".to_string()));
|
||||
// Temperature
|
||||
assert_eq!(run("-40 °F"), Ok("-40 °C".to_string()));
|
||||
assert_eq!(run("0 °F"), Ok("-17.78 °C".to_string()));
|
||||
|
|
16
src/parse.rs
16
src/parse.rs
|
@ -98,6 +98,13 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
|||
"stones" => Ok(NonMetric::Stone),
|
||||
"st" => Ok(NonMetric::Stone),
|
||||
|
||||
"short ton" => Ok(NonMetric::ShortTon),
|
||||
"short tons" => Ok(NonMetric::ShortTon),
|
||||
"US ton" => Ok(NonMetric::ShortTon),
|
||||
"US tons" => Ok(NonMetric::ShortTon),
|
||||
"us ton" => Ok(NonMetric::ShortTon),
|
||||
"us tons" => Ok(NonMetric::ShortTon),
|
||||
|
||||
// Temperature
|
||||
"degree Fahrenheit" => Ok(NonMetric::Fahrenheit),
|
||||
"degrees Fahrenheit" => Ok(NonMetric::Fahrenheit),
|
||||
|
@ -463,6 +470,15 @@ mod test {
|
|||
"st",
|
||||
]);
|
||||
|
||||
test_units(NonMetric::ShortTon, &[
|
||||
"short ton",
|
||||
"short tons",
|
||||
"US ton",
|
||||
"US tons",
|
||||
"us ton",
|
||||
"us tons",
|
||||
]);
|
||||
|
||||
// Temperature
|
||||
test_units(NonMetric::Fahrenheit, &[
|
||||
"degree Fahrenheit",
|
||||
|
|
|
@ -19,6 +19,7 @@ pub enum NonMetric {
|
|||
Ounce,
|
||||
Pound,
|
||||
Stone,
|
||||
ShortTon,
|
||||
// Temperature
|
||||
Fahrenheit,
|
||||
// Area
|
||||
|
|
Loading…
Reference in New Issue