From 08f9e3c1048023387c97bd7b26189feb24c0bafa Mon Sep 17 00:00:00 2001 From: Alex Hamilton Date: Thu, 21 Mar 2019 13:45:53 -0500 Subject: [PATCH] Add liter-based volume units to si. --- src/si/volume.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/si/volume.rs b/src/si/volume.rs index 1899bf4e..8294fd9b 100644 --- a/src/si/volume.rs +++ b/src/si/volume.rs @@ -70,7 +70,27 @@ quantity! { @gallon: 3.785_412_E-3; "gal", "gallon", "gallons"; @gill_imperial: 1.420_653_E-4; "gi (UK)", "Imperial gill", "Imperial gills"; @gill: 1.182_941_E-4; "gi", "gill", "gills"; - @liter: 1.0_E-3; "L", "liter", "liters"; + @yottaliter: prefix!(milli) * prefix!(yotta); "YL", "yottaliter", "yottaliters"; + @zettaliter: prefix!(milli) * prefix!(zetta); "ZL", "zettaliter", "zettaliters"; + @exaliter: prefix!(milli) * prefix!(exa); "EL", "exaliter", "exaliters"; + @petaliter: prefix!(milli) * prefix!(peta); "PL", "petaliter", "petaliters"; + @teraliter: prefix!(milli) * prefix!(tera); "TL", "teraliter", "teraliters"; + @gigaliter: prefix!(milli) * prefix!(giga); "GL", "gigaliter", "gigaliters"; + @megaliter: prefix!(milli) * prefix!(mega); "ML", "megaliter", "megaliters"; + @kiloliter: prefix!(milli) * prefix!(kilo); "kL", "kiloliter", "kiloliters"; + @hectoliter: prefix!(milli) * prefix!(hecto); "hL", "hectoliter", "hectoliters"; + @decaliter: prefix!(milli) * prefix!(deca); "daL", "decaliter", "decaliters"; + @liter: prefix!(milli); "L", "liter", "liters"; + @deciliter: prefix!(milli) * prefix!(deci); "dL", "deciliter", "deciliters"; + @centiliter: prefix!(milli) * prefix!(centi); "cL", "centiliter", "centiliters"; + @milliliter: prefix!(milli) * prefix!(milli); "mL", "milliliter", "milliliters"; + @microliter: prefix!(milli) * prefix!(micro); "µL", "microliter", "microliters"; + @nanoliter: prefix!(milli) * prefix!(nano); "nL", "nanoliter", "nanoliters"; + @picoliter: prefix!(milli) * prefix!(pico); "pL", "picoliter", "picoliters"; + @femtoliter: prefix!(milli) * prefix!(femto); "fL", "femtoliter", "femtoliters"; + @attoliter: prefix!(milli) * prefix!(atto); "aL", "attoliter", "attoliters"; + @zeptoliter: prefix!(milli) * prefix!(zepto); "zL", "zeptoliter", "zeptoliters"; + @yoctoliter: prefix!(milli) * prefix!(yocto); "yL", "yoctoliter", "yoctoliters"; @peck: 8.809_768_E-3; "pk", "peck", "pecks"; @pint_dry: 5.506_105_E-4; "dry pt", "dry pint", "dry pints"; @pint_liquid: 4.731_765_E-4; "liq pt", "liquid pint", "liquid pints"; @@ -103,6 +123,39 @@ mod tests { * Area::new::(V::one()); } + #[test] + fn check_liters() { + // Test liter base relative to cubic meter base to verify a baseline + test::(prefix!(milli)); + // Test relative to liter to make sure prefixes are good + // This transitively verifies the other relations + test::(prefix!(yotta)); + test::(prefix!(zetta)); + test::(prefix!(exa)); + test::(prefix!(peta)); + test::(prefix!(tera)); + test::(prefix!(giga)); + test::(prefix!(mega)); + test::(prefix!(kilo)); + test::(prefix!(hecto)); + test::(prefix!(deca)); + test::(V::one()); + test::(prefix!(deci)); + test::(prefix!(centi)); + test::(prefix!(milli)); + test::(prefix!(micro)); + test::(prefix!(nano)); + test::(prefix!(pico)); + test::(prefix!(femto)); + test::(prefix!(atto)); + test::(prefix!(zepto)); + test::(prefix!(yocto)); + + fn test, U: v::Conversion>(ratio: V) { + Test::assert_eq(&Volume::new::(V::one()), &Volume::new::(ratio)) + } + } + #[test] fn check_units() { // Values too large for f32.