Cotton code
63 lines · 3.2 KB · SwiftRaw
// The album's slide carousel: a slide in a slot for each photo the album// holds, the tray's eighty at most; up to three prints laid on the bench, the// cover first; every word the core's, tagged; the carousel lies on the Photos// darkroom bench and is stepped by a cut.@testable import CottonFacesimport CottonPaperimport CottonValuesimport SwiftUIimport XCTest@MainActorfinal class AlbumCarouselTests: XCTestCase {    typealias Catalogue = AlbumCarouselFaceCatalogue    /// RULE: The tray holds a slide for each photo the album holds, as the core counts them, eighty at most and none for an empty album.    func testTheTrayHoldsASlideForEachPhoto() {        XCTAssertEqual(CarouselSlides.filled(Catalogue.weekend), 23)        XCTAssertEqual(CarouselSlides.filled(Catalogue.two), 2)        XCTAssertEqual(CarouselSlides.filled(Catalogue.longName), 80, "1,204 photos fill the tray")        XCTAssertEqual(CarouselSlides.filled(Catalogue.empty), 0)        XCTAssertEqual(CarouselSlides.angle(of: 0), -90 + 360 * 0.5 / 80, "the round starts at the notch, twelve o'clock")        XCTAssertLessThan(CarouselSlides.angle(of: 79), 270, "and runs once round")    }    /// RULE: Up to three prints are laid on the bench, the cover first and on top; fewer leave the bench bare.    func testTheBenchTakesThreePrintsTheCoverFirst() {        XCTAssertEqual(CarouselSlides.shown(Catalogue.weekend), ["kelmoor-lake", "kelmoor-jetty", "portrait"])        XCTAssertEqual(CarouselSlides.shown(Catalogue.two), ["verandah", "verandah-wide"])        XCTAssertEqual(CarouselSlides.shown(Catalogue.empty), [])        XCTAssertEqual(SlidePlace.stacking.last, 0, "the cover is laid last, on top")        XCTAssertEqual(Set(SlidePlace.stacking), Set(SlidePlace.all.indices))    }    /// RULE: The label says the album's name, its count and its days, each tagged, and the slides are its pictures.    func testEveryWordIsTheCoresAndTagged() {        XCTAssertEqual(tagged(Catalogue.weekend), [.title, .corner, .when, .picture])        XCTAssertEqual(tagged(Catalogue.empty), [.title, .corner])        XCTAssertEqual(BoardPrints.facts(Catalogue.weekend), "23 photos \u{00B7} Sun 26 Oct")    }    /// RULE: The slide carousel lies bare on the Photos darkroom bench, draws its own sheet, and is stepped by a cut.    func testTheCarouselLiesOnTheBenchAndCuts() {        XCTAssertEqual(FaceRegistry.ground("album.carousel"), .darkroomBench)        XCTAssertEqual(FaceRegistry.stock("album.carousel"), .own)        XCTAssertEqual(Catalogue.face.steps, .cut)        XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["weekend", "two", "long-name", "empty"])        XCTAssertNotNil(CottonMedia.image("photos-bench", scale: 3), "the bench's tile is not in the catalogue")    }    private func tagged(_ card: DeckCard) -> Set<FacePart> {        final class Tagged { var parts: Set<FacePart> = [] }        let tagged = Tagged()        let drawn = AlbumCarouselFace(card: card)            .frame(width: 340, height: 425)            .backgroundPreferenceValue(FacePartsKey.self) { regions in                let _ = tagged.parts.formUnion(regions.map(\.part))                Color.clear            }        XCTAssertNotNil(ImageRenderer(content: drawn).cgImage)        return tagged.parts    }}