Added units of voltage

This commit is contained in:
Kasper 2020-11-21 02:47:31 +01:00
parent f03850f006
commit 6553c50d1d
3 changed files with 19 additions and 0 deletions

View File

@ -1,3 +1,9 @@
## Next
- Added units of electric current
- Added units of voltage
- Added units of resistance
- Fixed interpreting of `µs`
## 1.1.0 - 2020 Nov 14 ## 1.1.0 - 2020 Nov 14
- Added units of frequency - Added units of frequency
- Added support using foot-inch syntax with addition, like `2"+6'4"` - Added support using foot-inch syntax with addition, like `2"+6'4"`

View File

@ -336,6 +336,10 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
"Ω" | "" | "ohm" | "ohms" => tokens.push(Token::Unit(Ohm)), "Ω" | "" | "ohm" | "ohms" => tokens.push(Token::Unit(Ohm)),
"" | "kΩ" | "kiloohm" | "kiloohms" => tokens.push(Token::Unit(Kiloohm)), "" | "kΩ" | "kiloohm" | "kiloohms" => tokens.push(Token::Unit(Kiloohm)),
"mv" | "millivolt" | "millivolts" => tokens.push(Token::Unit(Millivolt)),
"v" | "volt" | "volts" => tokens.push(Token::Unit(Volt)),
"kv" | "kilovolt" | "kilovolts" => tokens.push(Token::Unit(Kilovolt)),
// for pound-force per square inch // for pound-force per square inch
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)), "lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
"force" => tokens.push(Token::LexerKeyword(Force)), "force" => tokens.push(Token::LexerKeyword(Force)),

View File

@ -27,6 +27,8 @@ pub enum UnitType {
ElectricCurrent, ElectricCurrent,
/// A unit of electric resistance, for example `Ohm` /// A unit of electric resistance, for example `Ohm`
Resistance, Resistance,
/// A unit of voltage, for example `Volt`
Voltage,
/// A unit of pressure, for example `Bar` /// A unit of pressure, for example `Bar`
Pressure, Pressure,
/// A unit of frequency, for example `Hertz` /// A unit of frequency, for example `Hertz`
@ -222,6 +224,10 @@ create_units!(
Ohm: (Resistance, d128!(1000)), Ohm: (Resistance, d128!(1000)),
Kiloohm: (Resistance, d128!(1000000)), Kiloohm: (Resistance, d128!(1000000)),
Millivolt: (Voltage, d128!(1)),
Volt: (Voltage, d128!(1000)),
Kilovolt: (Voltage, d128!(1000000)),
Pascal: (Pressure, d128!(1)), Pascal: (Pressure, d128!(1)),
Kilopascal: (Pressure, d128!(1000)), Kilopascal: (Pressure, d128!(1000)),
Atmosphere: (Pressure, d128!(101325)), Atmosphere: (Pressure, d128!(101325)),
@ -684,6 +690,9 @@ mod tests {
assert_eq!(convert_test(1000.0, Milliohm, Ohm), 1.0); assert_eq!(convert_test(1000.0, Milliohm, Ohm), 1.0);
assert_eq!(convert_test(1000.0, Ohm, Kiloohm), 1.0); assert_eq!(convert_test(1000.0, Ohm, Kiloohm), 1.0);
assert_eq!(convert_test(1000.0, Millivolt, Volt), 1.0);
assert_eq!(convert_test(1000.0, Volt, Kilovolt), 1.0);
assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0); assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0);
assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0); assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0);
assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0); assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0);