Add support for acres
This commit is contained in:
parent
85c5c9d66f
commit
7a7959c172
|
@ -75,6 +75,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
||||||
from: inch_from * inch_from,
|
from: inch_from * inch_from,
|
||||||
to: MetricQuantity { amount: 12.0 * inch_to * 12.0 * inch_to, unit: Metric::SquareMetre },
|
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 = [
|
let tests = [
|
||||||
Test(NonMetric::SquareInch, 0.00064516),
|
Test(NonMetric::SquareInch, 0.00064516),
|
||||||
Test(NonMetric::SquareFoot, 0.09290304),
|
Test(NonMetric::SquareFoot, 0.09290304),
|
||||||
|
Test(NonMetric::Acre, 4046.8564224),
|
||||||
];
|
];
|
||||||
run_tests(&tests, Metric::SquareMetre);
|
run_tests(&tests, Metric::SquareMetre);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
||||||
// Area
|
// Area
|
||||||
NonMetric::SquareInch => "square inches",
|
NonMetric::SquareInch => "square inches",
|
||||||
NonMetric::SquareFoot => "square feet",
|
NonMetric::SquareFoot => "square feet",
|
||||||
|
NonMetric::Acre => "acres",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,5 +111,6 @@ mod test {
|
||||||
// Area
|
// Area
|
||||||
assert_eq!(run("1 in²"), Ok("6.452 cm²".to_string()));
|
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 ft²"), Ok("929 cm²".to_string()));
|
||||||
|
assert_eq!(run("1 acre"), Ok("4 047 m²".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,10 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
||||||
"feet²" => Ok(NonMetric::SquareFoot),
|
"feet²" => Ok(NonMetric::SquareFoot),
|
||||||
"ft²" => Ok(NonMetric::SquareFoot),
|
"ft²" => Ok(NonMetric::SquareFoot),
|
||||||
|
|
||||||
|
"acre" => Ok(NonMetric::Acre),
|
||||||
|
"acres" => Ok(NonMetric::Acre),
|
||||||
|
"ac" => Ok(NonMetric::Acre),
|
||||||
|
|
||||||
_ => Err(ParseError::UnknownUnit(input)),
|
_ => Err(ParseError::UnknownUnit(input)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,6 +271,10 @@ mod test {
|
||||||
assert_eq!(parse_unit("feet²".to_string()), Ok(NonMetric::SquareFoot));
|
assert_eq!(parse_unit("feet²".to_string()), Ok(NonMetric::SquareFoot));
|
||||||
assert_eq!(parse_unit("ft²".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
|
// 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())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub enum NonMetric {
|
||||||
// Area
|
// Area
|
||||||
SquareInch,
|
SquareInch,
|
||||||
SquareFoot,
|
SquareFoot,
|
||||||
|
Acre,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue