diff --git a/crates/diman_unit_system/src/codegen/traits.rs b/crates/diman_unit_system/src/codegen/traits.rs index bf9de13..cf8992c 100644 --- a/crates/diman_unit_system/src/codegen/traits.rs +++ b/crates/diman_unit_system/src/codegen/traits.rs @@ -592,6 +592,9 @@ impl Defs { } for t in [Mul, Div] { add_trait!(traits, t, (Quantity, Concrete(ty.clone())), (Storage, Concrete(ty.clone()))); + add_trait!(traits, t, (&Quantity, Concrete(ty.clone())), (Storage, Concrete(ty.clone()))); + add_trait!(traits, t, (Quantity, Concrete(ty.clone())), (&Storage, Concrete(ty.clone()))); + add_trait!(traits, t, (&Quantity, Concrete(ty.clone())), (&Storage, Concrete(ty.clone()))); add_trait!(traits, t, (Storage, Concrete(ty.clone())), (Quantity, Generic)); } for t in [MulAssign, DivAssign] { diff --git a/tests/float/mod.rs b/tests/float/mod.rs index 6fab492..0c3393a 100644 --- a/tests/float/mod.rs +++ b/tests/float/mod.rs @@ -324,14 +324,35 @@ macro_rules! gen_tests_for_float { } #[test] - fn mul_quantity_float() { + fn mul_quantity_typeref() { + let x = Force::newtons(2.0); + let y = &3.0; + assert_is_close(x * y, Force::newtons(6.0)); + } + + #[test] + fn mul_ref_type() { + let x = &Force::newtons(2.0); + let y = 3.0; + assert_is_close(x * y, Force::newtons(6.0)); + } + + #[test] + fn mul_ref_typeref() { + let x = &Force::newtons(2.0); + let y = &3.0; + assert_is_close(x * y, Force::newtons(6.0)); + } + + #[test] + fn mul_quantity_type() { let x = Force::newtons(2.0); let y = 3.0; assert_is_close(x * y, Force::newtons(6.0)); } #[test] - fn mul_assign_quantity_float() { + fn mul_assign_quantity_type() { let mut x = Force::newtons(2.0); let y = 3.0; x *= y; @@ -339,14 +360,14 @@ macro_rules! gen_tests_for_float { } #[test] - fn mul_float_quantity() { + fn mul_type_quantity() { let x = 3.0; let y = Force::newtons(2.0); assert_is_close(x * y, Force::newtons(6.0)); } #[test] - fn mul_assign_float_quantity() { + fn mul_assign_type_quantity() { let mut x = 3.0; let y = Dimensionless::dimensionless(2.0); x *= y; @@ -414,14 +435,35 @@ macro_rules! gen_tests_for_float { } #[test] - fn div_quantity_float() { + fn div_quantity_type() { let x = Length::meters(6.0); let y = 2.0; assert_is_close(x / y, Length::meters(3.0)); } #[test] - fn div_assign_quantity_float() { + fn div_quantity_reftype() { + let x = Length::meters(6.0); + let y = &2.0; + assert_is_close(x / y, Length::meters(3.0)); + } + + #[test] + fn div_ref_type() { + let x = &Length::meters(6.0); + let y = 2.0; + assert_is_close(x / y, Length::meters(3.0)); + } + + #[test] + fn div_ref_reftype() { + let x = &Length::meters(6.0); + let y = &2.0; + assert_is_close(x / y, Length::meters(3.0)); + } + + #[test] + fn div_assign_quantity_type() { let mut x = Length::meters(6.0); let y = 2.0; x /= y; @@ -429,14 +471,14 @@ macro_rules! gen_tests_for_float { } #[test] - fn div_float_quantity() { + fn div_type_quantity() { let x = 2.0; let y = Velocity::meters_per_second(6.0); assert_is_close(x / y, Time::seconds(2.0) / Length::meters(6.0)); } #[test] - fn div_assign_float_quantity() { + fn div_assign_type_quantity() { let mut x = 6.0; let y = Dimensionless::dimensionless(2.0); x /= y;