mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 07:15:41 -06:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da3c8e8284 | |||
| 9c0711a54c | |||
| 4598dc07e2 |
@@ -146,159 +146,3 @@ impl Position {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn movement_system(
|
||||
// map: Res<Map>,
|
||||
// delta_time: Res<DeltaTime>,
|
||||
// mut entities: Query<(&mut Position, &mut Movable, &EntityType)>,
|
||||
// mut errors: EventWriter<GameError>,
|
||||
// ) {
|
||||
// for (mut position, mut movable, entity_type) in entities.iter_mut() {
|
||||
// let distance = movable.speed * 60.0 * delta_time.0;
|
||||
|
||||
// match *position {
|
||||
// Position::Stopped { .. } => {
|
||||
// // Check if we have a requested direction to start moving
|
||||
// if let Some(requested_direction) = movable.requested_direction {
|
||||
// if let Some(edge) = map.graph.find_edge_in_direction(position.current_node(), requested_direction) {
|
||||
// if can_traverse(*entity_type, edge) {
|
||||
// // Start moving in the requested direction
|
||||
// let progress = if edge.distance > 0.0 {
|
||||
// distance / edge.distance
|
||||
// } else {
|
||||
// // Zero-distance edge (tunnels) - immediately teleport
|
||||
// tracing::debug!(
|
||||
// "Entity entering tunnel from node {} to node {}",
|
||||
// position.current_node(),
|
||||
// edge.target
|
||||
// );
|
||||
// 1.0
|
||||
// };
|
||||
|
||||
// *position = Position::Moving {
|
||||
// from: position.current_node(),
|
||||
// to: edge.target,
|
||||
// remaining_distance: progress,
|
||||
// };
|
||||
// movable.current_direction = requested_direction;
|
||||
// movable.requested_direction = None;
|
||||
// }
|
||||
// } else {
|
||||
// errors.write(
|
||||
// EntityError::InvalidMovement(format!(
|
||||
// "No edge found in direction {:?} from node {}",
|
||||
// requested_direction,
|
||||
// position.current_node()
|
||||
// ))
|
||||
// .into(),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Position::Moving {
|
||||
// from,
|
||||
// to,
|
||||
// remaining_distance,
|
||||
// } => {
|
||||
// // Continue moving or handle node transitions
|
||||
// let current_node = *from;
|
||||
// if let Some(edge) = map.graph.find_edge(current_node, *to) {
|
||||
// // Extract target node before mutable operations
|
||||
// let target_node = *to;
|
||||
|
||||
// // Get the current edge for distance calculation
|
||||
// let edge = map.graph.find_edge(current_node, target_node);
|
||||
|
||||
// if let Some(edge) = edge {
|
||||
// // Update progress along the edge
|
||||
// if edge.distance > 0.0 {
|
||||
// *remaining_distance += distance / edge.distance;
|
||||
// } else {
|
||||
// // Zero-distance edge (tunnels) - immediately complete
|
||||
// *remaining_distance = 1.0;
|
||||
// }
|
||||
|
||||
// if *remaining_distance >= 1.0 {
|
||||
// // Reached the target node
|
||||
// let overflow = if edge.distance > 0.0 {
|
||||
// (*remaining_distance - 1.0) * edge.distance
|
||||
// } else {
|
||||
// // Zero-distance edge - use remaining distance for overflow
|
||||
// distance
|
||||
// };
|
||||
// *position = Position::Stopped { node: target_node };
|
||||
|
||||
// let mut continued_moving = false;
|
||||
|
||||
// // Try to use requested direction first
|
||||
// if let Some(requested_direction) = movable.requested_direction {
|
||||
// if let Some(next_edge) = map.graph.find_edge_in_direction(position.node, requested_direction) {
|
||||
// if can_traverse(*entity_type, next_edge) {
|
||||
// let next_progress = if next_edge.distance > 0.0 {
|
||||
// overflow / next_edge.distance
|
||||
// } else {
|
||||
// // Zero-distance edge - immediately complete
|
||||
// 1.0
|
||||
// };
|
||||
|
||||
// *position = Position::Moving {
|
||||
// from: position.current_node(),
|
||||
// to: next_edge.target,
|
||||
// remaining_distance: next_progress,
|
||||
// };
|
||||
// movable.current_direction = requested_direction;
|
||||
// movable.requested_direction = None;
|
||||
// continued_moving = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If no requested direction or it failed, try to continue in current direction
|
||||
// if !continued_moving {
|
||||
// if let Some(next_edge) = map.graph.find_edge_in_direction(position.node, direction) {
|
||||
// if can_traverse(*entity_type, next_edge) {
|
||||
// let next_progress = if next_edge.distance > 0.0 {
|
||||
// overflow / next_edge.distance
|
||||
// } else {
|
||||
// // Zero-distance edge - immediately complete
|
||||
// 1.0
|
||||
// };
|
||||
|
||||
// *position = Position::Moving {
|
||||
// from: position.current_node(),
|
||||
// to: next_edge.target,
|
||||
// remaining_distance: next_progress,
|
||||
// };
|
||||
// // Keep current direction and movement state
|
||||
// continued_moving = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If we couldn't continue moving, stop
|
||||
// if !continued_moving {
|
||||
// *movement_state = MovementState::Stopped;
|
||||
// movable.requested_direction = None;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // Edge not found - this is an inconsistent state
|
||||
// errors.write(
|
||||
// EntityError::InvalidMovement(format!(
|
||||
// "Inconsistent state: Moving on non-existent edge from {} to {}",
|
||||
// current_node, target_node
|
||||
// ))
|
||||
// .into(),
|
||||
// );
|
||||
// *movement_state = MovementState::Stopped;
|
||||
// position.edge_progress = None;
|
||||
// }
|
||||
// } else {
|
||||
// // Movement state says moving but no edge progress - this shouldn't happen
|
||||
// errors.write(EntityError::InvalidMovement("Entity in Moving state but no edge progress".to_string()).into());
|
||||
// *movement_state = MovementState::Stopped;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -69,7 +69,7 @@ pub fn player_control_system(
|
||||
}
|
||||
}
|
||||
|
||||
fn can_traverse(entity_type: EntityType, edge: Edge) -> bool {
|
||||
pub fn can_traverse(entity_type: EntityType, edge: Edge) -> bool {
|
||||
let entity_flags = entity_type.traversal_flags();
|
||||
edge.traversal_flags.contains(entity_flags)
|
||||
}
|
||||
|
||||
158
tests/error.rs
Normal file
158
tests/error.rs
Normal file
@@ -0,0 +1,158 @@
|
||||
use pacman::error::{
|
||||
AnimatedTextureError, AssetError, EntityError, GameError, GameResult, IntoGameError, MapError, OptionExt, ParseError,
|
||||
ResultExt, TextureError,
|
||||
};
|
||||
use std::io;
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_asset_error() {
|
||||
let asset_error = AssetError::NotFound("test.png".to_string());
|
||||
let game_error: GameError = asset_error.into();
|
||||
assert!(matches!(game_error, GameError::Asset(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_parse_error() {
|
||||
let parse_error = ParseError::UnknownCharacter('Z');
|
||||
let game_error: GameError = parse_error.into();
|
||||
assert!(matches!(game_error, GameError::MapParse(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_map_error() {
|
||||
let map_error = MapError::NodeNotFound(42);
|
||||
let game_error: GameError = map_error.into();
|
||||
assert!(matches!(game_error, GameError::Map(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_texture_error() {
|
||||
let texture_error = TextureError::LoadFailed("Failed to load".to_string());
|
||||
let game_error: GameError = texture_error.into();
|
||||
assert!(matches!(game_error, GameError::Texture(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_entity_error() {
|
||||
let entity_error = EntityError::NodeNotFound(10);
|
||||
let game_error: GameError = entity_error.into();
|
||||
assert!(matches!(game_error, GameError::Entity(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_error_from_io_error() {
|
||||
let io_error = io::Error::new(io::ErrorKind::NotFound, "File not found");
|
||||
let game_error: GameError = io_error.into();
|
||||
assert!(matches!(game_error, GameError::Io(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_texture_error_from_animated_error() {
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(-1.0);
|
||||
let texture_error: TextureError = animated_error.into();
|
||||
assert!(matches!(texture_error, TextureError::Animated(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_error_from_io_error() {
|
||||
let io_error = io::Error::new(io::ErrorKind::PermissionDenied, "Permission denied");
|
||||
let asset_error: AssetError = io_error.into();
|
||||
assert!(matches!(asset_error, AssetError::Io(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_error_display() {
|
||||
let error = ParseError::UnknownCharacter('!');
|
||||
assert_eq!(error.to_string(), "Unknown character in board: !");
|
||||
|
||||
let error = ParseError::InvalidHouseDoorCount(3);
|
||||
assert_eq!(error.to_string(), "House door must have exactly 2 positions, found 3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_entity_error_display() {
|
||||
let error = EntityError::NodeNotFound(42);
|
||||
assert_eq!(error.to_string(), "Node not found in graph: 42");
|
||||
|
||||
let error = EntityError::EdgeNotFound { from: 1, to: 2 };
|
||||
assert_eq!(error.to_string(), "Edge not found: from 1 to 2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animated_texture_error_display() {
|
||||
let error = AnimatedTextureError::InvalidFrameDuration(0.0);
|
||||
assert_eq!(error.to_string(), "Frame duration must be positive, got 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_game_error_trait() {
|
||||
let result: Result<i32, io::Error> = Err(io::Error::new(io::ErrorKind::Other, "test error"));
|
||||
let game_result: GameResult<i32> = result.into_game_error();
|
||||
|
||||
assert!(game_result.is_err());
|
||||
if let Err(GameError::InvalidState(msg)) = game_result {
|
||||
assert!(msg.contains("test error"));
|
||||
} else {
|
||||
panic!("Expected InvalidState error");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_game_error_trait_success() {
|
||||
let result: Result<i32, io::Error> = Ok(42);
|
||||
let game_result: GameResult<i32> = result.into_game_error();
|
||||
|
||||
assert_eq!(game_result.unwrap(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_option_ext_some() {
|
||||
let option: Option<i32> = Some(42);
|
||||
let result: GameResult<i32> = option.ok_or_game_error(|| GameError::InvalidState("Not found".to_string()));
|
||||
|
||||
assert_eq!(result.unwrap(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_option_ext_none() {
|
||||
let option: Option<i32> = None;
|
||||
let result: GameResult<i32> = option.ok_or_game_error(|| GameError::InvalidState("Not found".to_string()));
|
||||
|
||||
assert!(result.is_err());
|
||||
if let Err(GameError::InvalidState(msg)) = result {
|
||||
assert_eq!(msg, "Not found");
|
||||
} else {
|
||||
panic!("Expected InvalidState error");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_result_ext_success() {
|
||||
let result: Result<i32, io::Error> = Ok(42);
|
||||
let game_result: GameResult<i32> = result.with_context(|_| GameError::InvalidState("Context".to_string()));
|
||||
|
||||
assert_eq!(game_result.unwrap(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_result_ext_error() {
|
||||
let result: Result<i32, io::Error> = Err(io::Error::new(io::ErrorKind::Other, "original error"));
|
||||
let game_result: GameResult<i32> = result.with_context(|_| GameError::InvalidState("Context error".to_string()));
|
||||
|
||||
assert!(game_result.is_err());
|
||||
if let Err(GameError::InvalidState(msg)) = game_result {
|
||||
assert_eq!(msg, "Context error");
|
||||
} else {
|
||||
panic!("Expected InvalidState error");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_error_chain_conversions() {
|
||||
// Test that we can convert through multiple levels
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(-5.0);
|
||||
let texture_error: TextureError = animated_error.into();
|
||||
let game_error: GameError = texture_error.into();
|
||||
|
||||
assert!(matches!(game_error, GameError::Texture(TextureError::Animated(_))));
|
||||
}
|
||||
117
tests/events.rs
Normal file
117
tests/events.rs
Normal file
@@ -0,0 +1,117 @@
|
||||
use pacman::events::{GameCommand, GameEvent};
|
||||
use pacman::map::direction::Direction;
|
||||
|
||||
#[test]
|
||||
fn test_game_command_variants() {
|
||||
// Test that all GameCommand variants can be created
|
||||
let commands = vec![
|
||||
GameCommand::Exit,
|
||||
GameCommand::MovePlayer(Direction::Up),
|
||||
GameCommand::MovePlayer(Direction::Down),
|
||||
GameCommand::MovePlayer(Direction::Left),
|
||||
GameCommand::MovePlayer(Direction::Right),
|
||||
GameCommand::ToggleDebug,
|
||||
GameCommand::MuteAudio,
|
||||
GameCommand::ResetLevel,
|
||||
GameCommand::TogglePause,
|
||||
];
|
||||
|
||||
// Just verify they can be created and compared
|
||||
assert_eq!(commands.len(), 9);
|
||||
assert_eq!(commands[0], GameCommand::Exit);
|
||||
assert_eq!(commands[1], GameCommand::MovePlayer(Direction::Up));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_command_equality() {
|
||||
assert_eq!(GameCommand::Exit, GameCommand::Exit);
|
||||
assert_eq!(GameCommand::ToggleDebug, GameCommand::ToggleDebug);
|
||||
assert_eq!(
|
||||
GameCommand::MovePlayer(Direction::Left),
|
||||
GameCommand::MovePlayer(Direction::Left)
|
||||
);
|
||||
|
||||
assert_ne!(GameCommand::Exit, GameCommand::ToggleDebug);
|
||||
assert_ne!(
|
||||
GameCommand::MovePlayer(Direction::Left),
|
||||
GameCommand::MovePlayer(Direction::Right)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_command_copy_clone() {
|
||||
let original = GameCommand::MovePlayer(Direction::Up);
|
||||
let copied = original;
|
||||
let cloned = original.clone();
|
||||
|
||||
assert_eq!(original, copied);
|
||||
assert_eq!(original, cloned);
|
||||
assert_eq!(copied, cloned);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_event_variants() {
|
||||
let command_event = GameEvent::Command(GameCommand::Exit);
|
||||
let collision_event = GameEvent::Collision(bevy_ecs::entity::Entity::from_raw(1), bevy_ecs::entity::Entity::from_raw(2));
|
||||
|
||||
// Test that events can be created and compared
|
||||
assert_eq!(command_event, GameEvent::Command(GameCommand::Exit));
|
||||
assert_ne!(command_event, collision_event);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_command_to_game_event_conversion() {
|
||||
let command = GameCommand::ToggleDebug;
|
||||
let event: GameEvent = command.into();
|
||||
|
||||
assert_eq!(event, GameEvent::Command(GameCommand::ToggleDebug));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_command_to_game_event_conversion_all_variants() {
|
||||
let commands = vec![
|
||||
GameCommand::Exit,
|
||||
GameCommand::MovePlayer(Direction::Up),
|
||||
GameCommand::ToggleDebug,
|
||||
GameCommand::MuteAudio,
|
||||
GameCommand::ResetLevel,
|
||||
GameCommand::TogglePause,
|
||||
];
|
||||
|
||||
for command in commands {
|
||||
let event: GameEvent = command.into();
|
||||
assert_eq!(event, GameEvent::Command(command));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_player_all_directions() {
|
||||
let directions = [Direction::Up, Direction::Down, Direction::Left, Direction::Right];
|
||||
|
||||
for direction in directions {
|
||||
let command = GameCommand::MovePlayer(direction);
|
||||
let event: GameEvent = command.into();
|
||||
|
||||
if let GameEvent::Command(GameCommand::MovePlayer(dir)) = event {
|
||||
assert_eq!(dir, direction);
|
||||
} else {
|
||||
panic!("Expected MovePlayer command with direction {:?}", direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_event_debug_format() {
|
||||
let event = GameEvent::Command(GameCommand::Exit);
|
||||
let debug_str = format!("{:?}", event);
|
||||
assert!(debug_str.contains("Command"));
|
||||
assert!(debug_str.contains("Exit"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_command_debug_format() {
|
||||
let command = GameCommand::MovePlayer(Direction::Left);
|
||||
let debug_str = format!("{:?}", command);
|
||||
assert!(debug_str.contains("MovePlayer"));
|
||||
assert!(debug_str.contains("Left"));
|
||||
}
|
||||
@@ -19,7 +19,7 @@ fn get_formatted_output() -> impl IntoIterator<Item = String> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_formatting_alignment() {
|
||||
fn test_complex_formatting_alignment() {
|
||||
let mut colon_positions = vec![];
|
||||
let mut first_decimal_positions = vec![];
|
||||
let mut second_decimal_positions = vec![];
|
||||
@@ -93,3 +93,80 @@ fn test_formatting_alignment() {
|
||||
second_unit_positions
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_timing_display_basic() {
|
||||
let timing_data = vec![
|
||||
("render".to_string(), Duration::from_micros(1500), Duration::from_micros(200)),
|
||||
("input".to_string(), Duration::from_micros(300), Duration::from_micros(50)),
|
||||
("physics".to_string(), Duration::from_nanos(750), Duration::from_nanos(100)),
|
||||
];
|
||||
|
||||
let formatted = format_timing_display(timing_data);
|
||||
|
||||
// Should have 3 lines (one for each system)
|
||||
assert_eq!(formatted.len(), 3);
|
||||
|
||||
// Each line should contain the system name
|
||||
assert!(formatted.iter().any(|line| line.contains("render")));
|
||||
assert!(formatted.iter().any(|line| line.contains("input")));
|
||||
assert!(formatted.iter().any(|line| line.contains("physics")));
|
||||
|
||||
// Each line should contain timing information with proper units
|
||||
for line in formatted.iter() {
|
||||
assert!(line.contains(":"), "Line should contain colon separator: {}", line);
|
||||
assert!(line.contains("±"), "Line should contain ± symbol: {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_timing_display_empty() {
|
||||
let timing_data = vec![];
|
||||
let formatted = format_timing_display(timing_data);
|
||||
assert!(formatted.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_timing_display_units() {
|
||||
let timing_data = vec![
|
||||
("seconds".to_string(), Duration::from_secs(2), Duration::from_millis(100)),
|
||||
("millis".to_string(), Duration::from_millis(15), Duration::from_micros(200)),
|
||||
("micros".to_string(), Duration::from_micros(500), Duration::from_nanos(50)),
|
||||
("nanos".to_string(), Duration::from_nanos(250), Duration::from_nanos(25)),
|
||||
];
|
||||
|
||||
let formatted = format_timing_display(timing_data);
|
||||
|
||||
// Check that appropriate units are used
|
||||
let all_lines = formatted.join(" ");
|
||||
assert!(all_lines.contains("s"), "Should contain seconds unit");
|
||||
assert!(all_lines.contains("ms"), "Should contain milliseconds unit");
|
||||
assert!(all_lines.contains("µs"), "Should contain microseconds unit");
|
||||
assert!(all_lines.contains("ns"), "Should contain nanoseconds unit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_timing_display_alignment() {
|
||||
let timing_data = vec![
|
||||
("short".to_string(), Duration::from_micros(100), Duration::from_micros(10)),
|
||||
(
|
||||
"very_long_name".to_string(),
|
||||
Duration::from_micros(200),
|
||||
Duration::from_micros(20),
|
||||
),
|
||||
];
|
||||
|
||||
let formatted = format_timing_display(timing_data);
|
||||
|
||||
// Find colon positions - they should be aligned
|
||||
let colon_positions: Vec<usize> = formatted.iter().map(|line| line.find(':').unwrap_or(0)).collect();
|
||||
|
||||
// All colons should be at the same position (aligned)
|
||||
if colon_positions.len() > 1 {
|
||||
let first_pos = colon_positions[0];
|
||||
assert!(
|
||||
colon_positions.iter().all(|&pos| pos == first_pos),
|
||||
"Colons should be aligned at the same position"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
100
tests/player.rs
Normal file
100
tests/player.rs
Normal file
@@ -0,0 +1,100 @@
|
||||
use pacman::map::direction::Direction;
|
||||
use pacman::map::graph::{Edge, TraversalFlags};
|
||||
use pacman::systems::components::EntityType;
|
||||
use pacman::systems::player::can_traverse;
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_player_on_all_edges() {
|
||||
let edge = Edge {
|
||||
target: 1,
|
||||
distance: 10.0,
|
||||
direction: Direction::Up,
|
||||
traversal_flags: TraversalFlags::ALL,
|
||||
};
|
||||
|
||||
assert!(can_traverse(EntityType::Player, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_player_on_pacman_only_edges() {
|
||||
let edge = Edge {
|
||||
target: 1,
|
||||
distance: 10.0,
|
||||
direction: Direction::Right,
|
||||
traversal_flags: TraversalFlags::PACMAN,
|
||||
};
|
||||
|
||||
assert!(can_traverse(EntityType::Player, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_player_blocked_on_ghost_only_edges() {
|
||||
let edge = Edge {
|
||||
target: 1,
|
||||
distance: 10.0,
|
||||
direction: Direction::Left,
|
||||
traversal_flags: TraversalFlags::GHOST,
|
||||
};
|
||||
|
||||
assert!(!can_traverse(EntityType::Player, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_ghost_on_all_edges() {
|
||||
let edge = Edge {
|
||||
target: 2,
|
||||
distance: 15.0,
|
||||
direction: Direction::Down,
|
||||
traversal_flags: TraversalFlags::ALL,
|
||||
};
|
||||
|
||||
assert!(can_traverse(EntityType::Ghost, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_ghost_on_ghost_only_edges() {
|
||||
let edge = Edge {
|
||||
target: 2,
|
||||
distance: 15.0,
|
||||
direction: Direction::Up,
|
||||
traversal_flags: TraversalFlags::GHOST,
|
||||
};
|
||||
|
||||
assert!(can_traverse(EntityType::Ghost, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_ghost_blocked_on_pacman_only_edges() {
|
||||
let edge = Edge {
|
||||
target: 2,
|
||||
distance: 15.0,
|
||||
direction: Direction::Right,
|
||||
traversal_flags: TraversalFlags::PACMAN,
|
||||
};
|
||||
|
||||
assert!(!can_traverse(EntityType::Ghost, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_traverse_static_entities_flags() {
|
||||
let edge = Edge {
|
||||
target: 3,
|
||||
distance: 8.0,
|
||||
direction: Direction::Left,
|
||||
traversal_flags: TraversalFlags::ALL,
|
||||
};
|
||||
|
||||
// Static entities have empty traversal flags but can still "traverse"
|
||||
// in the sense that empty flags are contained in any flag set
|
||||
// This is the expected behavior since empty ⊆ any set
|
||||
assert!(can_traverse(EntityType::Pellet, edge));
|
||||
assert!(can_traverse(EntityType::PowerPellet, edge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_entity_type_traversal_flags() {
|
||||
assert_eq!(EntityType::Player.traversal_flags(), TraversalFlags::PACMAN);
|
||||
assert_eq!(EntityType::Ghost.traversal_flags(), TraversalFlags::GHOST);
|
||||
assert_eq!(EntityType::Pellet.traversal_flags(), TraversalFlags::empty());
|
||||
assert_eq!(EntityType::PowerPellet.traversal_flags(), TraversalFlags::empty());
|
||||
}
|
||||
Reference in New Issue
Block a user