diff options
Diffstat (limited to 'src')
-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); } |