use num_traits::Inv; use dana::{prelude::*, symbols::{electrical::*, physics::*}}; #[test] fn test_anonymous() { use dana::quantity::QuantityAnon; let l: QuantityAnon<_> = qty![72.0 km as ?]; let t: QuantityAnon<_> = qty![4.0 h as ?]; assert_eq!(qty![ 5.0 m/s ], l / t); assert_eq!(qty![ 5.0 m/s ], l * t.inv()); assert_eq!(qty![36.0 km ], l / t * qty![120.0 min]); assert_eq!(qty![ 0.5 m/s^2], l / t / qty![ 10.0 s ]); let width: QuantityAnon<_> = qty![40.0 cm as ?]; let height: QuantityAnon<_> = qty![ 1.5 m as ?]; let area_base = width.squared(); let volume_post = height * area_base; assert!(qty![0.16 m^2].almost_eq(area_base, 1e-10)); assert!(qty![0.24 m^3].almost_eq(volume_post, 1e-10)); // assert_ne!(qty![2.0 m], qty![2.0 m^0 as ?]); assert_eq!(qty![2.0 m], qty![2.0 m^1 as ?]); assert_eq!(qty![2.0 m], qty![4.0 m^2 as ?].sqrt()); assert_eq!(qty![2.0 m], qty![8.0 m^3 as ?].cbrt()); } #[test] fn test_f_ma() { let mass: Quantity = qty![2.0 kg]; let accel: Quantity = qty![3.0 km/s/s]; let force: Quantity = qty![(mass * accel) as _]; assert_eq!(qty![*force in kN], 6.0); } #[test] fn test_electrical() { // 3V3 across a 7g 150Ω resistor. let v: Quantity = qty![3.3 V]; let r: Quantity = qty![150.0 Ω]; let c: Quantity = qty![[1.0 J/K/g] * [7.0 g] in J/K]; // Should measure 22mA of current through the resistor. let i: Quantity = qty![(v / r) in A]; assert_eq!(qty![*i in mA], 22.0); // Resistor should be dissipating 72.6mW as heat. let p: Quantity = qty![(i * v) in W]; assert_eq!(qty![*p in mW], 72.6); // After 5 minutes, should have dissipated 21.78J in total. let t: Quantity