use super::common::*;
use crate::context::VerificationContext;
use crate::profile::Site;
use crate::supporttau::{SupportTauTiltingPair, enumerate_over_catalog};
#[test]
fn the_pair_counts_agree_with_three_independent_sources() {
let expected = [4usize, 8, 16, 5, 14, 2, 14, 12];
for field in fields() {
let fixtures = catalog_fixtures(field);
assert_eq!(fixtures.len(), expected.len());
for ((name, algebra, _), count) in fixtures.iter().zip(expected) {
let graph = walk(algebra);
assert_eq!(graph.len(), count, "{name}");
assert_eq!(graph.pairs().len(), count, "{name}");
}
}
}
#[test]
fn the_d4_graph_has_fifty_pairs_and_the_published_histogram() {
for field in fields() {
let graph = walk(&d4(field));
assert_eq!(graph.len(), 50, "over F_{}", field.modulus());
assert_eq!(graph.histogram(), vec![1, 4, 9, 16, 20]);
assert_eq!(graph.mutations().len(), 100);
}
}
#[test]
fn a_d4_f5_closure_context_has_hits_and_misses() {
let _reset_guard = crate::profile::tests::reset_lock();
let graph = walk(&d4(f5()));
let without_fingerprints = graph.witness.fingerprints_without_context();
let primitive_calls = |counts: &[u64]| {
[
Site::HomDim,
Site::Tau,
Site::TauWithOpposite,
Site::EndoNew,
Site::Decompose,
Site::PairIso,
]
.into_iter()
.map(|site| counts[site as usize])
.sum::<u64>()
};
crate::profile::reset();
assert!(graph.witness.verify_without_context());
let without_counts = crate::profile::snapshot();
let without_distinct = crate::profile::distinct_snapshot();
let without_context = primitive_calls(&without_counts);
crate::profile::reset();
let context = VerificationContext::new();
assert!(graph.witness.verify_with_context(&context));
assert_eq!(
without_fingerprints,
graph.witness.fingerprints_with_context(&context)
);
let (hits, misses) = context.memo_stats();
assert!(hits > 0, "the context has no hit");
assert!(misses > 0, "the context has no miss");
let with_counts = crate::profile::snapshot();
let with_distinct = crate::profile::distinct_snapshot();
let with_context = primitive_calls(&with_counts);
if crate::profile::ENABLED {
let sites = [
Site::HomDim,
Site::Tau,
Site::TauWithOpposite,
Site::EndoNew,
Site::Decompose,
Site::PairIso,
];
eprintln!(
"D4/F5 context: memo hits {hits}, misses {misses}; primitive calls {without_context} -> {with_context}; distinct {:?} -> {:?}",
sites
.iter()
.map(|site| without_distinct[*site as usize])
.collect::<Vec<_>>(),
sites
.iter()
.map(|site| with_distinct[*site as usize])
.collect::<Vec<_>>()
);
assert!(
with_context < without_context,
"context made {with_context} primitive calls versus {without_context} uncached"
);
}
}
#[test]
fn the_walk_and_the_catalog_route_list_the_same_pairs() {
for field in fields() {
for (name, algebra, catalog) in catalog_fixtures(field) {
let graph = walk(&algebra);
let enumeration = enumerate_over_catalog(&catalog).expect("the catalog route runs");
let walked: Vec<&SupportTauTiltingPair> = graph.pairs().collect();
let listed: Vec<&SupportTauTiltingPair> = enumeration.pairs().iter().collect();
assert_eq!(walked.len(), listed.len(), "{name}");
assert!(same_pair_set(&walked, &listed), "{name}: walk into catalog");
assert!(same_pair_set(&listed, &walked), "{name}: catalog into walk");
}
}
}
#[test]
fn every_closed_graph_verifies_its_closure_witness() {
for field in fields() {
for (name, algebra, _) in catalog_fixtures(field) {
let graph = walk(&algebra);
assert!(graph.verify(), "{name}");
}
}
}