#[path = "common/fixtures.rs"]
mod fixtures;
use fixtures::{facts, node_id, Shape, ALL_SHAPES, CLUSTER_SIZE, DENSE_SMALL_CAP};
use std::collections::HashSet;
const NODES: usize = 600;
const DEPTH: usize = 3;
#[test]
fn no_shape_emits_a_duplicate_ordered_pair() {
for &shape in ALL_SHAPES {
let edges = shape.edges(NODES);
let mut seen = HashSet::new();
for e in &edges {
assert!(
seen.insert((e.source.clone(), e.target.clone(), e.edge_type.clone())),
"{}: emits {} -> {} twice, which the single-open trigger rejects",
shape.name(),
e.source,
e.target
);
}
}
}
#[test]
fn every_edge_endpoint_is_a_seeded_concept() {
for &shape in ALL_SHAPES {
let ids: HashSet<String> = (0..NODES).map(node_id).collect();
for e in shape.edges(NODES) {
assert_ne!(e.source, e.target, "{}: self-loop", shape.name());
assert!(
ids.contains(&e.source),
"{}: dangling {}",
shape.name(),
e.source
);
assert!(
ids.contains(&e.target),
"{}: dangling {}",
shape.name(),
e.target
);
}
}
}
#[test]
fn every_shape_is_deterministic() {
for &shape in ALL_SHAPES {
let a = shape.edges(NODES);
let b = shape.edges(NODES);
assert_eq!(a.len(), b.len(), "{}: edge count varies", shape.name());
for (x, y) in a.iter().zip(b.iter()) {
assert_eq!(
(&x.source, &x.target),
(&y.source, &y.target),
"{}: edge set varies between calls",
shape.name()
);
}
}
}
#[test]
fn star_of_stars_is_a_tree_so_its_path_multiplier_is_one() {
let f = facts(Shape::StarOfStars, NODES, DEPTH);
assert_eq!(
f.simple_paths, f.reached,
"star_of_stars is no longer a tree: {f:?} — every pre-0.6.0 figure was \
taken on the tree, so changing it orphans the record"
);
assert!(
(f.path_multiplier() - 1.0).abs() < f64::EPSILON,
"expected multiplier 1.0, got {}",
f.path_multiplier()
);
assert!(
f.max_out_degree > NODES / 4,
"star_of_stars lost its hub: max out-degree {} over {} nodes",
f.max_out_degree,
NODES
);
}
#[test]
fn clustered_enumerates_far_more_paths_than_nodes() {
let f = facts(Shape::Clustered, NODES, DEPTH);
assert!(
f.path_multiplier() > 10.0,
"clustered stopped enumerating paths ({} paths for {} nodes, {:.1}x) — \
this is the shape T0.1 and D-076 exist for",
f.simple_paths,
f.reached,
f.path_multiplier()
);
assert!(
f.max_out_degree >= CLUSTER_SIZE - 1,
"clustered communities are no longer dense: max out-degree {}",
f.max_out_degree
);
}
#[test]
fn chain_is_deep_and_narrow() {
let f = facts(Shape::Chain, NODES, DEPTH);
assert!(
f.reached < 20,
"chain fans out: {} nodes reached in {DEPTH} hops",
f.reached
);
assert!(
f.max_out_degree <= 2,
"chain is branching: max out-degree {}",
f.max_out_degree
);
assert!(
f.edges >= NODES - 1,
"chain lost its spine: {} edges over {NODES} nodes",
f.edges
);
}
#[test]
fn dense_small_is_quadratic_and_capped() {
let f = facts(Shape::DenseSmall, 10_000, 2);
assert_eq!(
f.edges,
DENSE_SMALL_CAP * (DENSE_SMALL_CAP - 1),
"dense_small is no longer near-complete at its cap"
);
assert!(
f.max_out_degree == DENSE_SMALL_CAP - 1,
"dense_small node is not linked to every other: out-degree {}",
f.max_out_degree
);
assert_eq!(f.reached, DENSE_SMALL_CAP);
assert!(f.path_multiplier() > 100.0, "{:?}", f);
}
#[test]
fn the_matrix_discriminates() {
let all: Vec<_> = ALL_SHAPES
.iter()
.map(|&s| (s.name(), facts(s, NODES, DEPTH)))
.collect();
let star = &all[0].1;
let clustered = &all[1].1;
let chain = &all[2].1;
let dense = &all[3].1;
assert!(star.path_multiplier() < clustered.path_multiplier());
assert!(clustered.path_multiplier() < dense.path_multiplier());
assert!(star.max_out_degree > 10 * chain.max_out_degree);
for (name, f) in &all[..] {
if *name != "chain" {
assert!(
f.reached > chain.reached,
"{name} reaches {} nodes, no more than chain's {}",
f.reached,
chain.reached
);
}
}
}
const REGISTER: &str = include_str!("../docs/architecture/s13-decision-register.md");
const PERFORMANCE_DECISIONS: &[&str] = &[
"d-047", "d-055", "d-059", "d-063", "d-064", "d-070", "d-076", "d-086", "d-087", "d-088", ];
fn entry(id: &str) -> &'static str {
let anchor = format!("<a id=\"{id}\"></a>");
let start = REGISTER
.find(&anchor)
.unwrap_or_else(|| panic!("{id} is not in the decision register"));
let rest = ®ISTER[start + anchor.len()..];
match rest.find("\n<a id=\"d-") {
Some(end) => &rest[..end],
None => rest,
}
}
#[test]
fn every_performance_decision_names_its_fixture() {
for id in PERFORMANCE_DECISIONS {
let body = entry(id);
let named = ALL_SHAPES.iter().map(|s| s.name()).any(|n| {
body.contains(&format!("`{n}`")) || body.contains(&format!("`{}`", n.replace('_', "-")))
});
let opted_out = body.contains("**Fixture: none");
assert!(
named || opted_out,
"{id} draws a conclusion from a measurement and does not name the \
fixture it was taken on (T4.1, D-088). Add a `**Fixture: …**` line \
naming one of {:?} in backticks, or `**Fixture: none — …**` if it \
was not measured over a graph, or drop it from \
PERFORMANCE_DECISIONS if it is no longer a performance entry.",
ALL_SHAPES.iter().map(|s| s.name()).collect::<Vec<_>>()
);
}
}
#[test]
fn the_register_names_no_fixture_the_matrix_lacks() {
let known: Vec<String> = ALL_SHAPES
.iter()
.flat_map(|s| [s.name().to_string(), s.name().replace('_', "-")])
.collect();
for token in REGISTER.split('`').skip(1).step_by(2) {
let looks_like_a_fixture = token.contains('_')
&& token.len() > 4
&& token.chars().all(|c| c.is_ascii_lowercase() || c == '_')
&& token.starts_with(|c: char| c.is_ascii_lowercase());
if !looks_like_a_fixture {
continue;
}
if !known.iter().any(|k| k == token) && REGISTER.contains(&format!("fixture `{token}`")) {
panic!(
"the register calls `{token}` a fixture and the matrix has no such \
shape (T4.1, D-088). Known: {known:?}"
);
}
}
}