import XCTest import CoreGraphics @testable import NetworkCityCore final class LayoutSolverTests: XCTestCase { // A label box centered under the node: ~160 wide, sitting below the dot. private let label = CGRect(x: -80, y: -34, width: 160, height: 30) private func worldBox(at c: CGPoint) -> CGRect { label.offsetBy(dx: c.x, dy: c.y) } func testEmptyMapReturnsSeed() { let p = LayoutSolver.placeNonOverlapping(baseAngle: 0, baseRadius: 200, localRect: label, existing: []) XCTAssertEqual(p.x, 200, accuracy: 0.001) // attempt 0 == seed XCTAssertEqual(p.y, 0, accuracy: 0.001) } func testAvoidsOverlapWithExisting() { // Pre-place a box exactly where the seed would land. let seed = CGPoint(x: cos(0.0) * 200, y: sin(0.0) * 200) let existing = [worldBox(at: seed).insetBy(dx: -16, dy: -16)] let p = LayoutSolver.placeNonOverlapping(baseAngle: 0, baseRadius: 200, localRect: label, existing: existing) XCTAssertNotEqual(p, seed) // had to move // The chosen spot's padded box must clear the existing one. let placed = worldBox(at: p).insetBy(dx: -16, dy: -16) XCTAssertFalse(placed.intersects(existing[0])) } func testResultClearsAllOfManyNeighbours() { // Seed eight districts and confirm none of their boxes overlap. var placed: [CGRect] = [] for i in 0..<8 { let angle = Double(i) / 8 * 2 * .pi let c = LayoutSolver.placeNonOverlapping(baseAngle: angle, baseRadius: 180, localRect: label, existing: placed) placed.append(worldBox(at: c)) } for a in 0..