67 lines
5.1 KiB
Swift
67 lines
5.1 KiB
Swift
import Foundation
|
|
import CoreGraphics
|
|
|
|
@main struct PanelLayoutChecks {
|
|
static func main() {
|
|
precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)).width == 640)
|
|
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 [480, 559, 560, 600, 640, 960] {
|
|
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] = [246, 204, 256, 204, 260, 260]
|
|
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) == [220, 204, 260])
|
|
precondition(PanelLayout.columns(width: 960) == 2 && PanelLayout.columns(width: 559) == 1 && PanelLayout.columns(width: 640) == 2)
|
|
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), rows: [220, 204, 260]))
|
|
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 800), rows: [220, 204, 260]),
|
|
"Moving the interval to the footer must let the standard two-column overview fit")
|
|
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 760), rows: [220, 204, 260]))
|
|
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), footprintBytes: UInt64(2000 - index), threads: 1, restricted: false)
|
|
}
|
|
let cpu = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .cpu)], order: [])
|
|
precondition(cpu.first?.id.pid == 2000 && cpu.count == 2000)
|
|
let memory = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .memory)], order: [])
|
|
precondition(memory.first?.id.pid == 1)
|
|
let held = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .memory)], order: cpu.map(\.id))
|
|
precondition(held.map(\.id) == cpu.map(\.id))
|
|
let matched = ProcessTableProjection.rows(input, query: "needle", sorting: [ProcessSort(key: .cpu)], order: [])
|
|
precondition(matched.count == 1 && matched[0].id.pid == 43)
|
|
precondition(ProcessTableProjection.rows(input, query: "does-not-exist", sorting: [ProcessSort(key: .cpu)], order: []).isEmpty)
|
|
let ascending = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .cpu, order: .forward)], order: [])
|
|
precondition(ascending.first?.id.pid == 1)
|
|
let missing = ProcessMetrics(id: ProcessIdentity(pid: 3000, seconds: 1, microseconds: 0), name: "missing", path: nil,
|
|
cpu: nil, footprintBytes: nil, threads: nil, restricted: true)
|
|
for direction in [SortOrder.forward, .reverse] {
|
|
for key in [ProcessSort.Key.cpu, .memory, .threads] {
|
|
let result = ProcessTableProjection.rows(input + [missing], query: "", sorting: [ProcessSort(key: key, order: direction)], order: [])
|
|
precondition(result.last?.id == missing.id)
|
|
}
|
|
}
|
|
let pidSorted = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .pid)], order: [])
|
|
precondition(pidSorted.first?.id.pid == 2000)
|
|
print("PASS: physical-row heights, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results")
|
|
}
|
|
}
|