From 102e619d1acad36de27bd7b48e3d3ae4d9bd0b0b Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 15 May 2023 10:05:46 -0700 Subject: [PATCH] Minor edits --- TODO.md | 1 + src/quantity/unit/mod.rs | 10 +++++++++- src/tests.rs | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index ae47327..a52fe92 100644 --- a/TODO.md +++ b/TODO.md @@ -11,6 +11,7 @@ Roadmap for fixes and features. - Plural unit names - Releases - Unit substitutions + - mpg and gal replacement ## General - CLI Options: version, help, evaluate diff --git a/src/quantity/unit/mod.rs b/src/quantity/unit/mod.rs index 6bf8fd7..3c950c2 100644 --- a/src/quantity/unit/mod.rs +++ b/src/quantity/unit/mod.rs @@ -40,6 +40,7 @@ pub enum UnitBase { Barn, Hectare, MilesPerHour, + MilesPerGallon, Acre, @@ -190,6 +191,7 @@ macro_rules! fromstring_db { // Misc (UnitBase::MilesPerHour, "mph"), + (UnitBase::MilesPerGallon, "mpg"), (UnitBase::Barn, "b"), (UnitBase::Barn, "barn"), (UnitBase::Hectare, "ha"), @@ -459,11 +461,17 @@ macro_rules! unit_db { // Misc UnitBase::MilesPerHour => $X!( UnitBase::MilesPerHour, "mph", - rational, "1609.344", + float, "0.44704", (UnitBase::Meter, 1f64), (UnitBase::Second, -1f64) ), + UnitBase::MilesPerGallon => $X!( + UnitBase::MilesPerGallon, "mpg", + float, "425144", + (UnitBase::Meter, -2f64) + ), + UnitBase::Barn => $X!( UnitBase::Barn, "b", rational, "1e-28", diff --git a/src/tests.rs b/src/tests.rs index 8c24f00..22c7f3b 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -175,7 +175,7 @@ fn operators() { } #[test] -fn units() { +fn basic_units() { //good_expr("4 m*s", "2 m * 2s"); good_expr("1 s⁻¹", "1/s"); good_expr("6 kg", "2 * 3kg"); @@ -194,4 +194,11 @@ fn units() { bad_expr("m + s"); bad_expr("m ^ s"); //bad_expr("m ^ pi"); +} + +#[test] +fn complex_units() { + good_expr("0.62137 mi", "1km to mi"); + good_expr("3.2808 ft", "1km to ft"); + good_expr("62.137 mph", "100 km/h to mph"); } \ No newline at end of file