Skip to content

Commit

Permalink
Additional tests for vec3/vec4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri committed Aug 15, 2024
1 parent 1b5563d commit baee4fd
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tests/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,42 @@ macro_rules! impl_vec2_tests {
glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
assert_eq!($new(3 as $t, 4 as $t), a);
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
assert_eq!($new(1 as $t, 2 as $t), a);
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
assert_eq!($new(2 as $t, 4 as $t), a);
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
assert_eq!($new(1 as $t, 2 as $t), a);
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
assert_eq!($new(1 as $t, 0 as $t), a);
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
assert_eq!($new(2 as $t, 4 as $t), a);
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
assert_eq!($new(1 as $t, 2 as $t), a);
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
assert_eq!($new(1 as $t, 4 as $t), a);
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
assert_eq!($new(1 as $t, 2 as $t), a);
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
assert_eq!($new(0 as $t, 0 as $t), a);
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
Expand Down
102 changes: 102 additions & 0 deletions tests/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,62 @@ macro_rules! impl_vec3_tests {
assert_eq!($new(2 as $t, 4 as $t, 0 as $t), a % 8 as $t);
});

glam_test!(test_ops_propagated, {
let vec = $new(2 as $t, 4 as $t, 8 as $t);
let scalar = 2 as $t;
let g_scalar = 16 as $t;

assert_eq!((vec + vec), (vec + &vec));
assert_eq!((vec + vec), (&vec + vec));
assert_eq!((vec + vec), (&vec + &vec));
assert_eq!((vec + scalar), (vec + &scalar));
assert_eq!((vec + scalar), (&vec + &scalar));
assert_eq!((vec + scalar), (&vec + scalar));
assert_eq!((scalar + vec), (&scalar + vec));
assert_eq!((scalar + vec), (&scalar + &vec));
assert_eq!((scalar + vec), (scalar + &vec));

assert_eq!((vec - vec), (vec - &vec));
assert_eq!((vec - vec), (&vec - vec));
assert_eq!((vec - vec), (&vec - &vec));
assert_eq!((vec - scalar), (vec - &scalar));
assert_eq!((vec - scalar), (&vec - &scalar));
assert_eq!((vec - scalar), (&vec - scalar));
assert_eq!((g_scalar - vec), (&g_scalar - vec));
assert_eq!((g_scalar - vec), (&g_scalar - &vec));
assert_eq!((g_scalar - vec), (g_scalar - &vec));

assert_eq!((vec * vec), (vec * &vec));
assert_eq!((vec * vec), (&vec * vec));
assert_eq!((vec * vec), (&vec * &vec));
assert_eq!((vec * scalar), (vec * &scalar));
assert_eq!((vec * scalar), (&vec * &scalar));
assert_eq!((vec * scalar), (&vec * scalar));
assert_eq!((scalar * vec), (&scalar * vec));
assert_eq!((scalar * vec), (&scalar * &vec));
assert_eq!((scalar * vec), (scalar * &vec));

assert_eq!((vec / vec), (vec / &vec));
assert_eq!((vec / vec), (&vec / vec));
assert_eq!((vec / vec), (&vec / &vec));
assert_eq!((vec / scalar), (vec / &scalar));
assert_eq!((vec / scalar), (&vec / &scalar));
assert_eq!((vec / scalar), (&vec / scalar));
assert_eq!((scalar / vec), (&scalar / vec));
assert_eq!((scalar / vec), (&scalar / &vec));
assert_eq!((scalar / vec), (scalar / &vec));

assert_eq!((vec % vec), (vec % &vec));
assert_eq!((vec % vec), (&vec % vec));
assert_eq!((vec % vec), (&vec % &vec));
assert_eq!((vec % scalar), (vec % &scalar));
assert_eq!((vec % scalar), (&vec % &scalar));
assert_eq!((vec % scalar), (&vec % scalar));
assert_eq!((scalar % vec), (&scalar % vec));
assert_eq!((scalar % vec), (&scalar % &vec));
assert_eq!((scalar % vec), (scalar % &vec));
});

glam_test!(test_assign_ops, {
let a = $new(1 as $t, 2 as $t, 3 as $t);
let mut b = a;
Expand Down Expand Up @@ -223,6 +279,47 @@ macro_rules! impl_vec3_tests {
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), b);
});

glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t, 3 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
let a = $new(3 as $t, 5 as $t, 1 as $t);
let b = $new(4 as $t, 2 as $t, 6 as $t);
Expand Down Expand Up @@ -656,6 +753,11 @@ macro_rules! impl_vec3_signed_tests {
);
});

glam_test!(test_neg_propagation, {
let a = $new(1 as $t, 2 as $t, 3 as $t);
assert_eq!(-a, -(&a));
});

glam_test!(test_is_negative_bitmask, {
assert_eq!($vec3::ZERO.is_negative_bitmask(), 0b000);
assert_eq!($vec3::ONE.is_negative_bitmask(), 0b000);
Expand Down
102 changes: 102 additions & 0 deletions tests/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,62 @@ macro_rules! impl_vec4_tests {
assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 0 as $t), a % 8 as $t);
});

glam_test!(test_ops_propagated, {
let vec = $new(2 as $t, 4 as $t, 8 as $t, 16 as $t);
let scalar = 2 as $t;
let g_scalar = 16 as $t;

assert_eq!((vec + vec), (vec + &vec));
assert_eq!((vec + vec), (&vec + vec));
assert_eq!((vec + vec), (&vec + &vec));
assert_eq!((vec + scalar), (vec + &scalar));
assert_eq!((vec + scalar), (&vec + &scalar));
assert_eq!((vec + scalar), (&vec + scalar));
assert_eq!((scalar + vec), (&scalar + vec));
assert_eq!((scalar + vec), (&scalar + &vec));
assert_eq!((scalar + vec), (scalar + &vec));

assert_eq!((vec - vec), (vec - &vec));
assert_eq!((vec - vec), (&vec - vec));
assert_eq!((vec - vec), (&vec - &vec));
assert_eq!((vec - scalar), (vec - &scalar));
assert_eq!((vec - scalar), (&vec - &scalar));
assert_eq!((vec - scalar), (&vec - scalar));
assert_eq!((g_scalar - vec), (&g_scalar - vec));
assert_eq!((g_scalar - vec), (&g_scalar - &vec));
assert_eq!((g_scalar - vec), (g_scalar - &vec));

assert_eq!((vec * vec), (vec * &vec));
assert_eq!((vec * vec), (&vec * vec));
assert_eq!((vec * vec), (&vec * &vec));
assert_eq!((vec * scalar), (vec * &scalar));
assert_eq!((vec * scalar), (&vec * &scalar));
assert_eq!((vec * scalar), (&vec * scalar));
assert_eq!((scalar * vec), (&scalar * vec));
assert_eq!((scalar * vec), (&scalar * &vec));
assert_eq!((scalar * vec), (scalar * &vec));

assert_eq!((vec / vec), (vec / &vec));
assert_eq!((vec / vec), (&vec / vec));
assert_eq!((vec / vec), (&vec / &vec));
assert_eq!((vec / scalar), (vec / &scalar));
assert_eq!((vec / scalar), (&vec / &scalar));
assert_eq!((vec / scalar), (&vec / scalar));
assert_eq!((scalar / vec), (&scalar / vec));
assert_eq!((scalar / vec), (&scalar / &vec));
assert_eq!((scalar / vec), (scalar / &vec));

assert_eq!((vec % vec), (vec % &vec));
assert_eq!((vec % vec), (&vec % vec));
assert_eq!((vec % vec), (&vec % &vec));
assert_eq!((vec % scalar), (vec % &scalar));
assert_eq!((vec % scalar), (&vec % &scalar));
assert_eq!((vec % scalar), (&vec % scalar));
assert_eq!((scalar % vec), (&scalar % vec));
assert_eq!((scalar % vec), (&scalar % &vec));
assert_eq!((scalar % vec), (scalar % &vec));
});

glam_test!(test_assign_ops, {
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
let mut b = a;
Expand Down Expand Up @@ -273,6 +329,47 @@ macro_rules! impl_vec4_tests {
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b);
});

glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t);
let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t);
Expand Down Expand Up @@ -772,6 +869,11 @@ macro_rules! impl_vec4_signed_tests {
);
});

glam_test!(test_neg_propagation, {
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
assert_eq!(-a, -(&a));
});

glam_test!(test_is_negative_bitmask, {
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000);
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000);
Expand Down

0 comments on commit baee4fd

Please sign in to comment.