diff --git a/src/conversions.rs b/src/conversions.rs index e15161b..4f3362d 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -75,6 +75,11 @@ fn get_conversion(unit: NonMetric) -> Conversion { from: inch_from * inch_from, to: MetricQuantity { amount: 12.0 * inch_to * 12.0 * inch_to, unit: Metric::SquareMetre }, }, + NonMetric::Acre => Conversion { + offset: 0.0, + from: inch_from * inch_from, + to: MetricQuantity { amount: 43_560.0 * 12.0 * inch_to * 12.0 * inch_to, unit: Metric::SquareMetre }, + }, } } @@ -128,6 +133,7 @@ mod test { let tests = [ Test(NonMetric::SquareInch, 0.00064516), Test(NonMetric::SquareFoot, 0.09290304), + Test(NonMetric::Acre, 4046.8564224), ]; run_tests(&tests, Metric::SquareMetre); } diff --git a/src/lib.rs b/src/lib.rs index c1ea138..fc977bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str { // Area NonMetric::SquareInch => "square inches", NonMetric::SquareFoot => "square feet", + NonMetric::Acre => "acres", } } @@ -110,5 +111,6 @@ mod test { // Area assert_eq!(run("1 in²"), Ok("6.452 cm²".to_string())); assert_eq!(run("1 ft²"), Ok("929 cm²".to_string())); + assert_eq!(run("1 acre"), Ok("4 047 m²".to_string())); } } diff --git a/src/parse.rs b/src/parse.rs index 045aac0..95e038d 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -110,6 +110,10 @@ fn parse_unit(input: String) -> Result { "feet²" => Ok(NonMetric::SquareFoot), "ft²" => Ok(NonMetric::SquareFoot), + "acre" => Ok(NonMetric::Acre), + "acres" => Ok(NonMetric::Acre), + "ac" => Ok(NonMetric::Acre), + _ => Err(ParseError::UnknownUnit(input)), } } @@ -267,6 +271,10 @@ mod test { assert_eq!(parse_unit("feet²".to_string()), Ok(NonMetric::SquareFoot)); assert_eq!(parse_unit("ft²".to_string()), Ok(NonMetric::SquareFoot)); + assert_eq!(parse_unit("acre".to_string()), Ok(NonMetric::Acre)); + assert_eq!(parse_unit("acres".to_string()), Ok(NonMetric::Acre)); + assert_eq!(parse_unit("ac".to_string()), Ok(NonMetric::Acre)); + // 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 2bab38d..6123c8e 100644 --- a/src/units.rs +++ b/src/units.rs @@ -22,6 +22,7 @@ pub enum NonMetric { // Area SquareInch, SquareFoot, + Acre, } #[derive(Clone, Copy, Debug, PartialEq)]