// The lab print: the photograph laid at its own shape, as large as the card // allows (a wide one the card's width, a tall one its height), the white // border the same width on every print; the date the camera burned in read // off the card's date words as DD MM YY, none for a photograph with no date; // the picture and the date tagged; the print lies on the Photos darkroom // bench and is stepped by a cut. @testable import CottonFaces import CottonPaper import CottonValues import SwiftUI import XCTest @MainActor final class PhotoPrintTests: XCTestCase { private typealias Catalogue = PhotoPrintFaceCatalogue /// A phone's card. private let room = CGSize(width: 340, height: 425) /// RULE: A wide picture's print takes the card's width and a tall one's its height, each at the picture's own shape, the border the same width on both. func testThePrintIsLaidAtThePicturesShape() { let knobs = PhotoPrintFaceKnobs.self let wide = PrintLaying.laid(aspect: 1.5, in: room) XCTAssertEqual(wide.print.width, room.width * knobs.fillWidth, accuracy: 0.01) XCTAssertEqual(wide.picture.width / wide.picture.height, 1.5, accuracy: 0.001) let tall = PrintLaying.laid(aspect: 941.0 / 1390.0, in: room) XCTAssertEqual(tall.print.height, room.height * knobs.fillHeight, accuracy: 0.01) XCTAssertLessThan(tall.print.width, room.width * knobs.fillWidth, "the cloth shows at a tall print's sides") XCTAssertEqual(tall.picture.width / tall.picture.height, 941.0 / 1390.0, accuracy: 0.001) XCTAssertEqual(wide.border, tall.border, "the border is the same width on every print") let square = PrintLaying.laid(aspect: 1, in: room) XCTAssertEqual(square.picture.width, square.picture.height, accuracy: 0.001) XCTAssertEqual(square.print.width, room.width * knobs.fillWidth, accuracy: 0.01) // The picture takes nearly all of the print: a thin border, about 2% of its width. XCTAssertGreaterThan(wide.picture.width * wide.picture.height / (wide.print.width * wide.print.height), 0.88) // A picture whose shape is not known is a lab's standard print. XCTAssertEqual(PrintLaying.laid(aspect: nil, in: room), PrintLaying.laid(aspect: 1.5, in: room)) XCTAssertEqual(PrintLaying.laid(aspect: 0, in: room), PrintLaying.laid(aspect: 1.5, in: room)) } /// RULE: The date burned in is the card's date as DD MM YY, read off the core's words with or without a time after them; a card with no date, or words that say no day, burn none. func testTheDateBurnedInIsTheCardsDay() { XCTAssertEqual(PrintBurn.figures("Sun 26 Oct 2026 \u{00B7} 6:48 pm"), "26 10 26") XCTAssertEqual(PrintBurn.figures("Sat 3 Jan 1987"), "03 01 87") XCTAssertEqual(PrintBurn.figures("Tue 9 Dec 2025"), "09 12 25") XCTAssertNil(PrintBurn.figures(nil)) XCTAssertNil(PrintBurn.figures("Undated")) XCTAssertNil(PrintBurn.figures("26 Oct"), "a photo's day always says its year") XCTAssertEqual(PrintBurn.figures(Catalogue.lake.text("date")), "26 10 26") XCTAssertNil(PrintBurn.figures(Catalogue.noDate.text("date"))) } /// RULE: The burn's figures are seven segments each, the ones a date back lights. func testTheFiguresAreSevenSegments() { XCTAssertEqual(SevenSegments.lit.count, 10) XCTAssertEqual(SevenSegments.lit["8"]?.count, 7) XCTAssertEqual(SevenSegments.lit["1"], "bc") let path = SevenSegments.path("26 10 26", height: 12) XCTAssertFalse(path.isEmpty) let size = SevenSegments.size("26 10 26", height: 12) XCTAssertEqual(size.height, 12) XCTAssertLessThanOrEqual(path.boundingRect.maxX, size.width + 0.01) } /// RULE: The print tags its picture and its date, and nothing else: there is no caption on it. func testThePrintTagsItsPictureAndItsDate() { XCTAssertEqual(tagged(Catalogue.lake), [.picture, .when]) XCTAssertEqual(tagged(Catalogue.noDate), [.picture]) } private func tagged(_ card: DeckCard) -> Set { final class Tagged { var parts: Set = [] } let tagged = Tagged() let drawn = PhotoPrintFace(card: card, key: card.text("photo")) .frame(width: room.width, height: room.height) .backgroundPreferenceValue(FacePartsKey.self) { regions in let _ = tagged.parts.formUnion(regions.map(\.part)) Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage) return tagged.parts } /// RULE: The fixtures say each specimen picture's shape, so the print is laid at it: the lake wide, the verandah tall, the jetty square. func testTheFixturesSayTheirShapes() { XCTAssertEqual(FixturePictures.aspect("kelmoor-lake") ?? 0, 1.5, accuracy: 0.01) XCTAssertLessThan(FixturePictures.aspect("verandah-wide") ?? 1, 1) XCTAssertEqual(FixturePictures.aspect("kelmoor-jetty") ?? 0, 1, accuracy: 0.01) XCTAssertNil(FixturePictures.aspect("no-such-picture")) } /// RULE: The lab print lies bare on the Photos darkroom bench, laid with its painted tile, draws its own sheet, and is stepped by a cut. func testThePrintLiesOnTheDarkroomBenchAndCuts() { XCTAssertEqual(FaceRegistry.ground("photo.print"), .darkroomBench) XCTAssertEqual(FaceRegistry.stock("photo.print"), .own) XCTAssertTrue(FaceGround.darkroomBench.dark) XCTAssertEqual(FaceGround.darkroomBench.tile, "photos-bench") XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["opened", "lake", "portrait", "square", "no-date"]) for name in ["photos-bench", "photo-print-shadow", "photo-print-sheen"] { XCTAssertNotNil(CottonMedia.image(name, scale: 3), "\(name) is not in the catalogue") } } }