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::primitives::geometry::tests::{coord, point};

/// The unit-frame constructor adds NO rule of its own — it is two [`NormCoord::new`] calls under one
/// name — and this is where that is checked rather than assumed. A point has no sum to leave the
/// frame with, so there is nothing here for a second refusal to be about.
#[test]
fn a_unit_point_refuses_exactly_what_its_component_does() {
  assert!(Point2::try_unit(0.0, 0.0).is_ok());
  assert!(Point2::try_unit(1.0, 1.0).is_ok());
  assert!(Point2::try_unit(0.5, 0.5).is_ok());

  assert!(Point2::try_unit(1.5, 0.5).is_err());
  assert!(Point2::try_unit(0.5, -0.5).is_err());
  assert!(Point2::try_unit(f32::NAN, 0.5).is_err());
  assert!(Point2::try_unit(0.5, f32::INFINITY).is_err());
}

/// **The GENERIC holder checks NOTHING**, which is the family's ruling: a pixel position and a
/// metric one are both positions, and neither has an interval this crate knows about.
#[test]
fn the_generic_constructor_admits_what_no_unit_frame_would() {
  let pixels = Point2::new(4_096_u32, 2_160);
  assert_eq!(pixels.x(), 4_096);

  let metres = Point2::new(-12.5_f64, 900.25);
  assert_eq!(metres.y(), 900.25);
}

/// The component-wise carry, applied twice in field order.
#[test]
fn a_point_carries_both_components_through_one_function() {
  let pixels = point(0.25, 0.75).map(|component| (component.get() * 400.0) as u32);

  assert_eq!(pixels.x(), 100);
  assert_eq!(pixels.y(), 300);
}

/// **THE SEGMENT NAMES AND THEIR ORDER** — the bind pushes two placeholders in this order and the
/// decode fetches two names in it.
#[test]
fn a_point_names_its_two_columns_in_bind_order() {
  let names: Vec<_> = <Point2<NormCoord> as ColumnKind>::SEGMENTS
    .iter()
    .map(|segment| {
      segment
        .field()
        .expect("every segment here is named")
        .declared()
        .as_str()
    })
    .collect();

  assert_eq!(names, ["x", "y"]);
}

/// **THE CURSOR ROUND TRIP**, and the refusal a forged length earns.
#[test]
fn a_point_round_trips_through_a_cursor_and_refuses_a_forged_one() {
  let mut bytes = Vec::new();
  let written = point(0.25, 0.75);
  crate::CursorValue::write_cursor(&written, &mut bytes);

  assert_eq!(
    <Point2<NormCoord> as crate::CursorValue>::read_cursor(&bytes),
    Some(written)
  );

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

/// EMPTINESS is the conjunction of the two facets'.
#[test]
fn a_filter_is_empty_until_one_of_its_two_facets_is_set() {
  let bare = Point2Filter::<crate::ScalarFilter<NormCoord>>::new();
  assert!(crate::GraphqlFilter::is_empty(&bare));

  let asked = bare.with_y(crate::ScalarFilter::new().with_lt(coord(0.5)));
  assert!(!crate::GraphqlFilter::is_empty(&asked));
}