-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance word frame processor to not have overlaps
- Loading branch information
1 parent
377ce78
commit d9fc366
Showing
6 changed files
with
127 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// WordFrameTests.swift | ||
// | ||
// | ||
// Created by Mohamed Afifi on 2024-04-05. | ||
// | ||
|
||
import QuranGeometry | ||
import QuranKit | ||
import XCTest | ||
@testable import WordFrameService | ||
|
||
@MainActor | ||
class WordFrameTests: XCTestCase { | ||
let word1 = Word(verse: Quran.hafsMadani1405.firstVerse, wordNumber: 1) | ||
let word2 = Word(verse: Quran.hafsMadani1405.firstVerse, wordNumber: 2) | ||
|
||
func testNonOverlappingFrames() { | ||
// Case 1: Non-overlapping frames | ||
// Before: [leftFrame] [rightFrame] | ||
var leftFrame = WordFrame(line: 1, word: word1, minX: 0, maxX: 10, minY: 0, maxY: 10) | ||
var rightFrame = WordFrame(line: 1, word: word2, minX: 20, maxX: 30, minY: 0, maxY: 10) | ||
WordFrame.unionHorizontally(leftFrame: &leftFrame, rightFrame: &rightFrame) | ||
// After: [leftFrame][rightFrame] | ||
|
||
assertFrame(leftFrame, minX: 0, maxX: 15) | ||
assertFrame(rightFrame, minX: 15, maxX: 30) | ||
} | ||
|
||
func testOverlappingFrames() { | ||
// Case 2: Overlapping frames with non-overlapping parts | ||
// Before: [leftFrame overlaps] | ||
// [overlaps rightFrame] | ||
var leftFrame = WordFrame(line: 1, word: word1, minX: 0, maxX: 20, minY: 0, maxY: 10) | ||
var rightFrame = WordFrame(line: 1, word: word2, minX: 15, maxX: 35, minY: 0, maxY: 10) | ||
WordFrame.unionHorizontally(leftFrame: &leftFrame, rightFrame: &rightFrame) | ||
// After: [leftFrame][rightFrame] | ||
|
||
assertFrame(leftFrame, minX: 0, maxX: 15) | ||
assertFrame(rightFrame, minX: 15, maxX: 35) | ||
} | ||
} | ||
|
||
func assertFrame(_ frame: WordFrame, minX: Int, maxX: Int, file: StaticString = #filePath, line: UInt = #line) { | ||
XCTAssertEqual(frame.minX, minX, "minX") | ||
XCTAssertEqual(frame.maxX, maxX, "minX") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters