image.domain\self_evolve\exec_test_run.mbt

82.6% · 38 / 46 points · 153 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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