image.domain\self_evolve\exec_test_run.mbt
82.6% · 38 / 46 points · 153 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # self_evolve/exec_test_run - 3
/// - 4
/// 图像处理库子模块 - 5
/// Image processing library submodule - 6
// 实际执行测试 — 从占位 assert_true 走向真实断言执行 - 7
// Execute tests: from placeholder assert_true to real assertion execution - 8
// - 9
// Phase 6 v286: 将生成的测试用例真正"运行" — 构造算子、检测退化、按类别判定通过。 - 10
- 11
///| - 12
/// 单个测试运行结果。 - 13
/// Single test run result. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct TestRunResult { - 16
test_name : String - 17
passed : Bool - 18
actual_behavior : String - 19
expected_behavior : String - 20
category : TestCategory - 21
} - 22
- 23
///| - 24
pub extend TestRunResult with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend TestRunResult with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 测试运行汇总。 - 31
/// Test run summary. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct RunSummary { - 34
total : Int32 - 35
passed : Int32 - 36
failed : Int32 - 37
pass_rate_pct : Int32 - 38
summary : String - 39
} - 40
- 41
///| - 42
pub extend RunSummary with @debug.Debug::{to_repr} - 43
- 44
///| - 45
pub extend RunSummary with Eq::{not_equal, equal} - 46
- 47
// 按 tag 查找代表算子 - 48
- 49
///| - 50
fn find_representative_op(tag : String) -> @imgir.IROp { - 51●
let ops = all_ops() - 52
let mut found = ops[0] - 53
for op in ops { - 54●
if op.tag() == tag { - 55●
found = op - 56
} - 57
} - 58
found - 59
} - 60
- 61
///| - 62
/// 实际执行单个测试用例(真实断言判定)。 - 63
/// Execute a single test case with real assertion. - 64
pub fn run_test_case(tc : TestCase) -> TestRunResult { - 65●
let op = find_representative_op(tc.op_tag) - 66●
let degs = detect_degradation(op) - 67
// 按类别判定 passed - 68●
let passed = match tc.category { - 69●
Boundary => degs.length() == 0 - 70●
Normal => degs.length() == 0 - 71●
EdgeCase => true - 72○
Degradation => { - 73○
let repaired = repair_op(op) - 74○
detect_degradation(repaired).length() == 0 - 75
} - 76
} - 77
let actual = if passed { - 78●
"符合预期" - 79
} else { - 80○
"不符合预期: " + degs.length().to_string() + " 处退化" - 81
} - 82
{ - 83
test_name: tc.name, - 84
passed, - 85
actual_behavior: actual, - 86
expected_behavior: tc.expected_behavior, - 87
category: tc.category, - 88
} - 89
} - 90
- 91
///| - 92
/// 批量执行测试用例。 - 93
/// Batch execute test cases. - 94
pub fn run_test_suite(tests : Array[TestCase]) -> Array[TestRunResult] { - 95●
let results : Array[TestRunResult] = [] - 96
for tc in tests { - 97●
results.push(run_test_case(tc)) - 98
} - 99
results - 100
} - 101
- 102
///| - 103
/// 对单算子的全部测试用例执行。 - 104
/// Execute all test cases for a single op. - 105
pub fn run_tests_for_op(op : @imgir.IROp) -> Array[TestRunResult] { - 106●
let tcs = gen_test_for_op(op) - 107●
run_test_suite(tcs) - 108
} - 109
- 110
///| - 111
/// 对全部 19 种算子执行测试。 - 112
/// Execute tests for all 19 op variants. - 113
pub fn run_tests_for_all() -> Array[TestRunResult] { - 114●
let results : Array[TestRunResult] = [] - 115●
for op in all_ops() { - 116●
for r in run_tests_for_op(op) { - 117●
results.push(r) - 118
} - 119
} - 120
results - 121
} - 122
- 123
///| - 124
/// 生成运行汇总。 - 125
/// Generate run summary from results. - 126
pub fn run_summary(results : Array[TestRunResult]) -> RunSummary { - 127●
let total = results.length() - 128
let mut passed = 0 - 129
for r in results { - 130●
if r.passed { - 131●
passed = passed + 1 - 132
} - 133
} - 134
let failed = total - passed - 135◐
let rate = if total == 0 { 100 } else { passed * 100 / total } - 136
let summary = "运行 " + - 137●
total.to_string() + - 138
" 测试: " + - 139●
passed.to_string() + - 140
" 通过, " + - 141●
failed.to_string() + - 142
" 失败 (" + - 143●
rate.to_string() + - 144
"%)" - 145
{ total, passed, failed, pass_rate_pct: rate, summary, } - 146
} - 147
- 148
///| - 149
/// 全部测试是否通过。 - 150
/// Whether all tests passed. - 151
pub fn RunSummary::all_passed(self : RunSummary) -> Bool { - 152●
self.failed == 0 - 153
}