Oregami
Repositories/oxedyne/ore

oxedyne/ore/oracle/tests/oracle.rs

2.4 KiB, 1 run

created by r2848102244:105, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Assertions over the three stages. Panics are the point: an oracle that
2//! passes quietly when the design is wrong is worse than no oracle.
3
4use ore_oracle::cases;
5use ore_oracle::doc::{
6 Bind,
7 Mode,
8};
9use ore_oracle::stage2;
10
11/// Every adversarial case meets its stated expectation under the repaired
12/// anchor binding, in both serious move modes.
13#[test]
14fn stage1_cases_meet_expectations() {
15 for mode in [Mode::ClaimRegister, Mode::SplitBeforeMove] {
16 let outs = match cases::all(mode, Bind::Successor) {
17 Ok(o) => o,
18 Err(e) => panic!("{:?} failed to run: {}", mode, e),
19 };
20 for o in &outs {
21 assert!(o.met(), "{:?} / {}: expected {:?}, got {:?}",
22 mode, o.name, o.expect, o.text);
23 }
24 }
25}
26
27/// The design note as written misplaces an insertion that abuts a moved range.
28/// This test records the defect; it does not excuse it.
29#[test]
30fn stage1_left_bias_misplaces_an_abutting_edit() {
31 let o = match cases::case_boundary_edits(Mode::ClaimRegister, Bind::LeftBias) {
32 Ok(o) => o,
33 Err(e) => panic!("case failed to run: {}", e),
34 };
35 assert_eq!(o.text, "- Milk\n>- Eggs\n- Cheese\n<",
36 "the LeftBias defect has changed shape; re-examine it");
37 assert!(!o.met());
38}
39
40/// The unarbitrated reduction duplicates the moved range, which is the anomaly
41/// Kleppmann's 2020 construction exists to remove.
42#[test]
43fn stage1_unarbitrated_split_before_move_duplicates() {
44 let o = match cases::case_identical_move(Mode::SplitBeforeMoveNaive, Bind::Successor) {
45 Ok(o) => o,
46 Err(e) => panic!("case failed to run: {}", e),
47 };
48 assert!(o.text.matches("- Milk").count() == 2, "expected a duplicate, got {:?}", o.text);
49 assert!(o.flags.duplicated > 0);
50}
51
52/// Every delivery order of a small operation set renders the same bytes.
53#[test]
54fn stage2_exhaustive_delivery_orders() {
55 for bind in [Bind::LeftBias, Bind::Successor] {
56 for mode in [Mode::ClaimRegister, Mode::SplitBeforeMove] {
57 for seed in 0..12u64 {
58 if let Err(e) = stage2::exhaustive(seed, mode, bind, 4, 4, true) {
59 panic!("{:?}/{:?} seed {}: {}", bind, mode, seed, e);
60 }
61 }
62 }
63 }
64}
65
66/// Randomised replicas converge and conserve every byte.
67#[test]
68fn stage2_randomised_trials() {
69 for bind in [Bind::LeftBias, Bind::Successor] {
70 for mode in [Mode::ClaimRegister, Mode::SplitBeforeMove] {
71 for seed in 0..20u64 {
72 if let Err(e) = stage2::trial(2000 + seed, mode, bind, 5, 10, 3, true) {
73 panic!("{:?}/{:?} seed {}: {}", bind, mode, seed, e);
74 }
75 }
76 }
77 }
78}