image.domain\self_evolve\exec_test_gen.mbt
96.4% · 27 / 28 points · 136 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_gen - 3
/// - 4
/// 图像处理库子模块 - 5
/// Image processing library submodule - 6
// 可执行测试生成 — 从 TestCase 描述生成可运行 moon test 代码 - 7
// Executable test generation: from TestCase to runnable moon test code - 8
// - 9
// Phase 5 v281: 将 self_evolve 的测试用例描述转化为可执行的 moon test 代码字符串, - 10
// 使自演化从"描述"走向"执行"。 - 11
- 12
///| - 13
/// 单个可执行测试代码块。 - 14
/// Single executable test code block. - 15
#derive(Eq, @debug.Debug) - 16
pub(all) struct ExecutableTest { - 17
test_name : String - 18
code : String - 19
} - 20
- 21
///| - 22
pub extend ExecutableTest with @debug.Debug::{to_repr} - 23
- 24
///| - 25
pub extend ExecutableTest with Eq::{not_equal, equal} - 26
- 27
///| - 28
/// 可执行测试文件。 - 29
/// Executable test file. - 30
#derive(Eq, @debug.Debug) - 31
pub(all) struct ExecutableTestFile { - 32
file_header : String - 33
tests : Array[ExecutableTest] - 34
file_content : String - 35
} - 36
- 37
///| - 38
pub extend ExecutableTestFile with @debug.Debug::{to_repr} - 39
- 40
///| - 41
pub extend ExecutableTestFile with Eq::{not_equal, equal} - 42
- 43
// TestCategory 转字符串 - 44
- 45
///| - 46
fn test_category_str(cat : TestCategory) -> String { - 47●
match cat { - 48●
Boundary => "Boundary" - 49●
Normal => "Normal" - 50●
EdgeCase => "EdgeCase" - 51○
Degradation => "Degradation" - 52
} - 53
} - 54
- 55
///| - 56
/// 从单个 TestCase 生成可执行 moon test 代码。 - 57
/// Generate executable moon test code from a TestCase. - 58
pub fn gen_executable_test(tc : TestCase) -> ExecutableTest { - 59●
let name = "auto: " + tc.name - 60
let code = "///|\ntest \"" + - 61
name + - 62
"\" {\n // 算子: " + - 63
tc.op_tag + - 64
"\n // 类别: " + - 65●
test_category_str(tc.category) + - 66
"\n // 描述: " + - 67
tc.description + - 68
"\n // 输入: " + - 69
tc.input_spec + - 70
"\n // 期望: " + - 71
tc.expected_behavior + - 72
"\n assert_true(true) // 占位 — 需人工填充断言\n}" - 73
{ test_name: name, code, } - 74
} - 75
- 76
///| - 77
/// 批量生成可执行测试。 - 78
/// Batch generate executable tests. - 79
pub fn gen_executable_suite(tests : Array[TestCase]) -> Array[ExecutableTest] { - 80●
let result : Array[ExecutableTest] = [] - 81
for tc in tests { - 82●
result.push(gen_executable_test(tc)) - 83
} - 84
result - 85
} - 86
- 87
///| - 88
/// 从可执行测试列表生成完整文件内容。 - 89
/// Generate full file content from executable tests. - 90
pub fn gen_test_file_content(tests : Array[ExecutableTest]) -> String { - 91●
let header = "// 自动生成测试 — by self_evolve v281.0.0\n// Auto-generated tests — by self_evolve v281.0.0\n\n" - 92
let mut body = "" - 93
for t in tests { - 94●
body = body + "\n///|\n" + t.code + "\n" - 95
} - 96
header + body - 97
} - 98
- 99
///| - 100
/// 对单个算子生成完整可执行测试文件。 - 101
/// Generate full executable test file for a single op. - 102
pub fn gen_test_file_for_op(op : @imgir.IROp) -> ExecutableTestFile { - 103●
let test_cases = gen_test_for_op(op) - 104●
let exec_tests = gen_executable_suite(test_cases) - 105●
let content = gen_test_file_content(exec_tests) - 106
{ - 107●
file_header: "// 算子 " + op.tag() + " 自动生成测试", - 108
tests: exec_tests, - 109
file_content: content, - 110
} - 111
} - 112
- 113
///| - 114
/// 对全部 19 种算子生成可执行测试文件。 - 115
/// Generate executable test files for all 19 op variants. - 116
pub fn gen_test_file_for_all() -> Array[ExecutableTestFile] { - 117●
let result : Array[ExecutableTestFile] = [] - 118●
for op in all_ops() { - 119●
result.push(gen_test_file_for_op(op)) - 120
} - 121
result - 122
} - 123
- 124
///| - 125
/// 统计可执行测试文件中的测试数。 - 126
/// Count tests in an executable test file. - 127
pub fn ExecutableTestFile::test_count(self : ExecutableTestFile) -> Int32 { - 128●
self.tests.length() - 129
} - 130
- 131
///| - 132
/// 可执行测试文件是否非空。 - 133
/// Whether the executable test file is non-empty. - 134
pub fn ExecutableTestFile::is_non_empty(self : ExecutableTestFile) -> Bool { - 135●
self.tests.length() > 0 - 136
}