diff options
author | cc <cc@localhost> | 2025-08-25 22:49:13 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-25 22:49:51 -0700 |
commit | 6b82dd150073836e57a148d7eccae5276b9baea7 (patch) | |
tree | d87c35b73754f1393ad9d5a673384d71b46a38f3 | |
parent | d160ef855a642f27a0e472b12f5df3cb3dfe43c6 (diff) |
Add expectation assertions
Remove test echos
-rw-r--r-- | src/label_format.rs | 120 |
1 files changed, 101 insertions, 19 deletions
diff --git a/src/label_format.rs b/src/label_format.rs index 68efda4..38c5d19 100644 --- a/src/label_format.rs +++ b/src/label_format.rs @@ -275,16 +275,43 @@ mod tests { height: DIM, }; + let expected: [Vec<u16>;3] = [ + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 1, 1, 1, 2, 2, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + ]; + test_data.buffer[2+3*DIM] = 1; test_data.buffer[3+3*DIM] = 1; test_data.buffer[4+3*DIM] = 2; - test_data.display(); - println!(); + assert_eq!(test_data.buffer, expected[0]); + let dilated = test_data.dilate(); - dilated.display(); - println!(); + assert_eq!(dilated.buffer, expected[1]); + let restored = dilated.erode(); - restored.display(); + assert_eq!(restored.buffer, expected[2]); } #[test] @@ -296,17 +323,43 @@ mod tests { height: DIM, }; + let expected: [Vec<u16>;3] = [ + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 1, 1, 1, 2, 2, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + ]; + test_data.buffer[2+3*DIM] = 1; test_data.buffer[3+3*DIM] = 1; test_data.buffer[4+3*DIM] = 2; - test_data.display(); - println!(); + assert_eq!(test_data.buffer, expected[0]); + test_data.idilate(); - test_data.display(); - println!(); + assert_eq!(test_data.buffer, expected[1]); + test_data.ierode(); - test_data.display(); - println!(); + assert_eq!(test_data.buffer, expected[2]); } #[test] @@ -318,11 +371,44 @@ mod tests { height: DIM, }; + let expected: [Vec<u16>;4] = [ + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 2, 3, 0, + 0, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 2, 3, 0, + 0, 0, 0, 2, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + [ + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 2, 0, + 0, 0, 0, 1, 0, 0, + 0, 0, 3, 3, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ].to_vec(), + ]; + test_data_1.buffer[2+3*DIM] = 1; test_data_1.buffer[3+3*DIM] = 1; test_data_1.buffer[4+3*DIM] = 2; - test_data_1.display(); - println!(); let mut test_data_2 = LabelFormat { buffer: vec![0u16; DIM*DIM], @@ -334,16 +420,12 @@ mod tests { test_data_2.buffer[3+1*DIM] = 2; test_data_2.buffer[3+2*DIM] = 2; test_data_2.buffer[4+1*DIM] = 3; - test_data_2.display(); - println!(); if let Some(out_data) = test_data_1.combine(&test_data_2) { - out_data.display(); - println!(); + assert_eq!(out_data.buffer, expected[2]); let refreshed = out_data.refresh(); - refreshed.display(); - println!(); + assert_eq!(refreshed.buffer, expected[3]); } else { assert!(false); } |