rust/landgen/src/wavefront_collapse/tile_image.rs
branchtransitional_engine
changeset 15947 60b5639cc3a5
parent 15946 e82de0410da5
child 15948 9bd828451d77
--- a/rust/landgen/src/wavefront_collapse/tile_image.rs	Fri Feb 03 14:44:33 2023 +0100
+++ b/rust/landgen/src/wavefront_collapse/tile_image.rs	Fri Feb 03 15:59:18 2023 +0100
@@ -2,7 +2,7 @@
 use std::rc::Rc;
 use vec2d::Vec2D;
 
-#[derive(PartialEq, Clone)]
+#[derive(PartialEq, Clone, Debug)]
 pub struct Edge<I: PartialEq + Clone> {
     id: I,
     symmetrical: bool,
@@ -109,7 +109,78 @@
             left: self.bottom.clone(),
         }
     }
+
+    pub fn right_edge(&self) -> &Edge<I> {
+        &self.right
+    }
+
+    pub fn bottom_edge(&self) -> &Edge<I> {
+        &self.bottom
+    }
+
+    pub fn left_edge(&self) -> &Edge<I> {
+        &self.left
+    }
+
+    pub fn top_edge(&self) -> &Edge<I> {
+        &self.top
+    }
 }
 
 #[cfg(test)]
-mod tests {}
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_edge_new() {
+        let edge = Edge::new(1, true);
+        assert_eq!(edge.id, 1);
+        assert_eq!(edge.symmetrical, true);
+        assert_eq!(edge.reverse, false);
+    }
+
+    #[test]
+    fn test_edge_reversed() {
+        let edge = Edge::new(1, true);
+        let reversed = edge.reversed();
+        assert_eq!(reversed.id, edge.id);
+        assert_eq!(reversed.symmetrical, edge.symmetrical);
+        assert_eq!(reversed.reverse, false);
+
+        let edge = Edge::new(1, false);
+        let reversed = edge.reversed();
+        assert_eq!(reversed.id, edge.id);
+        assert_eq!(reversed.symmetrical, edge.symmetrical);
+        assert_eq!(reversed.reverse, true);
+    }
+
+    #[test]
+    fn test_edge_equality() {
+        let edge1 = Edge::new(1, true);
+        let edge2 = Edge::new(1, true);
+        assert_eq!(edge1, edge2);
+
+        let edge1 = Edge::new(1, false);
+        let edge2 = Edge::new(1, false);
+        assert_eq!(edge1, edge2);
+
+        let edge1 = Edge::new(1, false);
+        let edge2 = Edge::new(2, false);
+        assert_ne!(edge1, edge2);
+    }
+
+    #[test]
+    fn test_edge_equality_with_reverse() {
+        let edge1 = Edge::new(1, true);
+        let edge2 = edge1.reversed();
+        assert_eq!(edge1, edge2);
+
+        let edge1 = Edge::new(1, false);
+        let edge2 = edge1.reversed();
+        assert_ne!(edge1, edge2);
+
+        let edge1 = Edge::new(1, true);
+        let edge2 = edge1.reversed().reversed();
+        assert_eq!(edge1, edge2);
+    }
+}