41 lines
2.8 KiB
Swift
41 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 square = PanelLayout.resourceRowHeight(size: size)
|
|
let wide = PanelLayout.firstRowWideCardWidth(size: size)
|
|
precondition(square >= 220 && square <= 230)
|
|
precondition(abs(PanelLayout.batteryWidth(size: size) / square - 4.0 / 3.0) < 0.001)
|
|
precondition(abs(2 * wide + PanelLayout.batteryWidth(size: size) + 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")
|
|
}
|
|
}
|