Add support for square feet
This commit is contained in:
parent
7eb31b1b4b
commit
85c5c9d66f
|
@ -70,6 +70,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
||||||
from: inch_from * inch_from,
|
from: inch_from * inch_from,
|
||||||
to: MetricQuantity { amount: inch_to * inch_to, unit: Metric::SquareMetre },
|
to: MetricQuantity { amount: inch_to * inch_to, unit: Metric::SquareMetre },
|
||||||
},
|
},
|
||||||
|
NonMetric::SquareFoot => Conversion {
|
||||||
|
offset: 0.0,
|
||||||
|
from: inch_from * inch_from,
|
||||||
|
to: MetricQuantity { amount: 12.0 * inch_to * 12.0 * inch_to, unit: Metric::SquareMetre },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +127,7 @@ mod test {
|
||||||
fn area() {
|
fn area() {
|
||||||
let tests = [
|
let tests = [
|
||||||
Test(NonMetric::SquareInch, 0.00064516),
|
Test(NonMetric::SquareInch, 0.00064516),
|
||||||
|
Test(NonMetric::SquareFoot, 0.09290304),
|
||||||
];
|
];
|
||||||
run_tests(&tests, Metric::SquareMetre);
|
run_tests(&tests, Metric::SquareMetre);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
||||||
NonMetric::Fahrenheit => "degrees Fahrenheit",
|
NonMetric::Fahrenheit => "degrees Fahrenheit",
|
||||||
// Area
|
// Area
|
||||||
NonMetric::SquareInch => "square inches",
|
NonMetric::SquareInch => "square inches",
|
||||||
|
NonMetric::SquareFoot => "square feet",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,5 +109,6 @@ mod test {
|
||||||
assert_eq!(run("32 °F"), Ok("0 °C".to_string()));
|
assert_eq!(run("32 °F"), Ok("0 °C".to_string()));
|
||||||
// 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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,10 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
||||||
"inches²" => Ok(NonMetric::SquareInch),
|
"inches²" => Ok(NonMetric::SquareInch),
|
||||||
"in²" => Ok(NonMetric::SquareInch),
|
"in²" => Ok(NonMetric::SquareInch),
|
||||||
|
|
||||||
|
"foot²" => Ok(NonMetric::SquareFoot),
|
||||||
|
"feet²" => Ok(NonMetric::SquareFoot),
|
||||||
|
"ft²" => Ok(NonMetric::SquareFoot),
|
||||||
|
|
||||||
_ => Err(ParseError::UnknownUnit(input)),
|
_ => Err(ParseError::UnknownUnit(input)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,6 +263,10 @@ mod test {
|
||||||
assert_eq!(parse_unit("inches²".to_string()), Ok(NonMetric::SquareInch));
|
assert_eq!(parse_unit("inches²".to_string()), Ok(NonMetric::SquareInch));
|
||||||
assert_eq!(parse_unit("in²".to_string()), Ok(NonMetric::SquareInch));
|
assert_eq!(parse_unit("in²".to_string()), Ok(NonMetric::SquareInch));
|
||||||
|
|
||||||
|
assert_eq!(parse_unit("foot²".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));
|
||||||
|
|
||||||
// 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())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub enum NonMetric {
|
||||||
Fahrenheit,
|
Fahrenheit,
|
||||||
// Area
|
// Area
|
||||||
SquareInch,
|
SquareInch,
|
||||||
|
SquareFoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue