From 8ed44d5336639ef4cbd33da938e403f7a708647c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 20 Jul 2024 02:53:13 +0200 Subject: [PATCH] more tests (currently failing) --- src/layers.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/src/layers.rs b/src/layers.rs index f21cd02..1398d91 100644 --- a/src/layers.rs +++ b/src/layers.rs @@ -417,24 +417,84 @@ mod tests { fn take_shortcut() { let mesh = mesh_overlapping_layers(); for i in 0..6 { - let from = Vec2::new(0.0 + i as f32 / 10.0, 2.1); + let from = Vec2::new(i as f32 / 10.0, 2.1); let to = Vec2::new(5.0 - i as f32 / 10.0, 0.9); let path = dbg!(mesh.path(from, to).unwrap()); assert_eq!(path.path, vec![to]); } } + #[test] + fn take_shortcut_back() { + let mesh = mesh_overlapping_layers(); + for i in 0..6 { + let from = Vec2::new(5.0 - i as f32 / 10.0, 0.9); + let to = Vec2::new(i as f32 / 10.0, 2.1); + let path = dbg!(mesh.path(from, to).unwrap()); + assert_eq!(path.path, vec![to]); + } + } + #[test] fn take_long_way() { let mesh = mesh_overlapping_layers(); for i in 7..15 { - let from = Vec2::new(0.0 + i as f32 / 10.0, 2.1); + let from = Vec2::new(i as f32 / 10.0, 2.1); let to = Vec2::new(5.0 - i as f32 / 10.0, 0.9); let path = dbg!(mesh.path(from, to).unwrap()); assert_eq!(path.path, vec![vec2(2.0, 2.0), vec2(3.0, 1.0), to]); } } + #[test] + fn take_long_way_back() { + let mesh = mesh_overlapping_layers(); + for i in 7..15 { + let from = Vec2::new(5.0 - i as f32 / 10.0, 0.9); + let to = Vec2::new(i as f32 / 10.0, 2.1); + let path = dbg!(mesh.path(from, to).unwrap()); + assert_eq!(path.path, vec![vec2(2.0, 2.0), vec2(3.0, 1.0), to]); + } + } + + #[test] + fn from_one_to_the_other() { + let mesh = mesh_overlapping_layers(); + let path = dbg!(mesh + .path( + Coords { + pos: vec2(2.5, 1.5), + layer: Some(0) + }, + Coords { + pos: vec2(2.5, 1.5), + layer: Some(1) + }, + ) + .unwrap()); + assert_eq!( + path.path, + vec![vec2(3.0, 1.0,), vec2(4.0, 1.0,), vec2(2.5, 1.5,),], + ); + + let path_back = dbg!(mesh + .path( + Coords { + pos: vec2(2.5, 1.5), + layer: Some(1) + }, + Coords { + pos: vec2(2.5, 1.5), + layer: Some(0) + }, + ) + .unwrap()); + assert_eq!( + path_back.path, + vec![vec2(4.0, 1.0,), vec2(3.0, 1.0,), vec2(2.5, 1.5,),], + ); + } + #[test] fn find_point_on_layer() { let mesh = mesh_overlapping_layers();