Ok I lied about not needing unit tests.
1 files changed, 66 insertions(+), 3 deletions(-)

M src/lib.rs
M src/lib.rs +66 -3
@@ 162,7 162,18 @@ mod tests {
 
     struct St {
         contents: Vec<u8>,
-        size: u32,
+        size: usize,
+    }
+
+    impl St {
+        fn new(size: f32) -> Self {
+            // fukkin TryFrom<f32> not implemented for usize? why
+            let int_size = (size + 1.0) as usize;
+            Self {
+                contents: vec![0; int_size * int_size],
+                size: int_size,
+            }
+        }
     }
 
     impl Storage for St {

          
@@ 185,7 196,59 @@ mod tests {
     }
 
     #[test]
-    fn it_works() {
-        assert_eq!(2 + 2, 4);
+    fn rect_finding_1() {
+        let s = St::new(16.0);
+        let mut g = Glif::new(s, 16.0);
+        let r1 = g.find_new_rect(1.0, 1.0).unwrap();
+        assert_eq!(
+            r1,
+            Rect {
+                x: 0.0,
+                y: 0.0,
+                w: 1.0,
+                h: 1.0
+            }
+        );
+
+        let r2 = g.find_new_rect(1.0, 1.0).unwrap();
+        assert_eq!(
+            r2,
+            Rect {
+                x: 1.0,
+                y: 0.0,
+                w: 1.0,
+                h: 1.0
+            }
+        );
+        let r3 = g.find_new_rect(10.0, 10.0).unwrap();
+        assert_eq!(
+            r3,
+            Rect {
+                x: 2.0,
+                y: 0.0,
+                w: 10.0,
+                h: 10.0
+            }
+        );
+        let r4 = g.find_new_rect(10.0, 10.0);
+        assert!(r4.is_none());
+
+        let r5 = g.find_new_rect(1.0, 1.0).unwrap();
+        assert_eq!(
+            r5,
+            Rect {
+                x: 12.0,
+                y: 0.0,
+                w: 1.0,
+                h: 1.0
+            }
+        );
+    }
+
+    #[test]
+    fn rect_nonsense_1() {
+        let s = St::new(16.0);
+        let mut g = Glif::new(s, 16.0);
+        assert!(g.find_new_rect(17.0, 17.0).is_none());
     }
 }