From 682ac4be71bad60023028505f124e5b39c9739e7 Mon Sep 17 00:00:00 2001 From: Vlad Voronenkov Date: Wed, 3 Aug 2022 15:55:28 +0200 Subject: [PATCH] Add action quantity with corresponding units and tests. --- src/si/action.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ src/si/mod.rs | 1 + 2 files changed, 59 insertions(+) create mode 100644 src/si/action.rs diff --git a/src/si/action.rs b/src/si/action.rs new file mode 100644 index 00000000..d08c5fbf --- /dev/null +++ b/src/si/action.rs @@ -0,0 +1,58 @@ +//! Action (base unit joule second, kg ⋅ m² ⋅ s⁻¹). + +quantity! { + /// Action (base unit joule second, kg ⋅ m² ⋅ s⁻¹). + quantity: Action; "action"; + /// Dimension of action, L²MT⁻¹ (base unit joule second, kg ⋅ m² ⋅ s⁻¹). + dimension: ISQ< + P2, // length + P1, // mass + N1, // time + Z0, // electric current + Z0, // thermodynamic temperature + Z0, // amount of substance + Z0>; // luminous intensity + units { + @joule_second: prefix!(none); "J · s", "joule second", "joule seconds"; + + /// Reduced Planck constant ħ. + @atomic_unit_of_action: 1.054_571_817_E-34; "ħ", "atomic unit of action", + "atomic units of action"; + @reduced_planck_constant: 1.054_571_817_E-34; "ħ", "reduced planck constant", + "reduced planck constants"; + @planck_constant: 6.626_070_15_E-34; "h", "planck constant", "planck constants"; + @erg_second: 1.0_E-7; "erg · s", "erg second", "erg seconds"; + @electronvolt_second: 1.602_176_634_E-19; "eV · s", "electronvolt second", + "electronvolt seconds"; + } +} + +#[cfg(test)] +mod test { + storage_types! { + use crate::num::One; + use crate::si::quantities::*; + use crate::si::time as t; + use crate::si::energy as e; + use crate::si::action as act; + use crate::tests::Test; + + #[test] + fn check_dimension() { + let _: Action = Energy::new::(V::one()) + * Time::new::(V::one()); + } + + #[test] + fn check_units() { + test::(); + test::(); + test::(); + + fn test, T: t::Conversion, ACT: act::Conversion>() { + Test::assert_approx_eq(&Action::new::(V::one()), + &(Energy::new::(V::one()) * Time::new::(V::one()))); + } + } + } +} diff --git a/src/si/mod.rs b/src/si/mod.rs index 9e7d9ff0..24a38df8 100644 --- a/src/si/mod.rs +++ b/src/si/mod.rs @@ -47,6 +47,7 @@ system! { units: SI { absement::Absement, acceleration::Acceleration, + action::Action, amount_of_substance::AmountOfSubstance, angle::Angle, angular_acceleration::AngularAcceleration,