ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! The finding WITH a place: the required box, the geometry parameter, and the filter's three
//! facets.

use crate::{BoundingBox, BoundingBoxFilter, GraphqlFilter, NormCoord, ScalarFilter};

use super::{
  super::tests::{detection, located},
  BBOX, LocatedDetection, LocatedDetectionFilter,
};

/// All three parts survive the pairing, and the two shortcuts reach the classification's without
/// naming it.
#[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());
}

/// **THE COMPONENT IS THE CALLER'S** — the same shape in three worlds, none of them named by this
/// type.
#[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);
}

/// The box's segment name, pinned — four columns hang off it.
#[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"
  );
}

/// **The EMPTY filter asks nothing**, and all three facets are why.
#[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"
  );
}

/// Either half being set makes the whole filter ask something — which is what makes the three guard
/// ONE finding rather than three independent questions.
#[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());
}

/// **The COMPOSITE reading and the QUANTIFIED one**, pinned as type equalities — and the filter is
/// resolved through the framework's general payload alias rather than a second expression.
#[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>;
}

/// The renderings, with both halves under their own names.
#[test]
fn it_debugs_both_halves() {
  let rendered = format!("{:?}", located());

  assert!(rendered.starts_with("LocatedDetection { detection: Detection {"));
  assert!(rendered.contains("bbox: BoundingBox {"));
}