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::FusedScore;

/// The one value the constructor refuses, and the reason it is refused: it is the only `f64` for
/// which `partial_cmp` answers `None`, so admitting it would make [`Ord`] a lie.
#[test]
fn a_nan_is_refused_and_everything_else_is_admitted() {
  assert_eq!(FusedScore::new(f64::NAN), None);

  assert!(FusedScore::new(0.0).is_some());
  assert!(FusedScore::new(0.032_522_474_881_015_34).is_some());
  assert!(FusedScore::new(f64::INFINITY).is_some());
  assert!(FusedScore::new(f64::NEG_INFINITY).is_some());
}

/// `-0.0` is normalised on the way in, so two values that COMPARE equal cannot carry different bits
/// — the property a later [`Hash`](core::hash::Hash) impl would rest on, paid for at construction
/// rather than owed to it.
#[test]
fn negative_zero_is_normalised() {
  let minus = FusedScore::new(-0.0).expect("not a NaN");

  assert_eq!(minus, FusedScore::ZERO);
  assert_eq!(minus.get().to_bits(), 0.0_f64.to_bits());
}

/// The additive identity a fold's accumulator starts at.
#[test]
fn zero_is_the_bottom_of_the_answer() {
  let zero = FusedScore::ZERO;
  let any = FusedScore::new(1e-9).expect("not a NaN");

  assert_eq!(zero.get(), 0.0);
  assert!(zero < any);
}

/// The order is TOTAL, which is what the fold's descending sort spends: [`Ord`] is available at all,
/// so the sort key needs no comparator and never has to decide what an unordered pair means.
#[test]
fn the_order_is_total_and_descends_the_way_a_ranking_reads() {
  let mut scores: Vec<FusedScore> = [
    0.015_625,
    0.032_522_474_881_015_34,
    0.016_393_442_622_950_82,
  ]
  .into_iter()
  .map(|value| FusedScore::new(value).expect("not a NaN"))
  .collect();
  scores.sort_by(|a, b| b.cmp(a));

  assert_eq!(
    scores.iter().map(FusedScore::get).collect::<Vec<_>>(),
    vec![
      0.032_522_474_881_015_34,
      0.016_393_442_622_950_82,
      0.015_625
    ]
  );
}