extern crate std;
use super::{PREREGISTERED, is_preregistered, preregistration};
#[test]
fn ids_are_unique_and_sorted() {
let mut seen: std::vec::Vec<u32> = std::vec::Vec::new();
for p in PREREGISTERED {
let n: u32 =
p.id.strip_prefix("P-")
.and_then(|s| s.parse().ok())
.unwrap_or_else(|| panic!("{} is not of the form P-<number>", p.id));
assert!(!seen.contains(&n), "{} is registered twice", p.id);
if let Some(last) = seen.last() {
assert!(n > *last, "{} is out of order", p.id);
}
seen.push(n);
}
}
#[test]
fn every_registration_states_what_would_refute_it() {
for p in PREREGISTERED {
assert!(
p.hypothesis.len() > 40,
"{}: the hypothesis is too short to be a hypothesis",
p.id
);
assert!(
p.falsified_by.len() > 40,
"{}: no falsifier worth the name",
p.id
);
assert!(
!p.records.is_empty(),
"{}: an experiment that records nothing cannot be checked",
p.id
);
let well_formed = match p.ticket.split_once('-') {
Some((series, number)) => {
!series.is_empty()
&& series.chars().all(|c| c.is_ascii_alphabetic())
&& number.chars().next().is_some_and(|c| c.is_ascii_digit())
&& number.chars().all(|c| c.is_ascii_alphanumeric())
}
None => false,
};
assert!(well_formed, "{}: `{}` is not a ticket id", p.id, p.ticket);
}
}
#[test]
fn records_are_unique_within_a_registration() {
for p in PREREGISTERED {
for (i, a) in p.records.iter().enumerate() {
for b in &p.records[i + 1..] {
assert_ne!(a, b, "{}: `{a}` is listed twice", p.id);
}
}
}
}
#[test]
fn lookup_and_membership_agree() {
for p in PREREGISTERED {
assert!(is_preregistered(p.id));
assert_eq!(preregistration(p.id).hypothesis, p.hypothesis);
}
assert!(!is_preregistered("P-999"));
assert!(!is_preregistered("p-8"), "the check must be case sensitive");
assert!(!is_preregistered("P-8 "), "trailing space must not match");
assert!(!is_preregistered(""), "the empty id must not match");
}
#[test]
fn the_check_folds_at_compile_time() {
const _YES: () = assert!(is_preregistered("P-8"));
const _NO: () = assert!(!is_preregistered("P-999"));
}