Files
Kymo/kymoTests/PanelLayoutChecks.swift
T
wangairnan cc38066de2 feat(menubar): 完善首排监控卡片与温度风扇采样
补充 GPU 渲染分块、内存与利用率统计,增加只读 SMC 温度及风扇信息和旋转动效。完善电池功率与耗电进程列表,统一首排布局并固定异步加载区域高度。同步验证用例、架构说明和 GPU 能力调研工具。
2026-11-03 16:42:09 +08:00

42 lines
2.8 KiB
Swift

import Foundation
import CoreGraphics
@main struct PanelLayoutChecks {
static func main() {
for visible in [CGRect(x: 0, y: 67, width: 1512, height: 882), CGRect(x: -1440, y: -200, width: 1440, height: 800), CGRect(x: 0, y: 24, width: 800, height: 600)] {
let content = PanelLayout.contentSize(visible: visible, chrome: CGSize(width: 4, height: 12))
precondition(content.width + 4 <= visible.width - 32 && content.height + 12 <= visible.height - 32)
for frame in [CGRect(x: -500, y: 500, width: 1240, height: 820), CGRect(x: 1400, y: -800, width: 2000, height: 1200)] {
precondition(visible.insetBy(dx: 16, dy: 16).contains(PanelLayout.constrainedFrame(frame, visible: visible)))
let centered = PanelLayout.centeredFrame(frame, visible: visible)
precondition(abs(centered.midX - visible.midX) < 0.001)
precondition(visible.insetBy(dx: 16, dy: 16).contains(centered))
}
}
for size in [CGSize(width: 1240, height: 820), CGSize(width: 1160, height: 810)] {
let compact = PanelLayout.resourceRowHeight(size: size, coreRows: 2)
let expanded = PanelLayout.resourceRowHeight(size: size, coreRows: 3)
let width = PanelLayout.cardWidth(size: size)
precondition(compact >= 224 && compact <= 239)
precondition(expanded == min(265, compact + 26))
precondition(abs(3 * width + 16 - (size.width - 20)) < 0.001)
}
let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in
let id = ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0)
let path: String? = index == 42 ? "/test/needle" : nil
return ProcessMetrics(id: id, name: "worker-\(index)",
path: path, cpu: Double(index), residentBytes: UInt64(2000 - index), threads: 1, restricted: false)
}
let cpu = ProcessTableProjection.rows(input, query: "", byMemory: false, order: [])
precondition(cpu.first?.id.pid == 2000 && cpu.count == 2000)
let memory = ProcessTableProjection.rows(input, query: "", byMemory: true, order: [])
precondition(memory.first?.id.pid == 1)
let held = ProcessTableProjection.rows(input, query: "", byMemory: true, order: cpu.map(\.id))
precondition(held.map(\.id) == cpu.map(\.id))
let matched = ProcessTableProjection.rows(input, query: "needle", byMemory: false, order: [])
precondition(matched.count == 1 && matched[0].id.pid == 43)
precondition(ProcessTableProjection.rows(input, query: "does-not-exist", byMemory: false, order: []).isEmpty)
print("PASS: visible-frame bounds/chrome/negative origins, 2000-row CPU/RSS projection, frozen order, path search and empty results")
}
}