reduce test prolixity with smarter use statement
This commit is contained in:
parent
3af88ea712
commit
9a9bad4f71
42
src/main.rs
42
src/main.rs
@ -86,67 +86,67 @@ mod driver {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{rover, driver};
|
use super::driver;
|
||||||
use super::rover::{Rover};
|
use super::rover::{Rover, Facing,Rotation};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_north() {
|
fn move_north() {
|
||||||
let r = Rover(1, 1, rover::Facing::N);
|
let r = Rover(1, 1, Facing::N);
|
||||||
assert_eq!(r.forward(),
|
assert_eq!(r.forward(),
|
||||||
Rover(1, 0, rover::Facing::N));
|
Rover(1, 0, Facing::N));
|
||||||
|
|
||||||
let r = Rover(1, 3, rover::Facing::N);
|
let r = Rover(1, 3, Facing::N);
|
||||||
assert_eq!(r.forward(),
|
assert_eq!(r.forward(),
|
||||||
Rover(1, 2, rover::Facing::N));
|
Rover(1, 2, Facing::N));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_south() {
|
fn move_south() {
|
||||||
let r = Rover(1, 1, rover::Facing::S);
|
let r = Rover(1, 1, Facing::S);
|
||||||
assert_eq!(r.forward(),
|
assert_eq!(r.forward(),
|
||||||
Rover(1, 2, rover::Facing::S));
|
Rover(1, 2, Facing::S));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_west() {
|
fn move_west() {
|
||||||
let r = Rover(1, 1, rover::Facing::W);
|
let r = Rover(1, 1, Facing::W);
|
||||||
assert_eq!(r.forward(),
|
assert_eq!(r.forward(),
|
||||||
Rover(0, 1, rover::Facing::W));
|
Rover(0, 1, Facing::W));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_east() {
|
fn move_east() {
|
||||||
let r = Rover(1, 1, rover::Facing::E);
|
let r = Rover(1, 1, Facing::E);
|
||||||
assert_eq!(r.forward(),
|
assert_eq!(r.forward(),
|
||||||
Rover(2, 1, rover::Facing::E));
|
Rover(2, 1, Facing::E));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_backward() {
|
fn move_backward() {
|
||||||
let r = Rover(1, 1, rover::Facing::E);
|
let r = Rover(1, 1, Facing::E);
|
||||||
let r2 = r.forward();
|
let r2 = r.forward();
|
||||||
assert_eq!(r2.backward(), r);
|
assert_eq!(r2.backward(), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn spin_left() {
|
fn spin_left() {
|
||||||
let r = Rover(1, 1, rover::Facing::E);
|
let r = Rover(1, 1, Facing::E);
|
||||||
match r.rotate(rover::Rotation::Left) {
|
match r.rotate(Rotation::Left) {
|
||||||
Rover(_, _, facing) => assert_eq!(facing, rover::Facing::N)
|
Rover(_, _, facing) => assert_eq!(facing, Facing::N)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn spin_right() {
|
fn spin_right() {
|
||||||
let r = Rover(1, 1, rover::Facing::S);
|
let r = Rover(1, 1, Facing::S);
|
||||||
match r.rotate(rover::Rotation::Right) {
|
match r.rotate(Rotation::Right) {
|
||||||
Rover(_, _, facing) => assert_eq!(facing, rover::Facing::W)
|
Rover(_, _, facing) => assert_eq!(facing, Facing::W)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drive() {
|
fn drive() {
|
||||||
let r = Rover(1, 1, rover::Facing::S);
|
let r = Rover(1, 1, Facing::S);
|
||||||
assert_eq!(driver::execute(&r, "ffrf"),
|
assert_eq!(driver::execute(&r, "ffrf"),
|
||||||
Rover(0, 3, rover::Facing::W));
|
Rover(0, 3, Facing::W));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user