Minor edits

pull/2/head
Mark 2023-05-15 10:05:46 -07:00
parent 356a3c7824
commit 102e619d1a
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 18 additions and 2 deletions

View File

@ -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

View File

@ -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",

View File

@ -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");
@ -195,3 +195,10 @@ fn units() {
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");
}