mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-11 10:39:18 +00:00
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use pong::geom::geom::{BoundingBox, Vector};
|
|
use rstest::rstest;
|
|
|
|
#[rstest]
|
|
#[case(BoundingBox::create(&Vector::new(10., 10.), 5., 5.), Vector::new(10., 10.), true)]
|
|
#[case(BoundingBox::create(&Vector::new(10., 10.), 5., 5.), Vector::new(8., 8.), true)]
|
|
#[case(BoundingBox::create(&Vector::new(10., 10.), 5., 5.), Vector::new(20., 20.), false)]
|
|
pub fn should_correctly_determine_if_point_is_within_box(
|
|
#[case] bounding_box: BoundingBox,
|
|
#[case] point: Vector,
|
|
#[case] expected: bool,
|
|
) {
|
|
let res = bounding_box.is_point_within(&point);
|
|
assert_eq!(res, expected);
|
|
}
|
|
|
|
#[rstest]
|
|
#[case(
|
|
BoundingBox::create(&Vector::new(10., 10.), 5., 5.),
|
|
BoundingBox::create(&Vector::new(10., 10.), 5., 5.),
|
|
true
|
|
)]
|
|
#[case(
|
|
BoundingBox::create(&Vector::new(10., 10.), 5., 5.),
|
|
BoundingBox::create(&Vector::new(8., 8.), 5., 5.),
|
|
true
|
|
)]
|
|
#[case(
|
|
BoundingBox::create(&Vector::new(10., 10.), 5., 5.),
|
|
BoundingBox::create(&Vector::new(4.9, 4.9), 5., 5.),
|
|
false
|
|
)]
|
|
#[case(
|
|
BoundingBox::create(&Vector::new(10., 10.), 5., 5.),
|
|
BoundingBox::create(&Vector::new(5., 5.), 5., 5.),
|
|
true
|
|
)]
|
|
pub fn should_correctly_determine_if_overlap(
|
|
#[case] bounding_box_a: BoundingBox,
|
|
#[case] bounding_box_b: BoundingBox,
|
|
#[case] expected: bool,
|
|
) {
|
|
let res = bounding_box_a.overlaps(&bounding_box_b);
|
|
assert_eq!(res, expected);
|
|
}
|