minerva 0.2.0

Causal ordering for distributed systems
//! The `Metatheses` wire frame suite (S272): the golden layout fixture,
//! the framing and canonical-form refusals, the representable-value
//! acceptances, and the round-trip, canonicality, and totality laws.

extern crate alloc;

use crate::kairos::Kairos;
use crate::metis::dot::RawDot;
use crate::metis::{Anchor, Dot, Locus, Metatheses, Metathesis};

/// Builds an identity literal. Panics on the non-dot counter zero (R-91).
#[track_caller]
fn d(station: u32, counter: u64) -> Dot {
    Dot::from_parts(station, counter).expect("test literal names the non-dot counter zero")
}

mod examples;
mod properties;

/// A rank with a known 17-byte frame: `Kairos::new(physical, 0, 1, 0)`,
/// whose `to_bytes` is `0x01` then the 16-byte big-endian payload (the
/// rhapsody suite's twin helper).
fn rank(physical: u64) -> Kairos {
    Kairos::new(physical, 0u16, 1, 0u16)
}

/// One testimony: `target` re-placed at `anchor` under `rank(tick)`.
fn testimony(target: (u32, u64), anchor: Anchor, tick: u64) -> Metathesis {
    Metathesis {
        target: target.into(),
        to: Locus {
            anchor,
            rank: rank(tick),
        },
    }
}

/// The two-row record behind the golden fixture: an origin re-placement
/// and an after-anchored one, testimony dots ascending across stations.
fn canonical_record() -> Metatheses {
    let mut record = Metatheses::new();
    assert!(record.insert(d(1, 3), testimony((1, 1), Anchor::Origin, 7)));
    assert!(record.insert(
        d(2, 1),
        testimony(
            (1, 1),
            Anchor::After(RawDot {
                station: 1,
                counter: 3
            }),
            9
        )
    ));
    record
}