22 lines
917 B
Rust
22 lines
917 B
Rust
use budget_capture::ocr::{pixel_count, recognize_argb, recognize_rgb};
|
|
|
|
#[test]
|
|
fn bundled_models_recognize_a_real_product_image() {
|
|
let image = image::load_from_memory(include_bytes!("fixtures/product.png")).unwrap().into_rgb8();
|
|
let text = recognize_rgb(image.as_raw(), image.width(), image.height()).unwrap();
|
|
assert!(text.contains("Wireless Mouse"), "{text}");
|
|
assert!(text.contains("249.99"), "{text}");
|
|
assert!(text.contains("ZAR"), "{text}");
|
|
}
|
|
#[test]
|
|
fn rejects_invalid_dimensions_and_buffers_before_inference() {
|
|
assert!(pixel_count(0, 1).is_err());
|
|
assert!(pixel_count(u32::MAX, u32::MAX).is_err());
|
|
assert!(recognize_rgb(&[0; 2], 1, 1).is_err());
|
|
assert!(recognize_argb(&[], 1, 1).is_err());
|
|
}
|
|
#[test]
|
|
fn blank_screen_does_not_invent_a_product() {
|
|
let text = recognize_argb(&vec![-1; 320 * 160], 320, 160).unwrap();
|
|
assert!(text.trim().is_empty(), "{text}");
|
|
}
|