43 lines · 2.1 KB · SwiftRaw
// Every tier rotates around the hub on the shared fan pivot.import CoreGraphicsimport XCTest@testable import CottonUIfinal class FanPivotIsTheArcTests: XCTestCase { private let width = 393.0 /// RULE: every tier fans from the hub at the pivot, inside the screen's band. func testEveryTierSharesTheToolsPivotAndTheHubIsInsideItsBand() { for theme in [Theme.paper, Theme.plain] { let size = Double(theme.scale[.fanRecordSize]) let fan = FanGeometry(scale: theme.scale).withHub(diameter: size) let pivot = fan.pivot(width: width) XCTAssertEqual(pivot.x, width / 2) XCTAssertEqual(pivot.y, fan.top + fan.tileHeight / 2 + fan.radius) XCTAssertEqual(fan.hub(width: width, diameter: size).y + size / 2, fan.height) XCTAssertGreaterThan(pivot.y, fan.settledFoot) XCTAssertEqual(fan.radius, FanGeometry(scale: theme.scale).radius) XCTAssertEqual(fan.step, FanGeometry(scale: theme.scale).step) } } func testOpenedRecordKeepsTheRedCloseAtEveryTier() throws { let source = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Board/FanSurface.swift", ownedBy: "shell")) XCTAssertTrue(source.contains("acts: editor.openedTarget == nil && editor.holdsActs")) } /// RULE: the fan's surface builds the same arc with or without caps — its geometry reads the theme and nothing else. func testTheSurfaceBuildsTheArcWithOrWithoutCaps() throws { let source = SourceSweep.withoutComments( try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Board/FanSurface.swift", ownedBy: "shell")) .filter { !$0.isWhitespace } let built = source.components(separatedBy: "FanGeometry(").dropFirst().map { $0.prefix(while: { $0 != ")" }) } XCTAssertTrue(source.contains(".withHub(diameter:Double(scale[.fanRecordSize]))")) XCTAssertFalse(built.isEmpty) for arguments in built { XCTAssertTrue(arguments == "scale:theme.scale" || arguments == "scale:scale", "FanGeometry(\(arguments))") } }}