Add support for imperial quarts
This commit is contained in:
parent
9ef0c9655d
commit
8d50c9643a
4 changed files with 17 additions and 0 deletions
|
@ -105,6 +105,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
||||||
from: imperial_gallon_from,
|
from: imperial_gallon_from,
|
||||||
to: MetricQuantity { amount: imperial_gallon_to, unit: Metric::Litre },
|
to: MetricQuantity { amount: imperial_gallon_to, unit: Metric::Litre },
|
||||||
},
|
},
|
||||||
|
NonMetric::ImperialQuart => Conversion {
|
||||||
|
offset: 0.0,
|
||||||
|
from: 4.0 * imperial_gallon_from,
|
||||||
|
to: MetricQuantity { amount: imperial_gallon_to, unit: Metric::Litre },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +182,7 @@ mod test {
|
||||||
fn fluid_volume() {
|
fn fluid_volume() {
|
||||||
let tests = [
|
let tests = [
|
||||||
Test(NonMetric::ImperialGallon, 4.54609),
|
Test(NonMetric::ImperialGallon, 4.54609),
|
||||||
|
Test(NonMetric::ImperialQuart, 1.1365225),
|
||||||
];
|
];
|
||||||
run_tests(&tests, Metric::Litre);
|
run_tests(&tests, Metric::Litre);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
||||||
NonMetric::CubicFoot => "cubic feet",
|
NonMetric::CubicFoot => "cubic feet",
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
NonMetric::ImperialGallon => "imperial gallons",
|
NonMetric::ImperialGallon => "imperial gallons",
|
||||||
|
NonMetric::ImperialQuart => "imperial quarts",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,5 +130,6 @@ mod test {
|
||||||
assert_eq!(run("1 ft³"), Ok("28 317 cm³".to_string()));
|
assert_eq!(run("1 ft³"), Ok("28 317 cm³".to_string()));
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
assert_eq!(run("1 imp gal"), Ok("4.546 l".to_string()));
|
assert_eq!(run("1 imp gal"), Ok("4.546 l".to_string()));
|
||||||
|
assert_eq!(run("1 imp qt"), Ok("1.137 l".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,10 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
||||||
"imperial gallons" => Ok(NonMetric::ImperialGallon),
|
"imperial gallons" => Ok(NonMetric::ImperialGallon),
|
||||||
"imp gal" => Ok(NonMetric::ImperialGallon),
|
"imp gal" => Ok(NonMetric::ImperialGallon),
|
||||||
|
|
||||||
|
"imperial quart" => Ok(NonMetric::ImperialQuart),
|
||||||
|
"imperial quarts" => Ok(NonMetric::ImperialQuart),
|
||||||
|
"imp qt" => Ok(NonMetric::ImperialQuart),
|
||||||
|
|
||||||
_ => Err(ParseError::UnknownUnit(input)),
|
_ => Err(ParseError::UnknownUnit(input)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,6 +433,10 @@ mod test {
|
||||||
assert_eq!(parse_unit("imperial gallons".to_string()), Ok(NonMetric::ImperialGallon));
|
assert_eq!(parse_unit("imperial gallons".to_string()), Ok(NonMetric::ImperialGallon));
|
||||||
assert_eq!(parse_unit("imp gal".to_string()), Ok(NonMetric::ImperialGallon));
|
assert_eq!(parse_unit("imp gal".to_string()), Ok(NonMetric::ImperialGallon));
|
||||||
|
|
||||||
|
assert_eq!(parse_unit("imperial quart".to_string()), Ok(NonMetric::ImperialQuart));
|
||||||
|
assert_eq!(parse_unit("imperial quarts".to_string()), Ok(NonMetric::ImperialQuart));
|
||||||
|
assert_eq!(parse_unit("imp qt".to_string()), Ok(NonMetric::ImperialQuart));
|
||||||
|
|
||||||
// Unknown unit
|
// Unknown unit
|
||||||
assert_eq!(parse_unit("hutenosa".to_string()), Err(ParseError::UnknownUnit("hutenosa".to_string())));
|
assert_eq!(parse_unit("hutenosa".to_string()), Err(ParseError::UnknownUnit("hutenosa".to_string())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub enum NonMetric {
|
||||||
CubicFoot,
|
CubicFoot,
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
ImperialGallon,
|
ImperialGallon,
|
||||||
|
ImperialQuart,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
|
Loading…
Reference in a new issue