diff --git a/Package.swift b/Package.swift index 0c312d51..96e3750a 100644 --- a/Package.swift +++ b/Package.swift @@ -17,6 +17,7 @@ if isTestingEnabled { "Quick", "Nimble", ], resources: [ + .copy("resources/graphics-fixture.gif"), .copy("resources/sample.pdf"), ]), .testTarget(name: "TPPDFIntegrationTests", dependencies: [ diff --git a/Tests/TPPDFTests/Graphics/ColorCloseToEqualTests.swift b/Tests/TPPDFTests/Graphics/ColorCloseToEqualTests.swift new file mode 100644 index 00000000..909ca857 --- /dev/null +++ b/Tests/TPPDFTests/Graphics/ColorCloseToEqualTests.swift @@ -0,0 +1,35 @@ +// +// ColorCloseToEqualTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.16.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import CoreGraphics +import Testing +@testable import TPPDF + +struct ColorCloseToEqualTests { + @Test(arguments: [ + (0.79999, 0.69999, 0.59999, 0.49999, true), + (0.80001, 0.70001, 0.60001, 0.50001, true), + (0.79998, 0.7, 0.6, 0.5, false), + (0.8, 0.69998, 0.6, 0.5, false), + (0.8, 0.7, 0.59998, 0.5, false), + (0.8, 0.7, 0.6, 0.49998, false), + ]) + func comparingColorsRespectsToleranceForEachComponent( + red: Double, green: Double, blue: Double, alpha: Double, expectedCloseness: Bool + ) { + // Arrange + let color = Color(red: 0.8, green: 0.7, blue: 0.6, alpha: 0.5) + let otherColor = Color(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(alpha)) + + // Act + let isClose = color.isClose(to: otherColor, decimals: 5) + + // Assert + #expect(isClose == expectedCloseness) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFGraphicsTests.swift b/Tests/TPPDFTests/Graphics/PDFGraphicsTests.swift new file mode 100644 index 00000000..5ec34646 --- /dev/null +++ b/Tests/TPPDFTests/Graphics/PDFGraphicsTests.swift @@ -0,0 +1,136 @@ +// +// PDFGraphicsTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.02.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import CoreGraphics +import Foundation +import Testing +@testable import TPPDF + +struct PDFGraphicsTests { + @Test func dashedLinesUseButtCapsAndLengthsProportionalToWidth() throws { + // Arrange + let style = PDFLineStyle(type: .dashed, color: .red, width: 5) + + // Act + let dashes = try #require(PDFGraphics.createDashes(style: style)) + + // Assert + #expect(dashes.lengths == [15, 15]) + #expect(dashes.cap == .butt) + } + + @Test func dottedLinesUseRoundCapsAndLengthsProportionalToWidth() throws { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .red, width: 5) + + // Act + let dashes = try #require(PDFGraphics.createDashes(style: style)) + + // Assert + #expect(dashes.lengths == [0, 10]) + #expect(dashes.cap == .round) + } + + @Test func linesWithoutDashesDoNotCreateDashPattern() { + // Arrange + let style = PDFLineStyle(type: .none, color: .red, width: 5) + + // Act + let dashes = PDFGraphics.createDashes(style: style) + + // Assert + #expect(dashes == nil) + } + + @Test func resizingWithoutCompressionCreatesImageAtRequestedQuality() throws { + // Arrange + let image = try loadImage() + let frame = CGRect(x: 0, y: 0, width: 40, height: 40) + + // Act + let result = PDFGraphics.resizeAndCompressImage( + image: image, frame: frame, shouldResize: true, shouldCompress: false, quality: 0.2 + ) + + // Assert + #expect(image.size == CGSize(width: 61, height: 68)) + #expect(result !== image) + #expect(abs(result.size.width - 24) < 0.0001) + #expect(abs(result.size.height - 24) < 0.0001) + } + + @Test func compressingWithoutResizingPreservesImageSize() throws { + // Arrange + let image = try loadImage() + let frame = CGRect(x: 0, y: 0, width: 40, height: 40) + + // Act + let result = PDFGraphics.resizeAndCompressImage( + image: image, frame: frame, shouldResize: false, shouldCompress: true, quality: 0.2 + ) + + // Assert + #expect(image.size == CGSize(width: 61, height: 68)) + #expect(result !== image) + #expect(result.size == image.size) + } + + @Test(arguments: [(0.2, 24.0), (0.0, 8.0)]) + func resizingAndCompressingUsesQualityToDetermineSize(quality: Double, expectedLength: Double) throws { + // Arrange + let image = try loadImage() + let frame = CGRect(x: 0, y: 0, width: 40, height: 40) + let expectedSize = CGSize(width: expectedLength, height: expectedLength) + + // Act + let result = PDFGraphics.resizeAndCompressImage( + image: image, frame: frame, shouldResize: true, shouldCompress: true, quality: CGFloat(quality) + ) + + // Assert + #expect(image.size == CGSize(width: 61, height: 68)) + #expect(result !== image) + #expect(result.size == expectedSize) + } + + @Test func disablingResizingAndCompressionReturnsOriginalImage() throws { + // Arrange + let image = try loadImage() + let frame = CGRect(x: 0, y: 0, width: 40, height: 40) + + // Act + let result = PDFGraphics.resizeAndCompressImage( + image: image, frame: frame, shouldResize: false, shouldCompress: false, quality: 0.2 + ) + + // Assert + #expect(image.size == CGSize(width: 61, height: 68)) + #expect(result === image) + } + + @Test func roundingCornersCreatesNewImageWithoutResizingOrCompression() throws { + // Arrange + let image = try loadImage() + let frame = CGRect(x: 0, y: 0, width: 40, height: 40) + + // Act + let result = PDFGraphics.resizeAndCompressImage( + image: image, frame: frame, shouldResize: false, shouldCompress: false, quality: 0, + roundCorners: [.allCorners], cornerRadius: 10 + ) + + // Assert + #expect(image.size == CGSize(width: 61, height: 68)) + #expect(result !== image) + } + + private func loadImage() throws -> Image { + let url = try #require(Bundle.module.url(forResource: "graphics-fixture", withExtension: "gif")) + return try #require(Image(data: Data(contentsOf: url))) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFGraphics_Spec.swift b/Tests/TPPDFTests/Graphics/PDFGraphics_Spec.swift deleted file mode 100644 index 47796632..00000000 --- a/Tests/TPPDFTests/Graphics/PDFGraphics_Spec.swift +++ /dev/null @@ -1,138 +0,0 @@ -// -// PDFGraphics_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.02.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import CoreGraphics -import Foundation -import Nimble -import Quick -@testable import TPPDF - -class PDFGraphics_Spec: QuickSpec { - // swiftlint:disable closure_body_length function_body_length - override func spec() { - describe("PDFGraphics") { - it("can create dashes with butts") { - let width: CGFloat = 5 - let style = PDFLineStyle(type: .dashed, color: .red, width: width) - - let dashes = PDFGraphics.createDashes(style: style) - expect(dashes?.lengths) == [3 * width, 3 * width] - expect(dashes?.cap) == CGLineCap.butt - } - - it("can create dotted dashes") { - let width: CGFloat = 5 - let style = PDFLineStyle(type: .dotted, color: .red, width: width) - - let dashes = PDFGraphics.createDashes(style: style) - expect(dashes?.lengths) == [0, 2 * width] - expect(dashes?.cap) == CGLineCap.round - } - - it("does nothing when not a dashed type") { - let width: CGFloat = 5 - let style = PDFLineStyle(type: .none, color: .red, width: width) - - let dashes = PDFGraphics.createDashes(style: style) - expect(dashes).to(beNil()) - } - - describe("resizing and compression") { - // swiftlint:disable line_length - let base64String = "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" - // swiftlint:enable line_length - let data: Data! = Data(base64Encoded: base64String) - expect(data).toNot(beNil()) - - var image: Image! - let resultFrame = CGRect(x: 0, y: 0, width: 40, height: 40) - - beforeEach { - image = Image(data: data) - expect(image).toNot(beNil()) - - expect(image.size) == CGSize(width: 61, height: 68) - } - - it("can resize image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: true, - shouldCompress: false, - quality: 0.2) - expect(result) !== image - expect(result.size.width).to(beCloseTo(24)) - expect(result.size.height).to(beCloseTo(24)) - } - - it("can compress image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: false, - shouldCompress: true, - quality: 0.2) - expect(result) !== image - expect(result.size) == image.size - } - - it("can resize and compress image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: true, - shouldCompress: true, - quality: 0.2) - expect(result) !== image - expect(result.size) == CGSize(width: 24.0, height: 24.0) - } - - it("can return original image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: false, - shouldCompress: false, - quality: 0.2) - expect(result) === image - } - - it("can compress an image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: true, - shouldCompress: true, - quality: 0.0) - expect(result) !== image - } - - it("can resize and compress an image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: true, - shouldCompress: true, - quality: 0.0) - expect(result.size) == CGSize(width: 8, height: 8) - } - - it("can create a rounded image") { - let result = PDFGraphics.resizeAndCompressImage(image: image, - frame: resultFrame, - shouldResize: false, - shouldCompress: false, - quality: 0.0, - roundCorners: [.allCorners], - cornerRadius: 10) - expect(result) !== image - } - } - } - } - // swiftlint:enable closure_body_length function_body_length - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject+Equatable_Spec.swift b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject+Equatable_Spec.swift deleted file mode 100644 index 0be961f3..00000000 --- a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject+Equatable_Spec.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// PDFLineSeparatorObject+Equatable_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.12.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFLineSeparatorObject_Equatable_Spec: QuickSpec { - override func spec() { - describe("PDFLineSeparatorObject") { - context("Equatable") { - it("is equal") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - - expect(PDFLineSeparatorObject(style: style)) == PDFLineSeparatorObject(style: style) - } - - it("is not equal with different style") { - let style1 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - let style2 = PDFLineStyle(type: .dashed, color: .blue, width: 1.0) - - expect(PDFLineSeparatorObject(style: style1)) != PDFLineSeparatorObject(style: style2) - } - } - } - } - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectEquatableTests.swift b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectEquatableTests.swift new file mode 100644 index 00000000..0fef2bac --- /dev/null +++ b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectEquatableTests.swift @@ -0,0 +1,39 @@ +// +// PDFLineSeparatorObjectEquatableTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.12.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFLineSeparatorObjectEquatableTests { + @Test func separatorsWithSameStyleAreEqual() { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + let separator = PDFLineSeparatorObject(style: style) + let otherSeparator = PDFLineSeparatorObject(style: style) + + // Act + let isEqual = separator == otherSeparator + + // Assert + #expect(isEqual) + } + + @Test func separatorsWithDifferentStylesAreUnequal() { + // Arrange + let firstStyle = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + let secondStyle = PDFLineStyle(type: .dashed, color: .blue, width: 1) + let separator = PDFLineSeparatorObject(style: firstStyle) + let otherSeparator = PDFLineSeparatorObject(style: secondStyle) + + // Act + let isEqual = separator == otherSeparator + + // Assert + #expect(!isEqual) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectTests.swift b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectTests.swift new file mode 100644 index 00000000..df4029c7 --- /dev/null +++ b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObjectTests.swift @@ -0,0 +1,50 @@ +// +// PDFLineSeparatorObjectTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.12.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import CoreGraphics +import Testing +@testable import TPPDF + +struct PDFLineSeparatorObjectTests { + @Test func initializingWithoutArgumentsUsesDefaultLineStyle() { + // Arrange + let expectedStyle = PDFLineStyle() + + // Act + let separator = PDFLineSeparatorObject() + + // Assert + #expect(separator.style == expectedStyle) + } + + @Test func initializingWithStylePreservesStyle() { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + + // Act + let separator = PDFLineSeparatorObject(style: style) + + // Assert + #expect(separator.style == style) + } + + @Test func calculatingInLeftHeaderPositionsSeparatorAcrossAvailableWidth() throws { + // Arrange + let separator = PDFLineSeparatorObject() + let generator = PDFGenerator(document: PDFDocument(format: .a4)) + let container = PDFContainer.headerLeft + + // Act + let result = try separator.calculate(generator: generator, container: container) + + // Assert + #expect(result.first?.0 == container) + #expect(result.first?.1 as? PDFLineSeparatorObject === separator) + #expect(separator.frame == CGRect(x: 60, y: 60, width: 475, height: separator.style.width)) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject_Spec.swift b/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject_Spec.swift deleted file mode 100644 index 7be934b6..00000000 --- a/Tests/TPPDFTests/Graphics/PDFLineSeparatorObject_Spec.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// PDFLineSeparatorObject_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.12.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import CoreGraphics -import Nimble -import Quick -@testable import TPPDF - -class PDFLineSeparatorObject_Spec: QuickSpec { - override func spec() { - describe("PDFLineSeparatorObject") { - var separator: PDFLineSeparatorObject! = PDFLineSeparatorObject() - - context("variables") { - it("has a line style") { - expect(separator.style).toNot(beNil()) - } - } - - context("initializers") { - it("can be initialized without") { - separator = PDFLineSeparatorObject() - expect(separator).toNot(beNil()) - } - - it("can be initialized with a line style") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - - separator = PDFLineSeparatorObject(style: style) - - expect(separator.style) == style - } - } - - context("calculation") { - let document = PDFDocument(format: .a4) - let generator = PDFGenerator(document: document) - var container = PDFContainer.headerLeft - - it("works for container headerLeft") { - container = PDFContainer.headerLeft - - let result = try? separator.calculate(generator: generator, container: container) - - expect(result?.first?.0) == container - expect(result?.first?.1 as? PDFLineSeparatorObject) === separator - expect(separator.frame) == CGRect(x: 60, y: 60, width: 475, height: separator.style.width) - } - } - } - } - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/PDFLineStyleEquatableTests.swift b/Tests/TPPDFTests/Graphics/PDFLineStyleEquatableTests.swift new file mode 100644 index 00000000..b58ab79d --- /dev/null +++ b/Tests/TPPDFTests/Graphics/PDFLineStyleEquatableTests.swift @@ -0,0 +1,42 @@ +// +// PDFLineStyleEquatableTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.12.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFLineStyleEquatableTests { + @Test func stylesWithSameValuesAreEqual() { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + let otherStyle = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(isEqual) + } + + @Test(arguments: ["type", "color", "width"]) + func stylesWithDifferentValuesAreUnequal(property: String) { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + var otherStyle = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) + switch property { + case "type": otherStyle.type = .dashed + case "color": otherStyle.color = .red + default: otherStyle.width = 1 + } + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(!isEqual) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFLineStyleTests.swift b/Tests/TPPDFTests/Graphics/PDFLineStyleTests.swift new file mode 100644 index 00000000..70f65c98 --- /dev/null +++ b/Tests/TPPDFTests/Graphics/PDFLineStyleTests.swift @@ -0,0 +1,54 @@ +// +// PDFLineStyleTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.12.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import CoreGraphics +import Testing +@testable import TPPDF + +struct PDFLineStyleTests { + @Test func initializingWithoutArgumentsUsesDefaultStyle() { + // Arrange + let expectedType = PDFLineType.full + let expectedColor = Color.black + let expectedWidth: CGFloat = 0.25 + + // Act + let style = PDFLineStyle() + + // Assert + #expect(style.type == expectedType) + #expect(style.color == expectedColor) + #expect(style.width == expectedWidth) + } + + @Test func initializingWithArgumentsPreservesStyleValues() { + // Arrange + let type = PDFLineType.dotted + let color = Color.orange + let width: CGFloat = 1.25 + + // Act + let style = PDFLineStyle(type: type, color: color, width: width) + + // Assert + #expect(style.type == type) + #expect(style.color == color) + #expect(style.width == width) + } + + @Test func noneStyleHasNoLineAndZeroWidth() { + // Arrange + let expectedStyle = PDFLineStyle(type: .none, color: .black, width: 0) + + // Act + let style = PDFLineStyle.none + + // Assert + #expect(style == expectedStyle) + } +} diff --git a/Tests/TPPDFTests/Graphics/PDFLineStyle_Equatable_Spec.swift b/Tests/TPPDFTests/Graphics/PDFLineStyle_Equatable_Spec.swift deleted file mode 100644 index 3b030214..00000000 --- a/Tests/TPPDFTests/Graphics/PDFLineStyle_Equatable_Spec.swift +++ /dev/null @@ -1,51 +0,0 @@ -// -// PDFLineStyle_Equatable_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.12.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFLineStyle_Equatable_Spec: QuickSpec { - override func spec() { - describe("PDFLineStyle") { - context("Equatable") { - it("is equal") { - let style1 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - let style2 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - - expect(style1) == style2 - } - - it("is not equal with different line typ") { - let style1 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - let style2 = PDFLineStyle(type: .dashed, color: .orange, width: 0.25) - - expect(style1) != style2 - } - - it("is not equal with different color") { - let style1 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - let style2 = PDFLineStyle(type: .dotted, color: .red, width: 0.25) - - expect(style1) != style2 - } - - it("is not equal with different width") { - let style1 = PDFLineStyle(type: .dotted, color: .orange, width: 0.25) - let style2 = PDFLineStyle(type: .dotted, color: .orange, width: 1.0) - - expect(style1) != style2 - } - } - } - } - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/PDFLineStyle_Spec.swift b/Tests/TPPDFTests/Graphics/PDFLineStyle_Spec.swift deleted file mode 100644 index e519f942..00000000 --- a/Tests/TPPDFTests/Graphics/PDFLineStyle_Spec.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// PDFLineStyle_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.12.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import CoreGraphics -import Nimble -import Quick -@testable import TPPDF - -class PDFLineStyle_Spec: QuickSpec { - // swiftlint:disable closure_body_length - override func spec() { - describe("Line Style") { - var lineStyle: PDFLineStyle! - - let type = PDFLineType.dotted - let color = Color.orange - let width: CGFloat = 1.25 - - beforeEach { - lineStyle = PDFLineStyle() - } - - it("can be initialized with empty initializer") { - lineStyle = PDFLineStyle() - expect(lineStyle.type) == PDFLineType.full - expect(lineStyle.color) == Color.black - expect(lineStyle.width) == 0.25 - } - - it("can be initialized with values") { - lineStyle = PDFLineStyle(type: type, color: color, width: width) - expect(lineStyle.type) == type - expect(lineStyle.color) == color - expect(lineStyle.width) == width - } - - context("variables") { - beforeEach { - lineStyle = PDFLineStyle(type: type, color: color, width: width) - } - - it("should have a type") { - expect(lineStyle.type) == type - } - - it("should have a color") { - expect(lineStyle.color) == color - } - - it("should have a width") { - expect(lineStyle.width) == width - } - } - - it("has a static creator of style none") { - expect(PDFLineStyle.none) == PDFLineStyle(type: .none, color: .black, width: 0) - } - } - } - // swiftlint:enable closure_body_length - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/PDFLineType_Spec.swift b/Tests/TPPDFTests/Graphics/PDFLineType_Spec.swift deleted file mode 100644 index c5eff810..00000000 --- a/Tests/TPPDFTests/Graphics/PDFLineType_Spec.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// PDFLineType_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.04.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFLineType_Spec: QuickSpec { - override func spec() { - describe("PDFLineType") {} - } - - static let allTests = [ - ("spec", spec), - ] -} diff --git a/Tests/TPPDFTests/Graphics/UIImage+CloseToEqual_Spec.swift b/Tests/TPPDFTests/Graphics/UIImage+CloseToEqual_Spec.swift deleted file mode 100644 index 85fb3e03..00000000 --- a/Tests/TPPDFTests/Graphics/UIImage+CloseToEqual_Spec.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// UIImage+CloseToEqual_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.16.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class UIImage_CloseToEqual_Spec: QuickSpec { - override func spec() { - describe("UIImage") { - let color = Color(red: 0.8, green: 0.7, blue: 0.6, alpha: 0.5) - - context("CloseToEqual") { - it("is close to equal if difference is smaller than delta") { - let otherColor = Color(red: 0.79999, green: 0.69999, blue: 0.59999, alpha: 0.49999) - expect(color.isClose(to: otherColor, decimals: 5)).to(beTrue()) - - let secondOtherColor = Color(red: 0.80001, green: 0.70001, blue: 0.60001, alpha: 0.50001) - expect(color.isClose(to: secondOtherColor, decimals: 5)).to(beTrue()) - } - - it("is not close to equal if red difference is smaller than delta") { - let otherColor = Color(red: 0.79998, green: 0.7, blue: 0.6, alpha: 0.5) - expect(color.isClose(to: otherColor, decimals: 5)).to(beFalse()) - } - - it("is not close to equal if green difference is smaller than delta") { - let otherColor = Color(red: 0.8, green: 0.69998, blue: 0.6, alpha: 0.5) - expect(color.isClose(to: otherColor, decimals: 5)).to(beFalse()) - } - - it("is not close to equal if blue difference is smaller than delta") { - let otherColor = Color(red: 0.8, green: 0.7, blue: 0.59998, alpha: 0.5) - expect(color.isClose(to: otherColor, decimals: 5)).to(beFalse()) - } - - it("is not close to equal if alpha difference is smaller than delta") { - let otherColor = Color(red: 0.8, green: 0.7, blue: 0.6, alpha: 0.49998) - expect(color.isClose(to: otherColor, decimals: 5)).to(beFalse()) - } - } - } - } -} diff --git a/Tests/TPPDFTests/resources/graphics-fixture.gif b/Tests/TPPDFTests/resources/graphics-fixture.gif new file mode 100644 index 00000000..855b4041 Binary files /dev/null and b/Tests/TPPDFTests/resources/graphics-fixture.gif differ