use super::super::*;
use super::common::*;
use std::sync::Arc;
use crate::algebra::{Algebra, kronecker, linear_an, radical_square_zero_cycle};
use crate::mutation::FacWitness;
#[test]
fn a_vertex_budget_equal_to_the_true_count_still_closes() {
let limits = MutationGraphLimits {
max_vertices: 5,
..MutationGraphLimits::default()
};
let outcome = support_tau_tilting_graph(&linear_an(2, f2()), &limits)
.expect("A_2 walks without a defect");
assert!(outcome.is_closed());
assert_eq!(outcome.closed().expect("closed").len(), 5);
let tight = MutationGraphLimits {
max_vertices: 4,
..MutationGraphLimits::default()
};
let outcome =
support_tau_tilting_graph(&linear_an(2, f2()), &tight).expect("A_2 walks without a defect");
let graph = outcome.incomplete().expect("four vertices are one too few");
match graph.reason() {
IncompleteReason::BudgetExhausted(diagnostics) => {
assert_eq!(diagnostics.limit(), GraphLimit::Vertices);
}
IncompleteReason::CertificationBlocked(blocker) => {
panic!("a vertex budget is no blocked certification: {blocker}")
}
}
}
#[test]
fn the_kronecker_walk_truncates_with_a_typed_budget() {
let limits = MutationGraphLimits {
max_vertices: 16,
..MutationGraphLimits::default()
};
let outcome = support_tau_tilting_graph(&kronecker(2, f2()), &limits)
.expect("the Kronecker walk runs without a defect");
assert!(!outcome.is_closed());
let graph = outcome.incomplete().expect("the walk stopped short");
let diagnostics = match graph.reason() {
IncompleteReason::BudgetExhausted(diagnostics) => diagnostics,
IncompleteReason::CertificationBlocked(blocker) => {
panic!("the Kronecker walk certifies every step it takes: {blocker}")
}
};
assert_eq!(diagnostics.limit(), GraphLimit::Vertices);
assert_eq!(diagnostics.vertices_found(), 16);
assert_eq!(graph.vertices_found().len(), 16);
assert!(diagnostics.open_slots() > 0);
assert!(diagnostics.work_units() > 0);
for vertex in graph.vertices_found() {
assert!(vertex.pair().verify());
assert_eq!(vertex.pair().summand_count(), 2);
}
for vertex in graph.vertices_found() {
for summand in vertex.pair().module().summands() {
let dim = summand.module().dim_vector();
assert!(dim[0] <= dim[1], "a preinjective summand {dim:?} appeared");
}
}
}
#[test]
fn the_work_unit_counts_stay_under_their_ceilings() {
let cases: [(&str, Arc<Algebra>, u64); 4] = [
("A_2", linear_an(2, f2()), 16_384),
("A_3", linear_an(3, f2()), 524_288),
("A_4", linear_an(4, f2()), 8_388_608),
("D_4", d4(f2()), 8_388_608),
];
for (name, algebra, ceiling) in cases {
let graph = walk(&algebra);
assert!(
graph.work_units() <= ceiling,
"{name}: {} units over the ceiling {ceiling}",
graph.work_units()
);
}
assert_eq!(
walk(&linear_an(3, f2())).work_units(),
walk(&linear_an(3, f5())).work_units()
);
}
#[test]
fn the_a2_walk_is_the_pentagon() {
for field in fields() {
let graph = walk(&linear_an(2, field));
assert_eq!(graph.len(), 5);
assert_eq!(graph.mutations().len(), 5);
let mut parts: Vec<(Vec<Vec<usize>>, Vec<u32>)> = graph
.pairs()
.map(|pair| {
(
pair.module().dim_vectors(),
pair.projective().vertices().to_vec(),
)
})
.collect();
parts.sort();
assert_eq!(
parts,
vec![
(vec![], vec![0, 1]),
(vec![vec![0, 1]], vec![0]),
(vec![vec![0, 1], vec![1, 1]], vec![]),
(vec![vec![1, 0]], vec![1]),
(vec![vec![1, 0], vec![1, 1]], vec![]),
]
);
let fac: Vec<&FacWitness> = graph
.vertices()
.iter()
.flat_map(|vertex| vertex.slots())
.filter_map(SlotRecord::fac_witness)
.collect();
assert_eq!(fac.len(), 1);
assert_eq!(fac[0].summand().dim_vector(), [1, 0]);
assert_eq!(fac[0].module().dim_vector(), [1, 1]);
assert_eq!(graph.vertices()[0].slots().len(), 2);
let minima = graph
.vertices()
.iter()
.filter(|vertex| vertex.pair().module().is_empty())
.count();
assert_eq!(minima, 1);
assert!(graph.mutations().iter().all(|edge| edge.target() != 0));
}
}
#[test]
fn two_runs_agree_on_order_and_witnesses() {
for field in fields() {
for algebra in [linear_an(3, field), radical_square_zero_cycle(3, field)] {
let first = walk(&algebra);
let second = walk(&algebra);
assert_eq!(render(&first), render(&second));
assert_eq!(first.work_units(), second.work_units());
}
}
}