aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pasquet <dev@etenil.net>2019-11-20 17:33:52 +0000
committerGuillaume Pasquet <dev@etenil.net>2019-11-20 17:33:52 +0000
commitc2d6e5c99a6a967353da1664117dfabb90be4baf (patch)
tree37cacda7a704c3571113f505013054c067f2170a
parent337e7928945f37bb422cbf0a7905763dc68cc8be (diff)
More tests
-rw-r--r--src/world.rs59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/world.rs b/src/world.rs
index 451b091..2098308 100644
--- a/src/world.rs
+++ b/src/world.rs
@@ -145,7 +145,7 @@ impl Corridor {
}
};
- Ok(Corridor::new(origin, length.round() as usize, dir))
+ Ok(Corridor::new(origin, length.ceil() as usize, dir))
}
pub fn link(start: Point, end: Point) -> Result<Vec<Corridor>, String> {
@@ -502,6 +502,63 @@ mod tests {
}
#[test]
+ fn test_link_corridors_returns_a_vec_of_corridors_on_reversed_diagonal_points() {
+ let cor = Corridor::link((5, 5), (0, 0)).unwrap();
+
+ let exp_horz = vec![
+ Corridor::new((0, 5), 5, CorridorType::Horizontal),
+ Corridor::new((0, 0), 5, CorridorType::Vertical),
+ ];
+ let exp_vert = vec![
+ Corridor::new((5, 0), 5, CorridorType::Vertical),
+ Corridor::new((0, 0), 5, CorridorType::Horizontal),
+ ];
+
+ match cor[0].direction {
+ CorridorType::Horizontal => assert_eq!(cor, exp_horz),
+ CorridorType::Vertical => assert_eq!(cor, exp_vert),
+ };
+ }
+
+ #[test]
+ fn test_link_corridors_returns_a_vec_of_corridors_on_reversed_vertical_points() {
+ let cor = Corridor::link((0, 5), (5, 0)).unwrap();
+
+ let exp_horz = vec![
+ Corridor::new((0, 5), 5, CorridorType::Horizontal),
+ Corridor::new((5, 0), 5, CorridorType::Vertical),
+ ];
+ let exp_vert = vec![
+ Corridor::new((0, 0), 5, CorridorType::Vertical),
+ Corridor::new((0, 0), 5, CorridorType::Horizontal),
+ ];
+
+ match cor[0].direction {
+ CorridorType::Horizontal => assert_eq!(cor, exp_horz),
+ CorridorType::Vertical => assert_eq!(cor, exp_vert),
+ };
+ }
+
+ #[test]
+ fn test_link_corridors_returns_a_vec_of_corridors_on_reversed_horizontal_points() {
+ let cor = Corridor::link((5, 0), (0, 5)).unwrap();
+
+ let exp_horz = vec![
+ Corridor::new((0, 0), 5, CorridorType::Horizontal),
+ Corridor::new((0, 0), 5, CorridorType::Vertical),
+ ];
+ let exp_vert = vec![
+ Corridor::new((5, 0), 5, CorridorType::Vertical),
+ Corridor::new((0, 5), 5, CorridorType::Horizontal),
+ ];
+
+ match cor[0].direction {
+ CorridorType::Horizontal => assert_eq!(cor, exp_horz),
+ CorridorType::Vertical => assert_eq!(cor, exp_vert),
+ };
+ }
+
+ #[test]
fn test_link_corridors_with_horizontal_aligned_points_returns_one_corridor() {
let cor = Corridor::link((0, 0), (5, 0)).unwrap();