Simplify conversions::test::{length, mass, area, volume, fluid_volume}

This commit is contained in:
Juhani Krekelä 2023-06-01 19:48:12 +03:00
parent 254ac20186
commit 7191d5a378
1 changed files with 11 additions and 16 deletions

View File

@ -189,25 +189,23 @@ mod test {
#[test] #[test]
fn length() { fn length() {
let tests = [ run_tests(Metric::Metre, &[
Test(NonMetric::Inch, 0.0254), Test(NonMetric::Inch, 0.0254),
Test(NonMetric::Foot, 0.3048), Test(NonMetric::Foot, 0.3048),
Test(NonMetric::Yard, 0.9144), Test(NonMetric::Yard, 0.9144),
Test(NonMetric::Mile, 1609.344), Test(NonMetric::Mile, 1609.344),
]; ]);
run_tests(&tests, Metric::Metre);
} }
#[test] #[test]
fn mass() { fn mass() {
let tests = [ run_tests(Metric::Gram, &[
Test(NonMetric::Ounce, 28.349523125), Test(NonMetric::Ounce, 28.349523125),
Test(NonMetric::Pound, 453.59237), Test(NonMetric::Pound, 453.59237),
Test(NonMetric::Stone, 6350.29318), Test(NonMetric::Stone, 6350.29318),
Test(NonMetric::ShortTon, 907184.74), Test(NonMetric::ShortTon, 907184.74),
Test(NonMetric::LongTon, 1016046.9088), Test(NonMetric::LongTon, 1016046.9088),
]; ]);
run_tests(&tests, Metric::Gram);
} }
#[test] #[test]
@ -230,29 +228,27 @@ mod test {
#[test] #[test]
fn area() { fn area() {
let tests = [ run_tests(Metric::SquareMetre, &[
Test(NonMetric::SquareInch, 0.00064516), Test(NonMetric::SquareInch, 0.00064516),
Test(NonMetric::SquareFoot, 0.09290304), Test(NonMetric::SquareFoot, 0.09290304),
Test(NonMetric::SquareYard, 0.83612736), Test(NonMetric::SquareYard, 0.83612736),
Test(NonMetric::Acre, 4046.8564224), Test(NonMetric::Acre, 4046.8564224),
Test(NonMetric::SquareMile, 2589988.110336), Test(NonMetric::SquareMile, 2589988.110336),
]; ]);
run_tests(&tests, Metric::SquareMetre);
} }
#[test] #[test]
fn volume() { fn volume() {
let tests = [ run_tests(Metric::CubicMetre, &[
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), Test(NonMetric::CubicYard, 0.764554857984),
]; ]);
run_tests(&tests, Metric::CubicMetre);
} }
#[test] #[test]
fn fluid_volume() { fn fluid_volume() {
let tests = [ run_tests(Metric::Litre, &[
Test(NonMetric::ImperialFluidOunce, 0.0284130625), Test(NonMetric::ImperialFluidOunce, 0.0284130625),
Test(NonMetric::ImperialPint, 0.56826125), Test(NonMetric::ImperialPint, 0.56826125),
Test(NonMetric::ImperialQuart, 1.1365225), Test(NonMetric::ImperialQuart, 1.1365225),
@ -264,11 +260,10 @@ mod test {
Test(NonMetric::USLiquidPint, 0.473176473), Test(NonMetric::USLiquidPint, 0.473176473),
Test(NonMetric::USLiquidQuart, 0.946352946), Test(NonMetric::USLiquidQuart, 0.946352946),
Test(NonMetric::USGallon, 3.785411784), Test(NonMetric::USGallon, 3.785411784),
]; ]);
run_tests(&tests, Metric::Litre);
} }
fn run_tests(tests: &[Test], unit: Metric) { fn run_tests(unit: Metric, tests: &[Test]) {
for test in tests { for test in tests {
let from = NonMetricQuantity { let from = NonMetricQuantity {
amount: 1.0, amount: 1.0,