minerva 0.2.0

Causal ordering for distributed systems
use super::super::super::super::support::dot;
use super::have;
use crate::metis::DotSet;

/// A known have-set with a run of two, a singleton run, and a run-free station,
/// frozen byte-for-byte (PRD 0016). Station 1 holds `1..=3` (floor 3) plus the
/// out-of-order dots `5, 6, 8` (a hole at 4 and 7), which compress to the runs
/// `(5, 2)` and `(8, 1)`. Station 2 holds `1..=2` (floor 2) with no exceptions.
#[test]
fn test_have_set_to_bytes_layout() {
    let set = have(&[
        (1, 1),
        (1, 2),
        (1, 3),
        (1, 5),
        (1, 6),
        (1, 8),
        (2, 1),
        (2, 2),
    ]);
    let frame = set.to_bytes();
    assert!(set.exceptions().eq([dot(1, 5), dot(1, 6), dot(1, 8)]));
    assert_eq!(
        frame,
        [
            0x01, // version
            0x00, 0x00, 0x00, 0x02, // station_count = 2
            // station 1
            0x00, 0x00, 0x00, 0x01, // station_id = 1
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // floor = 3
            0x00, 0x00, 0x00, 0x02, // run_count = 2
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, // run start = 5
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // run len = 2
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, // run start = 8
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // run len = 1
            // station 2
            0x00, 0x00, 0x00, 0x02, // station_id = 2
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // floor = 2
            0x00, 0x00, 0x00, 0x00, // run_count = 0
        ]
    );
    // The frame round-trips to the same value.
    assert_eq!(DotSet::from_bytes(&frame), Ok(set));
}

/// The empty have-set (lattice bottom) is the five-byte header with a zero
/// station count, and it round-trips.
#[test]
fn test_have_set_empty_frame() {
    let frame = DotSet::new().to_bytes();
    assert_eq!(frame, [0x01u8, 0x00, 0x00, 0x00, 0x00]);
    assert_eq!(DotSet::from_bytes(&frame), Ok(DotSet::new()));
}