#![allow(clippy::unwrap_used, clippy::expect_used)]
use prism::pipeline::{validate_constrained_type, ConstrainedTypeShape};
use prism::std_types::{
E6FiltrationShape, E7AugmentationShape, E8EmbeddingShape, F4QuotientShape, G2ProductShape,
RevocationShape, RouteShape,
};
macro_rules! assert_arity_exact {
($($n:literal),* $(,)?) => {$(
const _: () = assert!(
<G2ProductShape<$n> as ConstrainedTypeShape>::SITE_COUNT == 2 * $n
);
const _: () = assert!(
<F4QuotientShape<$n> as ConstrainedTypeShape>::SITE_COUNT == $n
);
const _: () = assert!(
<E6FiltrationShape<$n> as ConstrainedTypeShape>::SITE_COUNT == $n + 1
);
const _: () = assert!(
<E7AugmentationShape<$n> as ConstrainedTypeShape>::SITE_COUNT == $n
);
const _: () = assert!(
<E8EmbeddingShape<$n> as ConstrainedTypeShape>::SITE_COUNT == $n
);
)*};
}
assert_arity_exact!(
0, 1, 2, 3, 4, 7, 8, 16, 71, 73, 74, 80, 256, 4096, 65536, 1_048_576, 16_777_216,
);
#[test]
fn site_count_scales_linearly_with_no_clamp() {
const W: [usize; 6] = [71, 256, 4096, 65536, 1_048_576, 16_777_216];
const G: [usize; 6] = [
<G2ProductShape<71> as ConstrainedTypeShape>::SITE_COUNT,
<G2ProductShape<256> as ConstrainedTypeShape>::SITE_COUNT,
<G2ProductShape<4096> as ConstrainedTypeShape>::SITE_COUNT,
<G2ProductShape<65536> as ConstrainedTypeShape>::SITE_COUNT,
<G2ProductShape<1_048_576> as ConstrainedTypeShape>::SITE_COUNT,
<G2ProductShape<16_777_216> as ConstrainedTypeShape>::SITE_COUNT,
];
const F: [usize; 6] = [
<F4QuotientShape<71> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<256> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<4096> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<65536> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<1_048_576> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<16_777_216> as ConstrainedTypeShape>::SITE_COUNT,
];
const E6: [usize; 6] = [
<E6FiltrationShape<71> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<256> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<4096> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<65536> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<1_048_576> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<16_777_216> as ConstrainedTypeShape>::SITE_COUNT,
];
for i in 0..W.len() {
assert_eq!(
F[i], W[i],
"operand-preserving unary SITE_COUNT (F₄/E₇/E₈) must equal the width exactly"
);
assert_eq!(G[i], 2 * W[i], "product SITE_COUNT must equal 2× the width");
assert_eq!(
E6[i],
W[i] + 1,
"structure-preserving E₆ filtration SITE_COUNT must equal width + 1"
);
if i > 0 {
assert!(F[i] > F[i - 1], "SITE_COUNT must stay strictly monotone");
assert!(G[i] > G[i - 1], "no hidden plateau / clamp at scale");
assert!(
E6[i] > E6[i - 1],
"E₆ SITE_COUNT must stay strictly monotone"
);
}
}
}
macro_rules! admit_all_shapes_at {
($($n:literal),* $(,)?) => {$(
validate_constrained_type(G2ProductShape::<$n>)
.expect(concat!("G2ProductShape<", stringify!($n), "> admits"));
validate_constrained_type(F4QuotientShape::<$n>)
.expect(concat!("F4QuotientShape<", stringify!($n), "> admits"));
validate_constrained_type(E6FiltrationShape::<$n>)
.expect(concat!("E6FiltrationShape<", stringify!($n), "> admits"));
validate_constrained_type(E7AugmentationShape::<$n>)
.expect(concat!("E7AugmentationShape<", stringify!($n), "> admits"));
validate_constrained_type(E8EmbeddingShape::<$n>)
.expect(concat!("E8EmbeddingShape<", stringify!($n), "> admits"));
)*};
}
#[test]
fn composition_shapes_admit_at_every_scale() {
admit_all_shapes_at!(1, 71, 256, 4096, 65536, 1_048_576, 16_777_216);
}
#[test]
fn route_and_revocation_shapes_admit_at_every_scale() {
validate_constrained_type(RouteShape::<1, 1, 1, 1, 1>).expect("minimal route admits");
validate_constrained_type(RouteShape::<71, 32, 32, 71, 71>).expect("canonical route admits");
validate_constrained_type(RouteShape::<65536, 65536, 65536, 65536, 65536>)
.expect("64 KiB-per-component route admits");
validate_constrained_type(RouteShape::<1_048_576, 4096, 256, 1_048_576, 1_048_576>)
.expect("MiB-class route admits");
validate_constrained_type(RevocationShape::<1, 1, 1, 1, 1, 1>)
.expect("minimal revocation admits");
validate_constrained_type(RevocationShape::<71, 32, 32, 71, 71, 71>)
.expect("canonical revocation admits");
validate_constrained_type(
RevocationShape::<1_048_576, 4096, 256, 1_048_576, 1_048_576, 1_048_576>,
)
.expect("MiB-class revocation admits");
}
#[test]
fn route_site_count_is_exact_parametric_sum_at_scale() {
const CANON: usize = <RouteShape<71, 32, 32, 71, 71> as ConstrainedTypeShape>::SITE_COUNT;
const BIG: usize =
<RouteShape<1_048_576, 4096, 256, 1_048_576, 1_048_576> as ConstrainedTypeShape>::SITE_COUNT;
assert_eq!(CANON, 71 + 32 + 32 + 71 + 71);
assert_eq!(BIG, 1_048_576 + 4096 + 256 + 1_048_576 + 1_048_576);
}
#[test]
fn revocation_extends_route_by_revoked_width_at_scale() {
const ROUTE_BIG: usize =
<RouteShape<1_048_576, 4096, 256, 1_048_576, 1_048_576> as ConstrainedTypeShape>::SITE_COUNT;
const REV_BIG: usize = <RevocationShape<1_048_576, 4096, 256, 1_048_576, 1_048_576, 65536>
as ConstrainedTypeShape>::SITE_COUNT;
assert_eq!(REV_BIG, ROUTE_BIG + 65536);
}
#[test]
fn cycle_size_is_exact_below_the_saturation_threshold() {
assert_eq!(<F4QuotientShape<0> as ConstrainedTypeShape>::CYCLE_SIZE, 1);
assert_eq!(
<F4QuotientShape<1> as ConstrainedTypeShape>::CYCLE_SIZE,
256
);
assert_eq!(
<F4QuotientShape<2> as ConstrainedTypeShape>::CYCLE_SIZE,
65_536
);
assert_eq!(
<E8EmbeddingShape<7> as ConstrainedTypeShape>::CYCLE_SIZE,
72_057_594_037_927_936, );
assert_eq!(
<E6FiltrationShape<0> as ConstrainedTypeShape>::CYCLE_SIZE,
256
); assert_eq!(
<E6FiltrationShape<1> as ConstrainedTypeShape>::CYCLE_SIZE,
65_536
); assert_eq!(
<E6FiltrationShape<6> as ConstrainedTypeShape>::CYCLE_SIZE,
72_057_594_037_927_936, );
assert_eq!(<G2ProductShape<0> as ConstrainedTypeShape>::CYCLE_SIZE, 1);
assert_eq!(
<G2ProductShape<1> as ConstrainedTypeShape>::CYCLE_SIZE,
65_536
); assert_eq!(
<G2ProductShape<3> as ConstrainedTypeShape>::CYCLE_SIZE,
281_474_976_710_656, );
}
#[test]
fn cycle_size_saturates_at_and_above_the_threshold() {
assert_eq!(
<F4QuotientShape<8> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX
);
assert_eq!(
<E6FiltrationShape<7> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX
);
assert_eq!(
<E6FiltrationShape<71> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX
);
assert_eq!(
<E8EmbeddingShape<16_777_216> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX,
);
assert_eq!(
<G2ProductShape<4> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX
);
assert_eq!(
<G2ProductShape<1_048_576> as ConstrainedTypeShape>::CYCLE_SIZE,
u64::MAX,
);
}
const fn internal_g2_nodes(k: usize) -> usize {
k - 1
}
#[test]
fn arbitrary_arity_decomposes_into_iterated_binary_products() {
const N: usize = 71;
validate_constrained_type(G2ProductShape::<N>).expect("the binary product node admits once");
assert_eq!(internal_g2_nodes(2), 1);
assert_eq!(internal_g2_nodes(3), 2);
assert_eq!(internal_g2_nodes(8), 7);
assert_eq!(internal_g2_nodes(1_000_000), 999_999);
let arities = [2usize, 3, 8, 64, 4096, 1_000_000];
let mut prev = internal_g2_nodes(arities[0]);
for &k in &arities[1..] {
let nodes = internal_g2_nodes(k);
assert_eq!(nodes, k - 1);
assert!(nodes > prev, "node count must grow with arity, never clamp");
prev = nodes;
}
}
#[test]
fn distinct_widths_remain_distinct_shapes_at_scale() {
assert_ne!(
<F4QuotientShape<16_777_216> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<16_777_215> as ConstrainedTypeShape>::SITE_COUNT,
);
assert_ne!(
<E6FiltrationShape<16_777_216> as ConstrainedTypeShape>::SITE_COUNT,
<E6FiltrationShape<16_777_215> as ConstrainedTypeShape>::SITE_COUNT,
);
assert_ne!(
<E6FiltrationShape<71> as ConstrainedTypeShape>::SITE_COUNT,
<F4QuotientShape<71> as ConstrainedTypeShape>::SITE_COUNT,
);
assert_eq!(
<G2ProductShape<1> as ConstrainedTypeShape>::IRI,
<G2ProductShape<16_777_216> as ConstrainedTypeShape>::IRI,
);
assert_eq!(
<E6FiltrationShape<1> as ConstrainedTypeShape>::IRI,
<E6FiltrationShape<16_777_216> as ConstrainedTypeShape>::IRI,
);
assert_eq!(
<RouteShape<1, 1, 1, 1, 1> as ConstrainedTypeShape>::IRI,
<RouteShape<1_048_576, 4096, 256, 1_048_576, 1_048_576> as ConstrainedTypeShape>::IRI,
);
}