use crate::{ConfidenceFilter, GraphqlFilter, TextFilter};
use super::{
super::tests::{detection, label, score},
CONFIDENCE, Detection, DetectionFilter, LABEL,
};
#[test]
fn it_holds_the_word_and_the_number() {
let seen = detection("golden retriever", 0.87);
assert_eq!(seen.label().as_str(), "golden retriever");
assert_eq!(seen.confidence().get(), 0.87);
}
#[test]
fn the_constructor_checks_nothing_because_its_parts_already_did() {
const SEEN: fn(super::Label, crate::Score) -> Detection = Detection::new;
let _ = SEEN(label("cat"), score(1.0));
}
#[test]
fn it_spans_two_named_columns() {
assert_eq!(LABEL.as_str(), "label");
assert_eq!(
CONFIDENCE.as_str(),
"confidence",
"a detector's degree column is a CONFIDENCE — the word the sibling house left open, settled \
here on the type's own name"
);
let [word, degree] = <Detection as crate::ColumnKind>::SEGMENTS else {
panic!("a detection is a word and a number");
};
assert!(matches!(word, crate::ColumnShape::Plain(named) if named.declared().as_str() == "label"));
assert!(
matches!(degree, crate::ColumnShape::Plain(named) if named.declared().as_str() == "confidence")
);
}
#[test]
fn it_renders_the_pair() {
let seen = detection("cat", 0.5);
assert_eq!(seen.to_string(), "cat (0.5)");
assert_eq!(
format!("{seen:?}"),
r#"Detection { label: "cat", confidence: 0.5 }"#
);
}
#[test]
fn an_unset_filter_is_empty() {
assert!(DetectionFilter::new().is_empty());
assert!(GraphqlFilter::is_empty(&DetectionFilter::default()));
assert!(
DetectionFilter::new()
.with_label(TextFilter::new())
.is_empty(),
"a PRESENT facet with no operator set still asks nothing"
);
}
#[test]
fn a_set_facet_is_not_empty() {
let by_word = DetectionFilter::new().with_label(TextFilter::new().with_eq(label("cat")));
assert!(!by_word.is_empty());
let by_degree = DetectionFilter::new().with_confidence(
ConfidenceFilter::new()
.with_gte(crate::ConfidenceOperand::number(0.8).expect("a confidence operand")),
);
assert!(!by_degree.is_empty());
}
#[test]
fn the_facets_are_reachable_four_ways() {
let mut filter = DetectionFilter::new();
assert!(filter.label().is_none());
filter.set_label(TextFilter::new().with_eq(label("cat")));
assert!(filter.label().is_some());
let cleared = filter.clone().maybe_label(None::<TextFilter<_, _>>);
assert!(cleared.label().is_none());
filter.update_label(None::<TextFilter<_, _>>);
assert!(filter.label().is_none());
}
#[test]
fn the_readings_are_the_composite_and_the_quantified() {
use core::marker::PhantomData as P;
let _: P<crate::CompositeMarker<Detection>> = P::<<Detection as crate::DefaultMarker>::Marker>;
let _: P<crate::QuantifiedMarker<Vec<Detection>>> =
P::<<Detection as crate::DefaultVecMarker>::Marker>;
let _: P<DetectionFilter> = P::<<Detection as crate::CompositeFilterMarker>::Filter>;
}