image.domain\self_evolve\adaptive.mbt
88.9% · 32 / 36 points · 156 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/adaptive - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 自适应测试策略 — 根据覆盖率自动调整测试优先级 - 7
// Adaptive test strategy: auto-adjust test priority based on coverage - 8
// - 9
// Phase 7 v292: 将测试生成从"均匀"推向"自适应" — 低覆盖算子优先。 - 10
- 11
///| - 12
/// 测试优先级。 - 13
/// 描述 Test priority level. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum TestPriority { - 18
HighPriority - 19
MediumPriority - 20
LowPriority - 21
} - 22
- 23
///| - 24
pub extend TestPriority with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend TestPriority with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 单算子自适应策略。 - 31
/// 自适应 Adaptive strategy for a single op. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct AdaptiveStrategy { - 34
op_tag : String - 35
current_coverage : Int32 - 36
priority : TestPriority - 37
suggested_tests : Int32 - 38
} - 39
- 40
///| - 41
pub extend AdaptiveStrategy with @debug.Debug::{to_repr} - 42
- 43
///| - 44
pub extend AdaptiveStrategy with Eq::{not_equal, equal} - 45
- 46
///| - 47
/// 自适应报告。 - 48
/// 自适应 Adaptive report. - 49
#derive(Eq, @debug.Debug) - 50
pub(all) struct AdaptiveReport { - 51
strategies : Array[AdaptiveStrategy] - 52
total_prioritized : Int32 - 53
high_priority_count : Int32 - 54
summary : String - 55
} - 56
- 57
///| - 58
pub extend AdaptiveReport with @debug.Debug::{to_repr} - 59
- 60
///| - 61
pub extend AdaptiveReport with Eq::{not_equal, equal} - 62
- 63
///| - 64
/// 根据覆盖度建议测试数量。 - 65
/// 描述 Suggest test count based on coverage (0-100). - 66
pub fn suggest_test_count(coverage : Int32) -> Int32 { - 67●
if coverage >= 80 { - 68●
2 - 69●
} else if coverage >= 50 { - 70●
5 - 71●
} else if coverage >= 25 { - 72●
8 - 73
} else { - 74●
12 - 75
} - 76
} - 77
- 78
///| - 79
/// 根据覆盖度判定优先级。 - 80
/// 描述 Determine priority based on coverage. - 81
pub fn priority_from_coverage(coverage : Int32) -> TestPriority { - 82●
if coverage >= 50 { - 83●
LowPriority - 84●
} else if coverage >= 25 { - 85●
MediumPriority - 86
} else { - 87●
HighPriority - 88
} - 89
} - 90
- 91
///| - 92
/// 分析单算子自适应策略。 - 93
/// 描述 Analyze adaptive strategy for a single op. - 94
pub fn adaptive_strategy(op : @imgir.IROp) -> AdaptiveStrategy { - 95●
let degs = detect_degradation(op) - 96●
let coverage = if degs.length() == 0 { - 97●
100 - 98
} else { - 99●
100 / (degs.length() + 1) - 100
} - 101●
let priority = priority_from_coverage(coverage) - 102●
let suggested = suggest_test_count(coverage) - 103
{ - 104●
op_tag: op.tag(), - 105
current_coverage: coverage, - 106
priority, - 107
suggested_tests: suggested, - 108
} - 109
} - 110
- 111
///| - 112
/// 对全部 19 种算子分析自适应策略。 - 113
/// 描述 Analyze adaptive strategy for all 19 ops. - 114
pub fn adaptive_strategy_all() -> AdaptiveReport { - 115●
let strategies : Array[AdaptiveStrategy] = [] - 116
let mut high_count = 0 - 117●
for op in all_ops() { - 118●
let s = adaptive_strategy(op) - 119
if s.priority is HighPriority { - 120○
high_count = high_count + 1 - 121
} - 122●
strategies.push(s) - 123
} - 124●
let total = strategies.length() - 125
let summary = "自适应策略: " + - 126●
total.to_string() + - 127
" 个算子, " + - 128●
high_count.to_string() + - 129
" 个高优先级" - 130
{ - 131
strategies, - 132
total_prioritized: total, - 133
high_priority_count: high_count, - 134
summary, - 135
} - 136
} - 137
- 138
///| - 139
/// 获取高优先级算子标签。 - 140
/// 获取 Get high-priority op tags. - 141
pub fn high_priority_ops() -> Array[String] { - 142●
let result : Array[String] = [] - 143●
for s in adaptive_strategy_all().strategies { - 144●
if s.priority is HighPriority { - 145○
result.push(s.op_tag) - 146
} - 147
} - 148
result - 149
} - 150
- 151
///| - 152
/// 自适应报告是否全部高覆盖。 - 153
/// 描述 Whether adaptive report is all high coverage. - 154
pub fn AdaptiveReport::is_well_covered(self : AdaptiveReport) -> Bool { - 155○
self.high_priority_count == 0 - 156
}