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 set answer's own shape: the numbers are ATTRIBUTED, both of each pair are carried, and the
//! correspondence with the row a fold saw is a fact of one list rather than an invariant between
//! two.

use super::{Folded, StreamBest};

/// The three accessors, and the list that is this type's whole difference from
/// [`Ranked`](super::super::Ranked).
#[test]
fn a_folded_result_carries_a_sighting_per_query_vector() {
  let folded = Folded::new(
    1.25_f32,
    Box::new([
      Some(StreamBest::new(0.75_f32, 1)),
      None,
      Some(StreamBest::new(0.5_f32, 7)),
    ]),
    "clip",
  );

  assert!((folded.score() - 1.25).abs() < f32::EPSILON);
  assert_eq!(folded.streams().len(), 3);
  assert_eq!(folded.node(), "clip");

  let (score, streams, node) = folded.into_components();
  assert!((score - 1.25).abs() < f32::EPSILON);
  assert_eq!(
    streams.len(),
    3,
    "one slot per query vector, answered or not"
  );
  assert_eq!(node, "clip");
}

/// **THE SCORE THE FOLD READ IS CARRIED OUT WITH THE ORDINAL** — the widening's whole content, and
/// the reason it is worth having: `0.75 + 0.5` is the folded score, so the slots explain the number
/// they made, and no client has to re-ask an engine to see how.
#[test]
fn each_slot_carries_the_pre_fold_score_beside_the_ordinal() {
  let folded = Folded::new(
    1.25_f32,
    Box::new([
      Some(StreamBest::new(0.75_f32, 1)),
      None,
      Some(StreamBest::new(0.5_f32, 7)),
    ]),
    "clip",
  );

  let present: Vec<(f32, u64)> = folded
    .streams()
    .iter()
    .flatten()
    .map(|slot| (slot.score(), slot.ordinal()))
    .collect();
  assert_eq!(present, vec![(0.75, 1), (0.5, 7)]);
  assert!(
    (present.iter().map(|(score, _)| score).sum::<f32>() - folded.score()).abs() < f32::EPSILON,
    "the entries do not add up to the score they made",
  );
}

/// **A SUBSCRIPT READS ONE STREAM**, and a subscript past the end is the caller's own arithmetic
/// rather than a different kind of absence.
#[test]
fn the_subscript_reads_one_stream_and_absence_is_one_answer() {
  let folded = Folded::new(
    1.25_f32,
    Box::new([Some(StreamBest::new(0.75_f32, 1)), None]),
    "clip",
  );

  assert_eq!(folded.stream(0).map(StreamBest::ordinal), Some(1));
  assert_eq!(folded.stream(1).map(StreamBest::ordinal), None);
  assert_eq!(folded.stream(9).map(StreamBest::ordinal), None);
}

/// **NOTHING IS RE-DENSIFIED.** An ordinal is the engine's own 1-based position in ITS stream, so an
/// entity may stand 200th in one stream and first in another. Re-numbering would be the invented
/// global ordinal this type exists to refuse.
#[test]
fn the_ordinals_are_each_streams_own_and_are_not_renumbered() {
  let sparse = Folded::new(
    0.9_f32,
    Box::new([
      Some(StreamBest::new(0.1_f32, 200)),
      Some(StreamBest::new(0.8_f32, 1)),
    ]),
    "keyframes",
  );

  assert_eq!(
    sparse
      .streams()
      .iter()
      .map(|slot| slot.map(|best| best.ordinal()))
      .collect::<Vec<_>>(),
    vec![Some(200), Some(1)],
  );
}

/// **`map_node` CARRIES EVERY NUMBER ACROSS** — the one move a hydrating loop and a wire crossing
/// both make, so neither can pick a number up from somewhere else.
#[test]
fn mapping_the_node_carries_the_score_and_every_slot() {
  let folded = Folded::new(
    1.25_f32,
    Box::new([Some(StreamBest::new(0.75_f32, 1)), None]),
    "clip",
  );
  let carried = folded.clone().map_node(42_u32);

  assert_eq!(carried.node(), 42);
  assert!((carried.score() - folded.score()).abs() < f32::EPSILON);
  assert_eq!(carried.streams(), folded.streams());
}