Merge branch 'master' of https://framagit.org/mhart/DancingDroids into parser2
Sync
This commit is contained in:
commit
c9241e4c4b
@ -23,7 +23,7 @@ mod world;
|
|||||||
|
|
||||||
/// Check if the robot is in the map.
|
/// Check if the robot is in the map.
|
||||||
fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
|
fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
|
||||||
if (r.p.x, r.p.y) < (0, 0) || (r.p.x, r.p.y) > (w.x, w.y) {
|
if r.p.x < 0 || r.p.y < 0 || r.p.x > w.x || r.p.y > w.y {
|
||||||
Err(format!("The robot {} is off map", r.id))
|
Err(format!("The robot {} is off map", r.id))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -254,10 +254,10 @@ mod tests {
|
|||||||
let mut r = robot::Robot::new(
|
let mut r = robot::Robot::new(
|
||||||
0,
|
0,
|
||||||
robot::Orientation::N,
|
robot::Orientation::N,
|
||||||
robot::Position { x: 2, y: 3 },
|
robot::Position { x: 2, y: 4 },
|
||||||
vec!['F'],
|
vec!['F'],
|
||||||
);
|
);
|
||||||
let w = world::World { x: 1, y: 1 };
|
let w = world::World { x: 3, y: 3 };
|
||||||
|
|
||||||
assert!(check_map(&r, &w).is_ok());
|
assert!(check_map(&r, &w).is_ok());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user