diff --git a/src/conversions.rs b/src/conversions.rs index 45c098b..8630d55 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -105,6 +105,11 @@ fn get_conversion(unit: NonMetric) -> Conversion { from: imperial_gallon_from, 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() { let tests = [ Test(NonMetric::ImperialGallon, 4.54609), + Test(NonMetric::ImperialQuart, 1.1365225), ]; run_tests(&tests, Metric::Litre); } diff --git a/src/lib.rs b/src/lib.rs index be5bd68..33dc895 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str { NonMetric::CubicFoot => "cubic feet", // Fluid volume 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())); // Fluid volume assert_eq!(run("1 imp gal"), Ok("4.546 l".to_string())); + assert_eq!(run("1 imp qt"), Ok("1.137 l".to_string())); } } diff --git a/src/parse.rs b/src/parse.rs index 7172571..547c66c 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -190,6 +190,10 @@ fn parse_unit(input: String) -> Result { "imperial gallons" => 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)), } } @@ -429,6 +433,10 @@ mod test { 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("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 assert_eq!(parse_unit("hutenosa".to_string()), Err(ParseError::UnknownUnit("hutenosa".to_string()))); } diff --git a/src/units.rs b/src/units.rs index 5c6f6a5..72c287e 100644 --- a/src/units.rs +++ b/src/units.rs @@ -31,6 +31,7 @@ pub enum NonMetric { CubicFoot, // Fluid volume ImperialGallon, + ImperialQuart, } #[derive(Clone, Copy, Debug, PartialEq)]