import SwiftUI @main struct CPUCoreGridChecks { static func main() { for count in 0...128 { for width in [120.0, 280.0, 430.0, 800.0] { let rows = CPUCoreGridLayout.rowCounts(count: count, width: width) precondition(rows.reduce(0, +) == count) if let first = rows.first, let last = rows.last { precondition(last > 0 && first - last <= 1) let columns = rows.max()! let cellWidth = (width - Double(columns - 1) * 3) / Double(columns) precondition(cellWidth >= 6, "Each real core needs its own visible meter cell") } } } precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 430) == [18]) precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 280) == [18]) precondition(CPUCoreGridLayout.rowCounts(count: 32, width: 430) == [32]) precondition(CPUCoreGridLayout.rowCounts(count: 48, width: 430) == [48]) for count in [0, 1, 4, 8, 14, 18, 24, 32, 48, 128] { let kinds = Dictionary(uniqueKeysWithValues: (0..= 0 && $0.isFinite }) precondition(widths.allSatisfy { $0 <= width }) if !groups.isEmpty { precondition(abs(widths.reduce(0, +) + Double(groups.count - 1) * 8 - width) < 1e-9) } for (group, groupWidth) in zip(groups, widths) { let rows = CPUCoreGridLayout.rowCounts(count: group.count, width: groupWidth) precondition(rows.reduce(0, +) == group.count) } } } for width in [CGFloat.nan, .infinity, -.infinity, 0] { precondition(CPUCoreGridLayout.rowCounts(count: 128, width: width).reduce(0, +) == 128) } precondition(CPUCoreGrid.groups(count: 3, kinds: [0: .efficiency]).count == 2) precondition(SegmentedCoreBar.portions(0) == [0,0,0,0]) precondition(SegmentedCoreBar.portions(0.125) == [0.5,0,0,0]) precondition(SegmentedCoreBar.portions(0.5) == [1,1,0,0]) precondition(SegmentedCoreBar.portions(1) == [1,1,1,1]) for invalid: Double? in [nil,.nan,-1] { precondition(SegmentedCoreBar.portions(invalid) == [0,0,0,0]) } print("PASS: compact per-core meters with intact identities and bounded wrapping at multiple widths/counts") } }