From c2d6e5c99a6a967353da1664117dfabb90be4baf Mon Sep 17 00:00:00 2001 From: Guillaume Pasquet Date: Wed, 20 Nov 2019 17:33:52 +0000 Subject: More tests --- src/world.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) 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, String> { @@ -501,6 +501,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(); -- cgit v1.2.3