Skip to content

Commit

Permalink
add tests for checked_manhattan_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
tguichaoua committed Dec 22, 2024
1 parent c72224e commit d438ee8
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,25 @@ macro_rules! impl_vec2_signed_integer_tests {
$vec2::new(-8, -23).manhattan_distance($vec2::new(12, 7)),
50
);

assert_eq!(
$vec2::new(5, 2).checked_manhattan_distance($vec2::new(23, 16)),
Some(32)
);
assert_eq!(
$vec2::new(30, 11).checked_manhattan_distance($vec2::new(30, 11)),
Some(0)
);
assert_eq!(
$vec2::new(-8, -23).checked_manhattan_distance($vec2::new(12, 7)),
Some(50)
);

assert_eq!(
$vec2::new($t::MIN, $t::MIN)
.checked_manhattan_distance($vec2::new($t::MAX, $t::MAX)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand All @@ -762,6 +781,21 @@ macro_rules! impl_vec2_unsigned_integer_tests {
glam_test!(test_manhattan_distance, {
assert_eq!($vec2::new(5, 2).manhattan_distance($vec2::new(23, 16)), 32);
assert_eq!($vec2::new(30, 11).manhattan_distance($vec2::new(30, 11)), 0);

assert_eq!(
$vec2::new(5, 2).checked_manhattan_distance($vec2::new(23, 16)),
Some(32)
);
assert_eq!(
$vec2::new(30, 11).checked_manhattan_distance($vec2::new(30, 11)),
Some(0)
);

assert_eq!(
$vec2::new($t::MIN, $t::MIN)
.checked_manhattan_distance($vec2::new($t::MAX, $t::MAX)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand Down
40 changes: 40 additions & 0 deletions tests/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,28 @@ macro_rules! impl_vec3_signed_integer_tests {
$vec3::new(-23, 2, -99).manhattan_distance($vec3::new(22, -12, 24)),
182
);

assert_eq!(
$vec3::new(3, 27, 98).checked_manhattan_distance($vec3::new(20, 65, 97)),
Some(56)
);
assert_eq!(
$vec3::new(8, 12, 12).checked_manhattan_distance($vec3::new(24, 56, 2)),
Some(70)
);
assert_eq!(
$vec3::new(-23, 2, -99).checked_manhattan_distance($vec3::new(22, -12, 24)),
Some(182)
);

assert_eq!(
$vec3::new($t::MIN, $t::MIN, $t::MIN).checked_manhattan_distance($vec3::new(
$t::MAX,
$t::MAX,
$t::MAX
)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand Down Expand Up @@ -895,6 +917,24 @@ macro_rules! impl_vec3_unsigned_integer_tests {
$vec3::new(8, 12, 12).manhattan_distance($vec3::new(24, 56, 2)),
70
);

assert_eq!(
$vec3::new(3, 27, 98).checked_manhattan_distance($vec3::new(20, 65, 97)),
Some(56)
);
assert_eq!(
$vec3::new(8, 12, 12).checked_manhattan_distance($vec3::new(24, 56, 2)),
Some(70)
);

assert_eq!(
$vec3::new($t::MIN, $t::MIN, $t::MIN).checked_manhattan_distance($vec3::new(
$t::MAX,
$t::MAX,
$t::MAX
)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand Down
36 changes: 36 additions & 0 deletions tests/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,26 @@ macro_rules! impl_vec4_signed_integer_tests {
$vec4::new(26, 2, 24, -22).manhattan_distance($vec4::new(26, 23, 6, 23)),
84
);

assert_eq!(
$vec4::new(41, 8, 21, 87).checked_manhattan_distance($vec4::new(49, 48, 28, 40)),
Some(102)
);
assert_eq!(
$vec4::new(19, 16, 100, 74).checked_manhattan_distance($vec4::new(14, 55, 115, 48)),
Some(85)
);

assert_eq!(
$vec4::new(26, 2, 24, -22).checked_manhattan_distance($vec4::new(26, 23, 6, 23)),
Some(84)
);

assert_eq!(
$vec4::new($t::MIN, $t::MIN, $t::MIN, $t::MIN)
.checked_manhattan_distance($vec4::new($t::MAX, $t::MAX, $t::MAX, $t::MAX)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand Down Expand Up @@ -1014,6 +1034,22 @@ macro_rules! impl_vec4_unsigned_integer_tests {
$vec4::new(19, 16, 179, 174).manhattan_distance($vec4::new(14, 55, 115, 148)),
134
);

assert_eq!(
$vec4::new(41, 8, 21, 87).checked_manhattan_distance($vec4::new(49, 48, 128, 40)),
Some(202)
);
assert_eq!(
$vec4::new(19, 16, 179, 174)
.checked_manhattan_distance($vec4::new(14, 55, 115, 148)),
Some(134)
);

assert_eq!(
$vec4::new($t::MIN, $t::MIN, $t::MIN, $t::MIN)
.checked_manhattan_distance($vec4::new($t::MAX, $t::MAX, $t::MAX, $t::MAX)),
None
);
});

glam_test!(test_chebyshev_distance, {
Expand Down

0 comments on commit d438ee8

Please sign in to comment.