use crate::{duration::Duration, energy::Energy, prelude::*};
#[quantity(Energy / Duration)]
#[ref_unit(Watt, "W", NONE, "Reference unit of quantity `Power`")]
#[unit(Milliwatt, "mW", MILLI, 0.001, "0.001·W")]
#[unit(Kilowatt, "kW", KILO, 1000, "1000·W")]
#[unit(Megawatt, "MW", MEGA, 1000000, "1000000·W")]
#[unit(Gigawatt, "GW", GIGA, 1000000000, "1000000000·W")]
#[unit(Terawatt, "TW", TERA, 1000000000000., "1000000000000·W")]
pub struct Power {}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
assert_almost_eq,
duration::{HOUR, MINUTE},
energy::KILOWATT_HOUR,
};
#[test]
fn test_energy_div_duration() {
let ae: AmountT = Amnt!(90.3);
let e = ae * KILOWATT_HOUR;
let at: AmountT = Amnt!(30.);
let t = at * MINUTE;
let p = e / t;
assert_almost_eq!(p.amount(), ae / at * Amnt!(60.));
assert_eq!(p.unit(), KILOWATT);
}
#[test]
fn test_energy_div_power() {
let ae: AmountT = Amnt!(90.3);
let e = ae * KILOWATT_HOUR;
let ap: AmountT = Amnt!(4.2);
let p = ap * KILOWATT;
let t = e / p;
assert_almost_eq!(t.amount(), ae / ap);
assert_eq!(t.unit(), HOUR);
}
}