#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
use crate::corpus::registry::{CorpusFormat, Grade};
use crate::corpus::runner::{
ConvergenceEntry, CorpusResult, CorpusScore, FormatScore, RegressionReport,
};
#[test]
fn test_RUNNER_COV_001_parse_lcov_coverage_ratio_with_valid_data() {
let mut result = CorpusResult::default();
result.transpiled = true;
result.schema_valid = true;
result.coverage_ratio = 0.75;
let score = result.score();
assert!(
(score - 41.25).abs() < 0.01,
"Score should be 41.25, got {score}"
);
}
#[test]
fn test_RUNNER_COV_002_parse_lcov_full_coverage() {
let mut result = CorpusResult::default();
result.transpiled = true;
result.schema_valid = true;
result.coverage_ratio = 1.0;
let score = result.score();
assert!(
(score - 45.0).abs() < 0.01,
"Score should be 45.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_003_classify_error_syntax_error() {
let mut result = CorpusResult::default();
result.transpiled = false;
result.error = Some("parse error: unexpected token".to_string());
result.error_category = Some("syntax_error".to_string());
result.error_confidence = Some(0.5);
assert_eq!(result.error_category.as_deref(), Some("syntax_error"));
assert_eq!(result.error_confidence, Some(0.5));
assert_eq!(result.score(), 0.0);
}
#[test]
fn test_RUNNER_COV_004_classify_error_unsupported_construct() {
let mut result = CorpusResult::default();
result.transpiled = false;
result.error = Some("unsupported construct: dyn Trait".to_string());
result.error_category = Some("unsupported_construct".to_string());
result.error_confidence = Some(0.5);
assert_eq!(
result.error_category.as_deref(),
Some("unsupported_construct")
);
assert_eq!(result.score(), 0.0);
}
#[test]
fn test_RUNNER_COV_005_classify_error_type_error() {
let mut result = CorpusResult::default();
result.transpiled = false;
result.error = Some("type mismatch: expected String got i32".to_string());
result.error_category = Some("type_error".to_string());
result.error_confidence = Some(0.5);
assert_eq!(result.error_category.as_deref(), Some("type_error"));
}
#[test]
fn test_RUNNER_COV_006_classify_error_unknown() {
let mut result = CorpusResult::default();
result.transpiled = false;
result.error = Some("something completely unrecognized".to_string());
result.error_category = Some("unknown".to_string());
result.error_confidence = Some(0.5);
assert_eq!(result.error_category.as_deref(), Some("unknown"));
}
#[test]
fn test_RUNNER_COV_007_score_transpile_fail_is_zero() {
let result = CorpusResult {
transpiled: false,
..Default::default()
};
assert_eq!(result.score(), 0.0);
}
#[test]
fn test_RUNNER_COV_008_score_schema_invalid_is_zero() {
let result = CorpusResult {
transpiled: true,
schema_valid: false,
..Default::default()
};
assert_eq!(result.score(), 0.0);
}
#[test]
fn test_RUNNER_COV_009_score_b_l1_fail_l2_l3_zero() {
let result = CorpusResult {
transpiled: true,
schema_valid: true,
output_contains: false,
output_exact: true, output_behavioral: true, lint_clean: true,
deterministic: true,
..Default::default()
};
let score = result.score();
assert!(
(score - 50.0).abs() < 0.01,
"Score should be 50.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_010_score_b_l1_pass_l2_l3_pass() {
let result = CorpusResult {
transpiled: true,
schema_valid: true,
output_contains: true,
output_exact: true,
output_behavioral: true,
lint_clean: true,
deterministic: true,
metamorphic_consistent: true,
cross_shell_agree: true,
coverage_ratio: 1.0,
..Default::default()
};
let score = result.score();
assert!(
(score - 100.0).abs() < 0.01,
"Score should be 100.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_011_score_partial_output() {
let result = CorpusResult {
transpiled: true,
schema_valid: true,
output_contains: true,
output_exact: false,
output_behavioral: false,
..Default::default()
};
let score = result.score();
assert!(
(score - 40.0).abs() < 0.01,
"Score should be 40.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_012_score_metamorphic_and_cross_shell() {
let result = CorpusResult {
transpiled: true,
schema_valid: true,
output_contains: true,
metamorphic_consistent: true,
cross_shell_agree: true,
..Default::default()
};
let score = result.score();
assert!(
(score - 50.0).abs() < 0.01,
"Score should be 50.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_013_score_v1_transpile_fail() {
let result = CorpusResult {
transpiled: false,
..Default::default()
};
assert_eq!(result.score_v1(), 0.0);
}
#[test]
fn test_RUNNER_COV_014_score_v1_full_score() {
let result = CorpusResult {
transpiled: true,
output_contains: true,
coverage_ratio: 1.0,
lint_clean: true,
deterministic: true,
..Default::default()
};
let score = result.score_v1();
assert!(
(score - 100.0).abs() < 0.01,
"V1 score should be 100.0, got {score}"
);
}
#[test]
fn test_RUNNER_COV_015_score_v1_no_output_contains() {
let result = CorpusResult {
transpiled: true,
output_contains: false,
..Default::default()
};
assert!((result.score_v1() - 40.0).abs() < 0.01);
}
fn make_corpus_score(rate: f64, score: f64) -> CorpusScore {
CorpusScore {
total: 100,
passed: (rate * 100.0) as usize,
failed: ((1.0 - rate) * 100.0) as usize,
rate,
score,
grade: Grade::A,
format_scores: vec![
FormatScore {
format: CorpusFormat::Bash,
total: 80,
passed: 75,
rate: 0.9375,
score: 95.0,
grade: Grade::A,
},
FormatScore {
format: CorpusFormat::Makefile,
total: 20,
passed: 18,
rate: 0.9,
score: 88.0,
grade: Grade::B,
},
],
results: vec![],
}
}
#[test]
fn test_RUNNER_COV_016_gateway_met_when_rate_above_60() {
let score = make_corpus_score(0.75, 90.0);
assert!(score.gateway_met());
}
#[test]
fn test_RUNNER_COV_017_gateway_not_met_when_rate_below_60() {
let score = make_corpus_score(0.5, 40.0);
assert!(!score.gateway_met());
}
#[test]
fn test_RUNNER_COV_018_gateway_met_at_exactly_60() {
let score = make_corpus_score(0.60, 70.0);
assert!(score.gateway_met());
}
#[test]
fn test_RUNNER_COV_019_format_score_found() {
let cs = make_corpus_score(0.9, 92.0);
let bash_score = cs.format_score(CorpusFormat::Bash);
assert!(bash_score.is_some());
assert!((bash_score.unwrap().score - 95.0).abs() < 0.01);
}
#[test]
fn test_RUNNER_COV_020_format_score_not_found() {
let cs = make_corpus_score(0.9, 92.0);
let dockerfile_score = cs.format_score(CorpusFormat::Dockerfile);
assert!(dockerfile_score.is_none());
}
fn make_convergence(
score: f64,
passed: usize,
bash_passed: usize,
makefile_passed: usize,
dockerfile_passed: usize,
bash_score: f64,
makefile_score: f64,
dockerfile_score: f64,
lint_passed: usize,
) -> ConvergenceEntry {
ConvergenceEntry {
iteration: 1,
date: "2025-01-01".to_string(),
total: 100,
passed,
failed: 100 - passed,
rate: passed as f64 / 100.0,
delta: 0.0,
notes: String::new(),
bash_passed,
bash_total: 80,
makefile_passed,
makefile_total: 10,
dockerfile_passed,
dockerfile_total: 10,
score,
grade: "A+".to_string(),
bash_score,
makefile_score,
dockerfile_score,
lint_passed,
lint_rate: lint_passed as f64 / 100.0,
}
}
#[test]
include!("runner_coverage_tests_tests_RUNNER.rs");