image.domain\self_evolve\combo_coverage.mbt

94.7% · 36 / 38 points · 126 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/combo_coverage
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 组合测试覆盖 — 自动发现未覆盖算子组合,生成组合测试
  7. 7// Combo coverage: discover uncovered op combinations and generate combo tests
  8. 8//
  9. 9// Phase 6 v288: 将测试覆盖从"单算子"推向"二元组合" — 19×19 = 361 组合。
  10. 10
  11. 11///|
  12. 12/// 算子二元组合。
  13. 13/// 二值 Binary op combination.
  14. 14#derive(Eq, @debug.Debug)
  15. 15pub(all) struct OpCombo {
  16. 16 first_tag : String
  17. 17 second_tag : String
  18. 18 combo_desc : String
  19. 19}
  20. 20
  21. 21///|
  22. 22pub extend OpCombo with @debug.Debug::{to_repr}
  23. 23
  24. 24///|
  25. 25pub extend OpCombo with Eq::{not_equal, equal}
  26. 26
  27. 27///|
  28. 28/// 组合覆盖报告。
  29. 29/// 描述 Combo coverage report.
  30. 30#derive(Eq, @debug.Debug)
  31. 31pub(all) struct ComboCoverageReport {
  32. 32 total_combos : Int32
  33. 33 generated_tests : Int32
  34. 34 coverage_pct : Int32
  35. 35 summary : String
  36. 36}
  37. 37
  38. 38///|
  39. 39pub extend ComboCoverageReport with @debug.Debug::{to_repr}
  40. 40
  41. 41///|
  42. 42pub extend ComboCoverageReport with Eq::{not_equal, equal}
  43. 43
  44. 44///|
  45. 45/// 生成全部 19×19 二元组合。
  46. 46/// 生成 Generate all 19×19 binary combinations.
  47. 47pub fn gen_all_combos() -> Array[OpCombo] {
  48. 48● let ops = all_ops()
  49. 49 let combos : Array[OpCombo] = []
  50. 50 for op1 in ops {
  51. 51● for op2 in ops {
  52. 52● combos.push({
  53. 53● first_tag: op1.tag(),
  54. 54● second_tag: op2.tag(),
  55. 55● combo_desc: op1.tag() + " ∘ " + op2.tag(),
  56. 56 })
  57. 57 }
  58. 58 }
  59. 59 combos
  60. 60}
  61. 61
  62. 62///|
  63. 63/// 对全部二元组合生成测试用例。
  64. 64/// 生成 Generate test cases for all binary combinations.
  65. 65pub fn gen_combo_tests() -> Array[TestCase] {
  66. 66● let ops = all_ops()
  67. 67 let tests : Array[TestCase] = []
  68. 68 for op1 in ops {
  69. 69● for op2 in ops {
  70. 70● tests.push({
  71. 71● name: "combo: " + op1.tag() + "+" + op2.tag(),
  72. 72● op_tag: op1.tag() + "+" + op2.tag(),
  73. 73 category: Normal,
  74. 74● description: "二元组合 " + op1.tag() + " ∘ " + op2.tag(),
  75. 75 input_spec: "双算子管道",
  76. 76 expected_behavior: "无退化",
  77. 77 })
  78. 78 }
  79. 79 }
  80. 80 tests
  81. 81}
  82. 82
  83. 83///|
  84. 84/// 生成组合覆盖报告。
  85. 85/// 生成 Generate combo coverage report.
  86. 86pub fn combo_coverage_report() -> ComboCoverageReport {
  87. 87● let combos = gen_all_combos()
  88. 88● let tests = gen_combo_tests()
  89. 89● let total = combos.length()
  90. 90● let generated = tests.length()
  91. 91◐ let pct = if total == 0 { 100 } else { generated * 100 / total }
  92. 92 let summary = "组合覆盖: " +
  93. 93● total.to_string() +
  94. 94 " 组合, " +
  95. 95● generated.to_string() +
  96. 96 " 测试生成, " +
  97. 97● pct.to_string() +
  98. 98 "% 覆盖"
  99. 99 {
  100. 100 total_combos: total,
  101. 101 generated_tests: generated,
  102. 102 coverage_pct: pct,
  103. 103 summary,
  104. 104 }
  105. 105}
  106. 106
  107. 107///|
  108. 108/// 统计独特算子对(去重 first_tag+second_tag)。
  109. 109/// 计数 Count unique op pairs.
  110. 110pub fn unique_combo_count() -> Int32 {
  111. 111● let combos = gen_all_combos()
  112. 112 let tags : Array[String] = []
  113. 113 for c in combos {
  114. 114● let key = c.first_tag + "+" + c.second_tag
  115. 115 let mut found = false
  116. 116 for t in tags {
  117. 117● if t == key {
  118. 118○ found = true
  119. 119 }
  120. 120 }
  121. 121 if !found {
  122. 122● tags.push(key)
  123. 123 }
  124. 124 }
  125. 125● tags.length()
  126. 126}