Skip to content

Commit

Permalink
Add Mul/Div for &Quantity <-> Storage, Quantity <-> &Storage and &Qua…
Browse files Browse the repository at this point in the history
…ntity <-> &Storage
  • Loading branch information
Tehforsch committed Jan 7, 2024
1 parent e2cb4e3 commit 93b05c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crates/diman_unit_system/src/codegen/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
58 changes: 50 additions & 8 deletions tests/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,50 @@ 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;
assert_is_close(x, Force::newtons(6.0));
}

#[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;
Expand Down Expand Up @@ -414,29 +435,50 @@ 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;
assert_is_close(x, Length::meters(3.0));
}

#[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;
Expand Down

0 comments on commit 93b05c1

Please sign in to comment.