Skip to content

Commit

Permalink
Move bitmap tests from CoreTests to BitmapTests
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyvan committed Jul 19, 2024
1 parent 7a2a546 commit f5a4073
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
58 changes: 58 additions & 0 deletions Tests/geometrizeTests/BitmapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 0 additions & 58 deletions Tests/geometrizeTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f5a4073

Please sign in to comment.