mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-13 19:49:18 +00:00
dev-ops/fix-linting-issues-in-tests
This commit is contained in:
@@ -5,7 +5,6 @@ use pong::geom::geom::Vector;
|
||||
use pong::geom::shape::Shape;
|
||||
use pong::utils::utils::DefaultLoggerFactory;
|
||||
use rstest::rstest;
|
||||
use std::borrow::{Borrow, BorrowMut};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -67,17 +66,18 @@ use std::rc::Rc;
|
||||
create_game_obj(2, Vector::new(0., 0.), Vector::new(0., 1.), true),
|
||||
)]
|
||||
pub fn should_handle_collision(
|
||||
#[case] mut obj_a: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] mut obj_b: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] expected_a: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] expected_b: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] obj_a: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] obj_b: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] _expected_a: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] _expected_b: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
) {
|
||||
let logger = DefaultLoggerFactory::noop();
|
||||
let mut handler = CollisionHandler::new(&logger);
|
||||
handler.register((String::from("obj"), String::from("obj")), |a, b| {});
|
||||
handler.register((String::from("obj"), String::from("obj")), |_a, _b| {});
|
||||
let res = handler.handle(obj_a, obj_b);
|
||||
assert_eq!(true, res)
|
||||
// assert_eq!(obj_a.pos(), expected_a.pos());
|
||||
assert_eq!(true, res);
|
||||
// TODO: Fix
|
||||
// assert_eq!(RefCell::borrow(&obj_a).pos(), RefCell::borrow(&expected_a).pos());
|
||||
// assert_eq!(obj_a.vel(), expected_a.vel());
|
||||
// assert_eq!(obj_b.pos(), expected_b.pos());
|
||||
// assert_eq!(obj_b.vel(), expected_b.vel());
|
||||
|
||||
@@ -4,7 +4,7 @@ use pong::geom::geom::{BoundingBox, Vector};
|
||||
use pong::geom::shape::ShapeType;
|
||||
use pong::utils::utils::DefaultLoggerFactory;
|
||||
use rstest::rstest;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::cell::{RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[rstest]
|
||||
@@ -62,8 +62,7 @@ pub fn should_detect_collisions(
|
||||
pub struct MockGameObject {
|
||||
id: u16,
|
||||
obj_type: String,
|
||||
bounding_box: BoundingBox,
|
||||
zero_vec: Vector,
|
||||
bounding_box: BoundingBox
|
||||
}
|
||||
|
||||
impl MockGameObject {
|
||||
@@ -75,19 +74,18 @@ impl MockGameObject {
|
||||
Rc::new(RefCell::new(Box::new(MockGameObject {
|
||||
id,
|
||||
obj_type: String::from(obj_type),
|
||||
bounding_box,
|
||||
zero_vec: Vector::zero(),
|
||||
bounding_box
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
impl GameObject for MockGameObject {
|
||||
fn id(&self) -> u16 {
|
||||
todo!()
|
||||
self.id
|
||||
}
|
||||
|
||||
fn obj_type(&self) -> &str {
|
||||
todo!()
|
||||
&*self.obj_type
|
||||
}
|
||||
|
||||
fn shape(&self) -> &ShapeType {
|
||||
@@ -110,12 +108,12 @@ impl GameObject for MockGameObject {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn update_pos(&mut self, ms_diff: f64) {
|
||||
fn update_pos(&mut self, _ms_diff: f64) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn bounding_box(&self) -> BoundingBox {
|
||||
todo!()
|
||||
self.bounding_box.clone()
|
||||
}
|
||||
|
||||
fn vel(&self) -> &Vector {
|
||||
@@ -134,7 +132,7 @@ impl GameObject for MockGameObject {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_dirty(&mut self, is_dirty: bool) {
|
||||
fn set_dirty(&mut self, _is_dirty: bool) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#[cfg(test)]
|
||||
mod game_field_tests {
|
||||
use pong::game_field::{Field, Input, InputType};
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[test]
|
||||
fn player_input_update_pos__up() {
|
||||
fn player_input_update_pos_up() {
|
||||
let height = 1000;
|
||||
let mut field = Field::mock(1000, height);
|
||||
field.add_player(1, 50, height / 2);
|
||||
@@ -26,7 +25,7 @@ mod game_field_tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn player_input_update_pos__down() {
|
||||
fn player_input_update_pos_down() {
|
||||
let height = 1000;
|
||||
let mut field = Field::mock(1000, height);
|
||||
field.add_player(1, 50, height / 2);
|
||||
|
||||
@@ -2,11 +2,10 @@ use pong::game_field::{Bound, Field};
|
||||
use pong::game_object::game_object::{DefaultGameObject, GameObject};
|
||||
use pong::geom::geom::Vector;
|
||||
use pong::pong::pong_collisions::handle_player_bound_collision;
|
||||
use pong::utils::utils::{DefaultLoggerFactory, NoopLogger};
|
||||
use pong::utils::utils::{DefaultLoggerFactory};
|
||||
use rstest::rstest;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use pong::event::event::EventWriter;
|
||||
use pong::pong::pong_events::NoopPongEventWriter;
|
||||
|
||||
#[rstest]
|
||||
@@ -43,10 +42,10 @@ use pong::pong::pong_events::NoopPongEventWriter;
|
||||
get_bound(Bound::TOP)
|
||||
)]
|
||||
pub fn should_correctly_handle_player_bounds_collision(
|
||||
#[case] mut player: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] mut bounds: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] mut player_expected: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] mut bounds_expected: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] player: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] bounds: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] player_expected: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
#[case] bounds_expected: Rc<RefCell<Box<dyn GameObject>>>,
|
||||
) {
|
||||
handle_player_bound_collision(player.clone(), bounds.clone());
|
||||
assert_eq!(player_expected.borrow().pos(), player.borrow().pos());
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use pong::geom::geom::Vector;
|
||||
use rstest::rstest;
|
||||
use std::f64::consts::FRAC_PI_2;
|
||||
use std::f64::consts::FRAC_PI_4;
|
||||
use std::f64::consts::PI;
|
||||
|
||||
#[rstest]
|
||||
#[case(1., 0., 1.)]
|
||||
@@ -82,8 +80,8 @@ pub fn should_correctly_rotate(
|
||||
#[case(Vector::new(1., 0.), Vector::new(0., 1.), 0.)]
|
||||
#[case(Vector::new(1., 0.), Vector::new(-1., 0.), -1.)]
|
||||
pub fn should_calculate_dot_product(
|
||||
#[case] mut vector: Vector,
|
||||
#[case] mut other: Vector,
|
||||
#[case] vector: Vector,
|
||||
#[case] other: Vector,
|
||||
#[case] expected: f64,
|
||||
) {
|
||||
let dot = vector.dot(&other);
|
||||
|
||||
Reference in New Issue
Block a user