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 width: CGFloat in [640, 899, 900, 1159, 1160, 1240] { let size = CGSize(width: width, height: 820) let columns = PanelLayout.columns(width: width) let cardWidth = PanelLayout.cardWidth(size: size) precondition(abs(CGFloat(columns) * cardWidth + CGFloat(columns - 1) * 8 - (width - 20)) < 0.001) let rows = PanelLayout.rowHeights(columns: columns, coreRows: 3, fanCount: 6) let requirements: [CGFloat] = [306, 332, 280, 280, 280, 280] for index in requirements.indices { precondition(rows[index / columns] >= requirements[index]) } precondition(rows.count == (6 + columns - 1) / columns) precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 600), rows: rows)) precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), rows: rows)) } precondition(PanelLayout.rowHeights(columns: 2, coreRows: 2, fanCount: 0) == [280, 280, 280]) 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: physical-row heights, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/RSS projection, frozen order, path search and empty results") } }