use super::*;
#[test]
fn falsify_rouge1_known_value() {
let score = rouge_n("a b c d", "a b e f", 1);
assert!((score - 0.5).abs() < 1e-10, "ROUGE-1 F1 should be 0.5, got {score}");
}
#[test]
fn falsify_rouge1_asymmetric_lengths() {
let score = rouge_n("a b c", "a", 1);
assert!(
(score - 0.5).abs() < 1e-10,
"ROUGE-1 with asymmetric lengths should be 0.5, got {score}"
);
}
#[test]
fn falsify_rouge_n_is_symmetric() {
let r1 = rouge_n("a b c", "a b d", 1);
let r2 = rouge_n("a b d", "a b c", 1);
assert!((r1 - r2).abs() < 1e-10, "ROUGE-1 F1 should be symmetric: {r1} vs {r2}");
}
#[test]
fn falsify_rouge2_known_value() {
let score = rouge_n("a b c d", "a b c e", 2);
assert!((score - 2.0 / 3.0).abs() < 1e-10, "ROUGE-2 F1 should be 2/3, got {score}");
}
#[test]
fn falsify_rouge_l_known_value() {
let score = rouge_l("a b c d e", "a x b c y");
assert!((score - 0.6).abs() < 1e-10, "ROUGE-L F1 should be 0.6, got {score}");
}
#[test]
fn falsify_rouge_l_subsequence_not_substring() {
let score = rouge_l("a x b x c", "a b c");
assert!((score - 0.75).abs() < 1e-10, "ROUGE-L should use subsequence, got {score}");
}
#[test]
fn falsify_rouge_l_geq_rouge2() {
let r2 = rouge_n(
"the quick brown fox jumps over the lazy dog",
"the quick brown cat jumps over the lazy dog",
2,
);
let rl = rouge_l(
"the quick brown fox jumps over the lazy dog",
"the quick brown cat jumps over the lazy dog",
);
assert!(rl >= r2 - 1e-10, "ROUGE-L should be >= ROUGE-2 for long sequences: RL={rl}, R2={r2}");
}
#[test]
fn falsify_perplexity_known_binary() {
let log_probs = vec![(0.5f64).ln(); 100];
let ppl = perplexity(&log_probs);
assert!((ppl - 2.0).abs() < 1e-10, "Binary uniform → PPL=2.0, got {ppl}");
}
#[test]
fn falsify_perplexity_single_token() {
let ppl = perplexity(&[(0.01f64).ln()]);
assert!((ppl - 100.0).abs() < 1e-6, "Single token p=0.01 → PPL=100, got {ppl}");
}
#[test]
fn falsify_perplexity_positive_log_probs() {
let ppl = perplexity(&[1.0, 2.0, 3.0]);
assert!(ppl < 1.0, "Positive log-probs → PPL < 1.0 (invalid but computable), got {ppl}");
}
#[test]
fn falsify_perplexity_mixed_values() {
let log_probs = vec![(0.9f64).ln(), (0.01f64).ln()];
let ppl = perplexity(&log_probs);
let expected = (1.0 / (0.9 * 0.01f64)).sqrt();
assert!((ppl - expected).abs() < 1e-6, "Mixed PPL: expected {expected}, got {ppl}");
}