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
use super::*;
use crate::NormCoord;

fn page() -> DocumentSegment<NormCoord> {
  DocumentSegment::new(
    Quad::try_unit((0.10, 0.12), (0.90, 0.10), (0.92, 0.88), (0.08, 0.90))
      .expect("the fixture's corners are in frame"),
    Score::new(0.97).expect("the fixture's confidence is in range"),
  )
}

/// **NINE COLUMNS, ALL NINE OF THEM THE VALUE** — the trio's one citizen with no index leaf.
#[test]
fn a_segment_carries_no_index_leaf_at_all() {
  type Page = DocumentSegment<NormCoord>;

  assert_eq!(crate::width(<Page as ColumnKind>::SEGMENTS), 9);
  assert_eq!(
    crate::value_width(<Page as ColumnKind>::SEGMENTS),
    9,
    "a quad derives nothing, so a segment holding one derives nothing either"
  );
  assert!(
    <Page as ColumnKind>::ORDER.is_empty(),
    "…which is why it keeps the non-reordering word and states no sequence"
  );

  let names: Vec<_> = <Page as ColumnKind>::SEGMENTS
    .iter()
    .map(|segment| segment.field().expect("named").declared().as_str())
    .collect();
  assert_eq!(names, ["quad", "confidence"]);
}

/// **THE WINDING ORDER SURVIVES THE HOLDER**, which is the property a nine-column fan of one
/// storage word could lose without any type error.
#[test]
fn the_corners_keep_their_winding_order_beneath_the_segment() {
  let found = page();

  assert_eq!(
    found.quad().corners(),
    [
      crate::Point2::try_unit(0.10, 0.12).expect("in frame"),
      crate::Point2::try_unit(0.90, 0.10).expect("in frame"),
      crate::Point2::try_unit(0.92, 0.88).expect("in frame"),
      crate::Point2::try_unit(0.08, 0.90).expect("in frame"),
    ],
    "the third corner is diagonally opposite the first, not below it"
  );
}

/// **THE CURSOR ROUND TRIP**, framed rather than divided — a quad's own split is its component's
/// width times eight, which is a number no constant here can name.
#[test]
fn a_segment_round_trips_through_a_cursor_and_refuses_a_forged_one() {
  use crate::CursorValue as _;

  let found = page();
  let mut bytes = Vec::new();
  found.write_cursor(&mut bytes);

  assert_eq!(
    <DocumentSegment<NormCoord> as crate::CursorValue>::read_cursor(&bytes),
    Some(found)
  );
  assert_eq!(
    <DocumentSegment<NormCoord> as crate::CursorValue>::read_cursor(&bytes[..bytes.len() - 1]),
    None
  );
}

/// EMPTINESS descends through the QUAD's filter into a corner's and then into the component's.
#[test]
fn a_filter_is_empty_until_a_component_under_some_corner_is_set() {
  type Face = DocumentSegmentFilter<crate::ScalarFilter<NormCoord>>;

  assert!(crate::GraphqlFilter::is_empty(&Face::new()));
  assert!(crate::GraphqlFilter::is_empty(
    &Face::new().with_quad(QuadFilter::new())
  ));
  assert!(!crate::GraphqlFilter::is_empty(
    &Face::new().with_quad(
      QuadFilter::new().with_top_left(
        crate::Point2Filter::new()
          .with_x(crate::ScalarFilter::new().with_gte(NormCoord::new(0.5).expect("in range")))
      )
    )
  ));
}