// A call's memory slip: every word the core's, the name, the day and what// happened tagged; a missed call printed in the ribbon's red, its arrow in// and every other call's arrow by what happened; the Cotton mark at the foot// of a call made with Cotton and the way's name for any other; the slip lies// bare on the calling desk's leather and is stepped by a cut.@testable importCottonFacesimportCottonPaperimportCottonValuesimportSwiftUIimport XCTest@MainActorfinalclassCallSlipTests: XCTestCase {typealiasCatalogue = CallSlipFaceCatalogue/// RULE: A missed call is printed red, as the call table's `red_when` says, read off the stored value under the state place; every other call in black, and a card that says nothing of what happened in black.func testAMissedCallIsPrintedRed() { XCTAssertTrue(CallSlipSetting.missed(Catalogue.missed)) XCTAssertFalse(CallSlipSetting.missed(Catalogue.incoming)) XCTAssertFalse(CallSlipSetting.missed(Catalogue.outgoing)) XCTAssertFalse(CallSlipSetting.missed(Catalogue.longName)) XCTAssertFalse(CallSlipSetting.missed(Catalogue.bare)) }/// RULE: The call's way is an arrow after its day: in for a call that came in or was missed, out for one made from here, none where the card does not say what happened.func testTheArrowSaysTheWayTheCallWent() { XCTAssertEqual(CallSlipSetting.arrow(Catalogue.incoming), "arrow.down.left") XCTAssertEqual(CallSlipSetting.arrow(Catalogue.missed), "arrow.down.left") XCTAssertEqual(CallSlipSetting.arrow(Catalogue.outgoing), "arrow.up.right") XCTAssertEqual(CallSlipSetting.arrow(Catalogue.longName), "arrow.up.right") XCTAssertNil(CallSlipSetting.arrow(Catalogue.bare)) }/// RULE: A call made with Cotton prints the Cotton mark at its foot and no word; a call made another way prints the way's name; a card that names no way prints neither.func testTheFootSaysHowTheCallWasMade() { XCTAssertTrue(CallSlipSetting.madeWithCotton(Catalogue.incoming)) XCTAssertNil(CallSlipSetting.way(Catalogue.incoming)) XCTAssertFalse(CallSlipSetting.madeWithCotton(Catalogue.outgoing)) XCTAssertEqual(CallSlipSetting.way(Catalogue.outgoing), "WhatsApp") XCTAssertFalse(CallSlipSetting.madeWithCotton(Catalogue.bare)) XCTAssertNil(CallSlipSetting.way(Catalogue.bare)) }/// RULE: The number is printed under the name where the call kept one, and not where the name is the number.func testTheNumberIsPrintedOnceAtMost() { XCTAssertEqual(CallSlipSetting.number(Catalogue.outgoing), "+1 555 0142") XCTAssertNil(CallSlipSetting.number(Catalogue.bare)) XCTAssertNil(CallSlipSetting.number(Catalogue.incoming)) }/// RULE: The name, the day and what happened are each the core's and tagged; a bare call tags only its name.func testEveryWordIsTheCoresAndTagged() { XCTAssertEqual(tagged(Catalogue.incoming), [.title, .when, .state]) XCTAssertEqual(tagged(Catalogue.missed), [.title, .when, .state]) XCTAssertEqual(tagged(Catalogue.bare), [.title]) }/// RULE: The tear bar's teeth keep inside the slip's room and run whole across its head and its foot.func testTheTeethKeepInsideTheSlip() {let room = CGRect(x: 0, y: 0, width: 240, height: 400)let path = TornSlip().path(in: room) XCTAssertTrue(room.insetBy(dx: -0.01, dy: -0.01).contains(path.boundingRect)) XCTAssertEqual(path.boundingRect.width, room.width, accuracy: 0.01) XCTAssertEqual(path.boundingRect.height, room.height, accuracy: 0.01) }/// RULE: The slip lies bare on the calling desk's oxblood leather, draws its own paper, and is stepped by a cut.func testTheSlipLiesOnTheLeatherAndCuts() { XCTAssertEqual(FaceRegistry.ground("call.slip"), .leatherDesk) XCTAssertEqual(FaceRegistry.stock("call.slip"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["incoming", "missed", "outgoing", "long-name", "bare"]) XCTAssertTrue(FaceGround.leatherDesk.dark, "words beside the card take the light ink on the dark leather") XCTAssertNotNil(CottonMedia.image("calling-desk", scale: 3), "the leather's tile is not in the catalogue") XCTAssertNotNil(CottonMedia.image("desk-lamp", scale: 3), "the desk lamp's pool is not in the catalogue") }privatefunc tagged(_ card: DeckCard) -> Set<FacePart> {finalclassTagged { var parts: Set<FacePart> = [] }let tagged = Tagged()let drawn = CallSlipFace(card: card) .frame(width: 340, height: 425) .backgroundPreferenceValue(FacePartsKey.self) { regions inlet _ = tagged.parts.formUnion(regions.map(\.part))Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage)return tagged.parts }}