Add support for cubic yards
This commit is contained in:
parent
8e4680a3bc
commit
e8e81b4564
5 changed files with 38 additions and 0 deletions
|
@ -65,6 +65,7 @@ Supported units
|
||||||
|
|
||||||
* cubic inch (in³)
|
* cubic inch (in³)
|
||||||
* cubic foot (ft³)
|
* cubic foot (ft³)
|
||||||
|
* cubic yard (yd³)
|
||||||
|
|
||||||
### Imperial fluid volume units
|
### Imperial fluid volume units
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
||||||
from: inch_from * inch_from * inch_from,
|
from: inch_from * inch_from * inch_from,
|
||||||
to: MetricQuantity { amount: 12.0 * inch_to * 12.0 * inch_to * 12.0 * inch_to, unit: Metric::CubicMetre },
|
to: MetricQuantity { amount: 12.0 * inch_to * 12.0 * inch_to * 12.0 * inch_to, unit: Metric::CubicMetre },
|
||||||
},
|
},
|
||||||
|
NonMetric::CubicYard => Conversion {
|
||||||
|
offset: 0.0,
|
||||||
|
from: inch_from * inch_from * inch_from,
|
||||||
|
to: MetricQuantity { amount: 3.0 * 12.0 * inch_to * 3.0 * 12.0 * inch_to * 3.0 * 12.0 * inch_to, unit: Metric::CubicMetre },
|
||||||
|
},
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
NonMetric::ImperialFluidOunce => Conversion {
|
NonMetric::ImperialFluidOunce => Conversion {
|
||||||
offset: 0.0,
|
offset: 0.0,
|
||||||
|
@ -240,6 +245,7 @@ mod test {
|
||||||
let tests = [
|
let tests = [
|
||||||
Test(NonMetric::CubicInch, 1.6387064e-5),
|
Test(NonMetric::CubicInch, 1.6387064e-5),
|
||||||
Test(NonMetric::CubicFoot, 0.028316846592),
|
Test(NonMetric::CubicFoot, 0.028316846592),
|
||||||
|
Test(NonMetric::CubicYard, 0.764554857984),
|
||||||
];
|
];
|
||||||
run_tests(&tests, Metric::CubicMetre);
|
run_tests(&tests, Metric::CubicMetre);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
||||||
// Volume
|
// Volume
|
||||||
NonMetric::CubicInch => "cubic inches",
|
NonMetric::CubicInch => "cubic inches",
|
||||||
NonMetric::CubicFoot => "cubic feet",
|
NonMetric::CubicFoot => "cubic feet",
|
||||||
|
NonMetric::CubicYard => "cubic yards",
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
NonMetric::ImperialFluidOunce => "imperial fluid ounces",
|
NonMetric::ImperialFluidOunce => "imperial fluid ounces",
|
||||||
NonMetric::ImperialPint => "imperial pints",
|
NonMetric::ImperialPint => "imperial pints",
|
||||||
|
@ -147,6 +148,7 @@ mod test {
|
||||||
// Volume
|
// Volume
|
||||||
assert_eq!(run("1 in³"), Ok("16.39 cm³".to_string()));
|
assert_eq!(run("1 in³"), Ok("16.39 cm³".to_string()));
|
||||||
assert_eq!(run("1 ft³"), Ok("28 317 cm³".to_string()));
|
assert_eq!(run("1 ft³"), Ok("28 317 cm³".to_string()));
|
||||||
|
assert_eq!(run("1 yd³"), Ok("764 555 cm³".to_string()));
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
assert_eq!(run("1 imp fl oz"), Ok("2.841 cl".to_string()));
|
assert_eq!(run("1 imp fl oz"), Ok("2.841 cl".to_string()));
|
||||||
assert_eq!(run("1 imp pt"), Ok("5.683 dl".to_string()));
|
assert_eq!(run("1 imp pt"), Ok("5.683 dl".to_string()));
|
||||||
|
|
28
src/parse.rs
28
src/parse.rs
|
@ -213,6 +213,19 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
||||||
"feet^3" => Ok(NonMetric::CubicFoot),
|
"feet^3" => Ok(NonMetric::CubicFoot),
|
||||||
"ft^3" => Ok(NonMetric::CubicFoot),
|
"ft^3" => Ok(NonMetric::CubicFoot),
|
||||||
|
|
||||||
|
"cubic yard" => Ok(NonMetric::CubicYard),
|
||||||
|
"cubic yards" => Ok(NonMetric::CubicYard),
|
||||||
|
"cubic yd" => Ok(NonMetric::CubicYard),
|
||||||
|
"cu yard" => Ok(NonMetric::CubicYard),
|
||||||
|
"cu yards" => Ok(NonMetric::CubicYard),
|
||||||
|
"cu yd" => Ok(NonMetric::CubicYard),
|
||||||
|
"yard³" => Ok(NonMetric::CubicYard),
|
||||||
|
"yards³" => Ok(NonMetric::CubicYard),
|
||||||
|
"yd³" => Ok(NonMetric::CubicYard),
|
||||||
|
"yard^3" => Ok(NonMetric::CubicYard),
|
||||||
|
"yards^3" => Ok(NonMetric::CubicYard),
|
||||||
|
"yd^3" => Ok(NonMetric::CubicYard),
|
||||||
|
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
"imperial fluid ounce" => Ok(NonMetric::ImperialFluidOunce),
|
"imperial fluid ounce" => Ok(NonMetric::ImperialFluidOunce),
|
||||||
"imperial fluid ounces" => Ok(NonMetric::ImperialFluidOunce),
|
"imperial fluid ounces" => Ok(NonMetric::ImperialFluidOunce),
|
||||||
|
@ -630,6 +643,21 @@ mod test {
|
||||||
"ft^3",
|
"ft^3",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
test_units(NonMetric::CubicYard, &[
|
||||||
|
"cubic yard",
|
||||||
|
"cubic yards",
|
||||||
|
"cubic yd",
|
||||||
|
"cu yard",
|
||||||
|
"cu yards",
|
||||||
|
"cu yd",
|
||||||
|
"yard³",
|
||||||
|
"yards³",
|
||||||
|
"yd³",
|
||||||
|
"yard^3",
|
||||||
|
"yards^3",
|
||||||
|
"yd^3",
|
||||||
|
]);
|
||||||
|
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
test_units(NonMetric::ImperialFluidOunce, &[
|
test_units(NonMetric::ImperialFluidOunce, &[
|
||||||
"imperial fluid ounce",
|
"imperial fluid ounce",
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub enum NonMetric {
|
||||||
// Volume
|
// Volume
|
||||||
CubicInch,
|
CubicInch,
|
||||||
CubicFoot,
|
CubicFoot,
|
||||||
|
CubicYard,
|
||||||
// Fluid volume
|
// Fluid volume
|
||||||
ImperialFluidOunce,
|
ImperialFluidOunce,
|
||||||
ImperialPint,
|
ImperialPint,
|
||||||
|
|
Loading…
Reference in a new issue