diff --git a/Tests/geometrizeTests/BitmapTests.swift b/Tests/geometrizeTests/BitmapTests.swift index 1663a86..3d2c584 100644 --- a/Tests/geometrizeTests/BitmapTests.swift +++ b/Tests/geometrizeTests/BitmapTests.swift @@ -549,6 +549,64 @@ final class BitmapTests: XCTestCase { ) } + func testDifferenceFull() throws { + let blackBitmap = Bitmap(width: 10, height: 10, color: .black) + + // Difference with itself is 0 + XCTAssertEqual(blackBitmap.differenceFull(with: blackBitmap), 0) + + var blackBitmapOnePixelChanged = blackBitmap + blackBitmapOnePixelChanged[0, 0] = .white + var blackBitmapTwoPixelsChanged = blackBitmapOnePixelChanged + blackBitmapTwoPixelsChanged[0, 1] = .white + + // Changing two pixels means there's more difference than changing one. + XCTAssertGreaterThan( + blackBitmap.differenceFull(with: blackBitmapTwoPixelsChanged), + blackBitmap.differenceFull(with: blackBitmapOnePixelChanged) + ) + + // Now the same for white image + let whiteBitmap = Bitmap(width: 10, height: 10, color: .white) + + // Difference with itself is 0 + XCTAssertEqual(whiteBitmap.differenceFull(with: whiteBitmap), 0) + + var whiteBitmapOnePixelChanged = whiteBitmap + whiteBitmapOnePixelChanged[0, 0] = .black + var whiteBitmapTwoPixelsChanged = whiteBitmapOnePixelChanged + whiteBitmapTwoPixelsChanged[0, 1] = .black + + // Changing two pixels means there's more difference than changing one. + XCTAssertGreaterThan( + whiteBitmap.differenceFull(with: whiteBitmapTwoPixelsChanged), + whiteBitmap.differenceFull(with: whiteBitmapOnePixelChanged) + ) + } + + func testDifferenceFullComparingResultWithCPlusPlus() throws { + let bitmapFirst = try Bitmap(ppmBundleResource: "differenceFull bitmap first", withExtension: "ppm") + let bitmapSecond = try Bitmap(ppmBundleResource: "differenceFull bitmap second", withExtension: "ppm") + XCTAssertEqual(bitmapFirst.differenceFull(with: bitmapSecond), 0.170819, accuracy: 0.000001) + } + + func testDifferencePartialComparingResultWithCPlusPlus() throws { + let bitmapTarget = try Bitmap(ppmBundleResource: "differencePartial bitmap target", withExtension: "ppm") + let bitmapBefore = try Bitmap(ppmBundleResource: "differencePartial bitmap before", withExtension: "ppm") + let bitmapAfter = try Bitmap(ppmBundleResource: "differencePartial bitmap after", withExtension: "ppm") + let scanlines = try [Scanline](stringBundleResource: "differencePartial scanlines", withExtension: "txt") + XCTAssertEqual( + bitmapBefore.differencePartial( + with: bitmapAfter, + target: bitmapTarget, + score: 0.170819, + mask: scanlines + ), + 0.170800, + accuracy: 0.000001 + ) + } + } // swiftlint:disable:this file_length diff --git a/Tests/geometrizeTests/CoreTests.swift b/Tests/geometrizeTests/CoreTests.swift index e250155..5fcd0e6 100644 --- a/Tests/geometrizeTests/CoreTests.swift +++ b/Tests/geometrizeTests/CoreTests.swift @@ -3,64 +3,6 @@ import XCTest final class CoreTests: XCTestCase { - func testDifferenceFull() throws { - let blackBitmap = Bitmap(width: 10, height: 10, color: .black) - - // Difference with itself is 0 - XCTAssertEqual(blackBitmap.differenceFull(with: blackBitmap), 0) - - var blackBitmapOnePixelChanged = blackBitmap - blackBitmapOnePixelChanged[0, 0] = .white - var blackBitmapTwoPixelsChanged = blackBitmapOnePixelChanged - blackBitmapTwoPixelsChanged[0, 1] = .white - - // Changing two pixels means there's more difference than changing one. - XCTAssertGreaterThan( - blackBitmap.differenceFull(with: blackBitmapTwoPixelsChanged), - blackBitmap.differenceFull(with: blackBitmapOnePixelChanged) - ) - - // Now the same for white image - let whiteBitmap = Bitmap(width: 10, height: 10, color: .white) - - // Difference with itself is 0 - XCTAssertEqual(whiteBitmap.differenceFull(with: whiteBitmap), 0) - - var whiteBitmapOnePixelChanged = whiteBitmap - whiteBitmapOnePixelChanged[0, 0] = .black - var whiteBitmapTwoPixelsChanged = whiteBitmapOnePixelChanged - whiteBitmapTwoPixelsChanged[0, 1] = .black - - // Changing two pixels means there's more difference than changing one. - XCTAssertGreaterThan( - whiteBitmap.differenceFull(with: whiteBitmapTwoPixelsChanged), - whiteBitmap.differenceFull(with: whiteBitmapOnePixelChanged) - ) - } - - func testDifferenceFullComparingResultWithCPlusPlus() throws { - let bitmapFirst = try Bitmap(ppmBundleResource: "differenceFull bitmap first", withExtension: "ppm") - let bitmapSecond = try Bitmap(ppmBundleResource: "differenceFull bitmap second", withExtension: "ppm") - XCTAssertEqual(bitmapFirst.differenceFull(with: bitmapSecond), 0.170819, accuracy: 0.000001) - } - - func testDifferencePartialComparingResultWithCPlusPlus() throws { - let bitmapTarget = try Bitmap(ppmBundleResource: "differencePartial bitmap target", withExtension: "ppm") - let bitmapBefore = try Bitmap(ppmBundleResource: "differencePartial bitmap before", withExtension: "ppm") - let bitmapAfter = try Bitmap(ppmBundleResource: "differencePartial bitmap after", withExtension: "ppm") - let scanlines = try [Scanline](stringBundleResource: "differencePartial scanlines", withExtension: "txt") - XCTAssertEqual( - bitmapBefore.differencePartial( - with: bitmapAfter, - target: bitmapTarget, - score: 0.170819, - mask: scanlines - ), - 0.170800, - accuracy: 0.000001 - ) - } - func testDefaultEnergyFunctionComparingResultWithCPlusPlus() throws { let scanlines = try [Scanline]( stringBundleResource: "defaultEnergyFunction scanlines",