use crate::{BoundingBox, BoundingBoxFilter, GraphqlFilter, NormCoord, ScalarFilter};
use super::{
super::tests::{detection, located},
BBOX, LocatedDetection, LocatedDetectionFilter,
};
#[test]
fn it_holds_the_classification_and_the_place() {
let subject = located();
assert_eq!(subject.detection(), &detection("person", 0.94));
assert_eq!(subject.label().as_str(), "person");
assert_eq!(subject.confidence().get(), 0.94);
assert_eq!(subject.bbox().x(), NormCoord::new(0.10).unwrap());
}
#[test]
fn the_geometry_component_is_open() {
let normalized = located();
assert_eq!(normalized.bbox().height().get(), 0.43);
let pixels = LocatedDetection::new(
detection("cat", 0.5),
BoundingBox::new(12_u32, 40, 200, 150),
);
assert_eq!(pixels.bbox().height(), 150);
let metres = LocatedDetection::new(
detection("car", 0.5),
BoundingBox::new(1.5_f64, 2.5, 4.0, 3.0),
);
assert_eq!(metres.bbox().width(), 4.0);
}
#[test]
fn the_box_is_named_bbox() {
assert_eq!(
BBOX.as_str(),
"bbox",
"`box` is a reserved word, so a declaration could not name a field after that column"
);
}
#[test]
fn an_unset_filter_is_empty() {
let empty = LocatedDetectionFilter::<ScalarFilter<NormCoord>>::new();
assert!(empty.is_empty());
assert!(GraphqlFilter::is_empty(&LocatedDetectionFilter::<
ScalarFilter<NormCoord>,
>::default()));
assert!(
empty.with_bbox(BoundingBoxFilter::new()).is_empty(),
"a PRESENT box facet with no operator set still asks nothing"
);
}
#[test]
fn either_half_makes_it_ask() {
let by_word = LocatedDetectionFilter::<ScalarFilter<NormCoord>>::new().with_detection(
super::super::DetectionFilter::new()
.with_label(crate::TextFilter::new().with_eq(super::super::tests::label("person"))),
);
assert!(!by_word.is_empty());
let by_place = LocatedDetectionFilter::new().with_bbox(
BoundingBoxFilter::new()
.with_x(ScalarFilter::<NormCoord>::new().with_gte(NormCoord::new(0.5).expect("in range"))),
);
assert!(!by_place.is_empty());
}
#[test]
fn the_readings_are_the_composite_and_the_quantified() {
use core::marker::PhantomData as P;
type Finding = LocatedDetection<NormCoord>;
let _: P<crate::CompositeMarker<Finding>> = P::<<Finding as crate::DefaultMarker>::Marker>;
let _: P<crate::QuantifiedMarker<Vec<Finding>>> =
P::<<Finding as crate::DefaultVecMarker>::Marker>;
let _: P<LocatedDetectionFilter<crate::PayloadFilter<NormCoord>>> =
P::<<Finding as crate::CompositeFilterMarker>::Filter>;
}
#[test]
fn it_debugs_both_halves() {
let rendered = format!("{:?}", located());
assert!(rendered.starts_with("LocatedDetection { detection: Detection {"));
assert!(rendered.contains("bbox: BoundingBox {"));
}