use super::*;
use crate::metis::dot::RawDot;
mod ledger;
mod refusals;
#[test]
fn a_verbatim_anchor_carry_flips_a_rank_contest_the_consignment_preserves() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(1)));
weave(
&mut text,
d(1, 2),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
rank(5),
),
);
let window_rank = Kairos::new(3, 0, 2, 0u16);
let birth = text_delta(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
window_rank,
),
);
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(1, &boundary, &[(2, 1)]);
let refounded = text.store().refound(&Metatheses::new()).unwrap();
let mut shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
shadow.deliver_text(&birth).unwrap();
let projection = shadow.projection().clone();
assert_eq!(projection.order(), [d(1, 1), d(1, 2), d(2, 1)]);
let mut verbatim = refounded.store().clone();
assert!(verbatim.weave(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1
}),
window_rank
)
));
assert_eq!(verbatim.order(), [d(1, 1), d(2, 1), d(1, 2)]);
let consignment = shadow.consign(&sealed).unwrap().0;
assert_eq!(consignment.text().store().order(), projection.order());
assert_eq!(consignment.moves().store().testimonies().count(), 0);
}
#[test]
fn the_old_world_move_verdict_crosses_baked_never_as_testimony() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(2)));
weave(&mut text, d(1, 2), locus(Anchor::Origin, rank(1)));
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(2, &boundary, &[(2, 2)]);
let refounded = text.store().refound(&Metatheses::new()).unwrap();
let testimony = movement(
d(2, 2),
(1, 1),
Anchor::After(RawDot {
station: 1,
counter: 2,
}),
rank(1),
);
let mut shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
shadow.deliver_moves(&testimony).unwrap();
assert_eq!(shadow.recension().refused(), []);
let projection = shadow.projection().clone();
assert_eq!(projection.order(), [d(1, 2), d(1, 1)]);
let translated = Metatheses::singleton(
d(2, 2),
Metathesis {
target: RawDot::new(1, 1),
to: locus(
Anchor::After(RawDot {
station: 1,
counter: 2,
}),
rank(1),
),
},
);
assert_eq!(
refounded.store().recension(&translated).refused(),
[d(2, 2)]
);
let consignment = shadow.consign(&sealed).unwrap().0;
assert_eq!(consignment.text().store().order(), projection.order());
assert_eq!(consignment.moves().store().testimonies().count(), 0);
assert!(consignment.moves().context().contains(d(2, 2)));
}
#[test]
fn the_consignment_carries_births_moves_and_deletes_whole() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(3)));
weave(&mut text, d(1, 2), locus(Anchor::Origin, rank(2)));
weave(&mut text, d(1, 3), locus(Anchor::Origin, rank(1)));
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(1, &boundary, &[(2, 1), (2, 2), (2, 3)]);
let mut shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
let birth = text_delta(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
Kairos::new(9, 0, 2, 0u16),
),
);
shadow.deliver_text(&birth).unwrap();
let mut removal = DotSet::new();
assert!(removal.insert(d(2, 2)));
assert!(removal.insert(d(1, 2)));
shadow.deliver_text(&Dotted::from_context(removal)).unwrap();
let moved = movement(d(2, 3), (1, 3), Anchor::Origin, Kairos::new(11, 0, 2, 0u16));
shadow.deliver_moves(&moved).unwrap();
let projection = shadow.projection().clone();
assert_eq!(projection.order(), [d(1, 3), d(1, 1), d(2, 1)]);
let consignment = shadow.consign(&sealed).unwrap().0;
let base = consignment.text().store();
assert_eq!(base.order(), projection.order());
assert!(base.locus(d(1, 2)).is_some());
assert!(!base.is_visible(d(1, 2)));
let mut native = base.clone();
assert!(native.weave(
d(3, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 2
}),
rank(9)
)
));
assert_eq!(native.order(), [d(1, 3), d(1, 1), d(2, 1), d(3, 1)]);
assert_eq!(consignment.text().context(), consignment.moves().context());
let floor = consignment.text().context().floor();
assert_eq!(floor.get(1), 4);
assert_eq!(floor.get(2), 3);
assert!(consignment.moves().context().contains(d(2, 1)));
assert!(consignment.moves().context().contains(d(2, 3)));
assert!(consignment.text().context().contains(d(2, 2)));
}
#[test]
fn the_consignment_reads_identically_in_both_arrival_orders() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(2)));
weave(&mut text, d(1, 2), locus(Anchor::Origin, rank(1)));
let boundary = Cut::floor_of(text.context());
let birth = text_delta(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
Kairos::new(7, 0, 2, 0u16),
),
);
let moved = movement(d(2, 2), (1, 2), Anchor::Origin, Kairos::new(8, 0, 2, 0u16));
let mut consignments = Vec::new();
for reversed in [false, true] {
let (adopted, sealed) = seal_mill(1, &boundary, &[(2, 1), (2, 2)]);
let mut shadow = EpochStratum::new(&adopted, text.clone(), Moves::new())
.unwrap()
.into_transition()
.shadow;
if reversed {
shadow.deliver_moves(&moved).unwrap();
shadow.deliver_text(&birth).unwrap();
} else {
shadow.deliver_text(&birth).unwrap();
shadow.deliver_moves(&moved).unwrap();
}
consignments.push(shadow.consign(&sealed).unwrap().0);
}
assert_eq!(
consignments[0].text().store().to_bytes(),
consignments[1].text().store().to_bytes()
);
assert_eq!(
consignments[0].text().context(),
consignments[1].text().context()
);
assert_eq!(
consignments[0].moves().context(),
consignments[1].moves().context()
);
}
#[test]
fn a_window_dead_birth_crosses_as_context_only() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(1)));
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(1, &boundary, &[(2, 1), (2, 2)]);
let mut shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
let birth = text_delta(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
Kairos::new(5, 0, 2, 0u16),
),
);
shadow.deliver_text(&birth).unwrap();
let mut removal = DotSet::new();
assert!(removal.insert(d(2, 2)));
assert!(removal.insert(d(2, 1)));
shadow.deliver_text(&Dotted::from_context(removal)).unwrap();
let consignment = shadow.consign(&sealed).unwrap().0;
assert_eq!(consignment.text().store().order(), [d(1, 1)]);
assert!(consignment.text().store().locus(d(2, 1)).is_none());
assert!(consignment.text().context().contains(d(2, 1)));
assert!(consignment.text().context().contains(d(2, 2)));
}
#[test]
fn a_dead_at_cut_identity_does_not_cross_the_consignment() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(2)));
weave(
&mut text,
d(1, 2),
locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
rank(1),
),
);
weave(
&mut text,
d(2, 1),
locus(
Anchor::After(RawDot {
station: 1,
counter: 2,
}),
rank(1),
),
);
remove(&mut text, d(2, 1));
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(1, &boundary, &[]);
let shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
let consignment = shadow.consign(&sealed).unwrap().0;
assert_eq!(consignment.text().store().order(), [d(1, 1), d(1, 2)]);
assert_eq!(consignment.text().store().skeleton_len(), 2);
assert!(!consignment.text().context().contains(d(2, 1)));
assert_eq!(consignment.text().context().floor().get(2), 0);
}
#[test]
fn a_ceiling_image_does_not_overflow_the_chain_guard() {
let mut text = Rhapsody::new();
assert!(text.weave(d(2, u64::MAX), locus(Anchor::Origin, rank(5))));
assert!(text.weave(
d(2, 1),
locus(
Anchor::After(RawDot {
station: 2,
counter: u64::MAX
}),
rank(1)
)
));
let map = Rhapsody::new()
.refound(&Metatheses::new())
.unwrap()
.map()
.clone();
let store = text
.recension(&Metatheses::new())
.consign_store(&map)
.unwrap();
assert_eq!(store.order(), [d(2, u64::MAX), d(2, 1)]);
}
#[test]
fn a_window_move_can_flip_a_native_move_verdict_hence_the_deferral_duty() {
let mut text = Text::new();
weave(&mut text, d(1, 1), locus(Anchor::Origin, rank(2)));
weave(&mut text, d(1, 2), locus(Anchor::Origin, rank(1)));
let boundary = Cut::floor_of(text.context());
let (adopted, sealed) = seal_mill(1, &boundary, &[(2, 1)]);
let refounded = text.store().refound(&Metatheses::new()).unwrap();
let native = Metatheses::singleton(
d(2, 5),
Metathesis {
target: RawDot::new(1, 2),
to: locus(
Anchor::After(RawDot {
station: 1,
counter: 1,
}),
Kairos::new(9, 0, 2, 0u16),
),
},
);
assert_eq!(refounded.store().recension(&native).refused(), []);
let mut shadow = EpochStratum::new(&adopted, text, Moves::new())
.unwrap()
.into_transition()
.shadow;
shadow
.deliver_moves(&movement(
d(2, 1),
(1, 1),
Anchor::After(RawDot {
station: 1,
counter: 2,
}),
rank(1),
))
.unwrap();
let consignment = shadow.consign(&sealed).unwrap().0;
assert_eq!(consignment.text().store().order(), [d(1, 2), d(1, 1)]);
assert_eq!(
consignment.text().store().recension(&native).refused(),
[d(2, 5)]
);
}