64 lines
2.6 KiB
Swift
64 lines
2.6 KiB
Swift
import XCTest
|
||
@testable import TargetPrint
|
||
|
||
final class GeometryTests: XCTestCase {
|
||
func testG1_300dpi_2400x3000_isExactly8x10() {
|
||
let w = Geometry.physicalInches(pixels: 2400, dpi: 300)
|
||
let h = Geometry.physicalInches(pixels: 3000, dpi: 300)
|
||
XCTAssertEqual(w, 8.0, accuracy: 1e-9)
|
||
XCTAssertEqual(h, 10.0, accuracy: 1e-9)
|
||
XCTAssertTrue(Geometry.geometricAccuracyPass(
|
||
expectedWidthIn: 8, expectedHeightIn: 10,
|
||
actualWidthIn: w, actualHeightIn: h
|
||
))
|
||
let ptW = Geometry.pointSize(pixels: 2400, dpi: 300, scaling: 1)
|
||
let ptH = Geometry.pointSize(pixels: 3000, dpi: 300, scaling: 1)
|
||
XCTAssertEqual(ptW, 576, accuracy: 1e-9)
|
||
XCTAssertEqual(ptH, 720, accuracy: 1e-9)
|
||
}
|
||
|
||
func testMissingDPIFallsBackTo72() {
|
||
XCTAssertEqual(Geometry.physicalInches(pixels: 720, dpi: 0), 10.0, accuracy: 1e-9)
|
||
XCTAssertEqual(Geometry.physicalInches(pixels: 720, dpi: -3), 10.0, accuracy: 1e-9)
|
||
XCTAssertEqual(Geometry.physicalInches(pixels: 72, dpi: 72), 1.0, accuracy: 1e-9)
|
||
}
|
||
|
||
func testGeometricToleranceIsOneTenthMillimetre() {
|
||
let tolIn = Geometry.mmToInches(0.1)
|
||
XCTAssertTrue(Geometry.geometricAccuracyPass(
|
||
expectedWidthIn: 8, expectedHeightIn: 10,
|
||
actualWidthIn: 8 + tolIn, actualHeightIn: 10
|
||
))
|
||
XCTAssertFalse(Geometry.geometricAccuracyPass(
|
||
expectedWidthIn: 8, expectedHeightIn: 10,
|
||
actualWidthIn: 8 + tolIn + 0.0001, actualHeightIn: 10
|
||
))
|
||
}
|
||
|
||
func testCenteredDestinationOnA4() {
|
||
let paper = Geometry.paper(named: "A4")
|
||
let imageable = Geometry.imageableBounds(paper: paper)
|
||
let dest = Geometry.calculateDestinationRect(
|
||
pixelWidth: 2100, pixelHeight: 3000, dpiX: 300, dpiY: 300,
|
||
paper: paper, imageable: imageable, centered: true, scaling: 1
|
||
)
|
||
XCTAssertEqual(dest.width, 504, accuracy: 0.001)
|
||
XCTAssertEqual(dest.height, 720, accuracy: 0.001)
|
||
XCTAssertEqual(dest.midX, imageable.midX, accuracy: 0.002)
|
||
XCTAssertEqual(dest.midY, imageable.midY, accuracy: 0.002)
|
||
XCTAssertFalse(dest.minX.isNaN)
|
||
}
|
||
|
||
func testNeverUsesBackingScaleInPointSize() {
|
||
// 7 in at 150 dpi = 1050 px. Point size must be 7 × 72 regardless of any 2× display.
|
||
let pt = Geometry.pointSize(pixels: 1050, dpi: 150, scaling: 1)
|
||
XCTAssertEqual(pt, 504, accuracy: 1e-9)
|
||
}
|
||
|
||
func testLetterSize() {
|
||
let letter = Geometry.paper(named: "Letter")
|
||
XCTAssertEqual(letter.widthPt, 612, accuracy: 0.01)
|
||
XCTAssertEqual(letter.heightPt, 792, accuracy: 0.01)
|
||
}
|
||
}
|