image.domain\self_evolve\evolve_types.mbt

50% · 5 / 10 points · 146 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/evolve_types
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// self_evolve 类型定义 — 自动测试用例生成 + 退化场景发现
  7. 7// Type definitions for self-evolution: auto test generation + degradation detection
  8. 8
  9. 9///|
  10. 10/// 测试用例类别。
  11. 11/// 描述 Test case category.
  12. 12/// `#non_exhaustive` 表示未来可能添加新构造器
  13. 13#derive(Eq, @debug.Debug)
  14. 14#non_exhaustive
  15. 15pub(all) enum TestCategory {
  16. 16 Boundary // 边界条件(零尺寸/最小尺寸/最大尺寸)
  17. 17 Normal // 正常用例
  18. 18 EdgeCase // 边缘用例(极端参数)
  19. 19 Degradation // 退化用例(数值退化场景)
  20. 20}
  21. 21
  22. 22///|
  23. 23pub extend TestCategory with @debug.Debug::{to_repr}
  24. 24
  25. 25///|
  26. 26pub extend TestCategory with Eq::{not_equal, equal}
  27. 27
  28. 28///|
  29. 29/// 退化类型(对应 4.7.4 领域规则)。
  30. 30/// 描述 Degradation kind (corresponds to 4.7.4 domain rules).
  31. 31/// `#non_exhaustive` 表示未来可能添加新构造器
  32. 32#derive(Eq, @debug.Debug)
  33. 33#non_exhaustive
  34. 34pub(all) enum DegradationKind {
  35. 35 DivisionByZero // 除零
  36. 36 SingularMatrix // 奇异矩阵(行列式 ≈ 0)
  37. 37 FieldDiscontinuity // 场间断(边界不连续)
  38. 38 Overflow // 整数/浮点溢出
  39. 39 NaNValue // NaN 传播
  40. 40 InfValue // Inf 传播
  41. 41}
  42. 42
  43. 43///|
  44. 44pub extend DegradationKind with @debug.Debug::{to_repr}
  45. 45
  46. 46///|
  47. 47pub extend DegradationKind with Eq::{not_equal, equal}
  48. 48
  49. 49///|
  50. 50/// 严重程度。
  51. 51/// 描述 Severity level.
  52. 52/// `#non_exhaustive` 表示未来可能添加新构造器
  53. 53#derive(Eq, @debug.Debug)
  54. 54#non_exhaustive
  55. 55pub(all) enum Severity {
  56. 56 Warning // 警告:结果可能不精确但可用
  57. 57 Critical // 严重:结果不可靠
  58. 58 Fatal // 致命:会崩溃或抛异常
  59. 59}
  60. 60
  61. 61///|
  62. 62pub extend Severity with @debug.Debug::{to_repr}
  63. 63
  64. 64///|
  65. 65pub extend Severity with Eq::{not_equal, equal}
  66. 66
  67. 67///|
  68. 68/// 自动生成的测试用例描述。
  69. 69/// 描述 Auto-generated test case description.
  70. 70#derive(Eq, @debug.Debug)
  71. 71pub(all) struct TestCase {
  72. 72 name : String
  73. 73 op_tag : String
  74. 74 category : TestCategory
  75. 75 description : String
  76. 76 input_spec : String
  77. 77 expected_behavior : String
  78. 78}
  79. 79
  80. 80///|
  81. 81pub extend TestCase with @debug.Debug::{to_repr}
  82. 82
  83. 83///|
  84. 84pub extend TestCase with Eq::{not_equal, equal}
  85. 85
  86. 86///|
  87. 87/// 退化场景描述。
  88. 88/// 描述 Degradation case description.
  89. 89#derive(Eq, @debug.Debug)
  90. 90pub(all) struct DegradationCase {
  91. 91 kind : DegradationKind
  92. 92 op_tag : String
  93. 93 description : String
  94. 94 severity : Severity
  95. 95}
  96. 96
  97. 97///|
  98. 98pub extend DegradationCase with @debug.Debug::{to_repr}
  99. 99
  100. 100///|
  101. 101pub extend DegradationCase with Eq::{not_equal, equal}
  102. 102
  103. 103///|
  104. 104/// 演化报告:生成的测试 + 发现的退化。
  105. 105/// 描述 Evolution report: generated tests + found degradations.
  106. 106#derive(Eq, @debug.Debug)
  107. 107pub(all) struct EvolveReport {
  108. 108 generated_tests : Array[TestCase]
  109. 109 found_degradations : Array[DegradationCase]
  110. 110 summary : String
  111. 111}
  112. 112
  113. 113///|
  114. 114pub extend EvolveReport with @debug.Debug::{to_repr}
  115. 115
  116. 116///|
  117. 117pub extend EvolveReport with Eq::{not_equal, equal}
  118. 118
  119. 119///|
  120. 120/// 测试用例数量。
  121. 121/// 描述 Number of test cases.
  122. 122pub fn EvolveReport::test_count(self : EvolveReport) -> Int32 {
  123. 123● self.generated_tests.length()
  124. 124}
  125. 125
  126. 126///|
  127. 127/// 退化场景数量。
  128. 128/// 描述 Number of degradation cases.
  129. 129pub fn EvolveReport::degradation_count(self : EvolveReport) -> Int32 {
  130. 130● self.found_degradations.length()
  131. 131}
  132. 132
  133. 133///|
  134. 134/// 严重退化数量(Critical + Fatal)。
  135. 135/// 描述 Number of severe degradations.
  136. 136pub fn EvolveReport::severe_count(self : EvolveReport) -> Int32 {
  137. 137● let mut count = 0
  138. 138 for d in self.found_degradations {
  139. 139○ match d.severity {
  140. 140○ Warning => ()
  141. 141○ Critical => count = count + 1
  142. 142○ Fatal => count = count + 1
  143. 143 }
  144. 144 }
  145. 145 count
  146. 146}