Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Improve PlayerModel floating point equality tests #27263

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ios/brave-ios/Tests/PlaylistUITests/PlayerModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ class PlayerModelTests: CoreDataTestCase {
XCTAssertEqual(playerModel.selectedItemID, itemsIDs.first)

await playerModel.seek(to: 1, accurately: true)
XCTAssertNotEqual(playerModel.currentTime, 0)
XCTAssertNotEqual(playerModel.currentTime, 0, accuracy: 0.1)

await playerModel.playPreviousItem()
XCTAssertEqual(playerModel.selectedItemID, itemsIDs.first)
XCTAssertEqual(playerModel.currentTime, 0)
XCTAssertEqual(playerModel.currentTime, 0, accuracy: 0.1)
}

/// Tests playing the previous item successfully from somewhere other than the first item in the
Expand Down Expand Up @@ -354,7 +354,7 @@ class PlayerModelTests: CoreDataTestCase {
playerModel.selectedFolderID = folder.id
await playerModel.prepareItemQueue()

XCTAssertEqual(playerModel.currentTime, 3)
XCTAssertEqual(playerModel.currentTime, 3, accuracy: 0.1)
}

/// Tests that playback is correctly saved when the app resigns being active
Expand All @@ -371,9 +371,9 @@ class PlayerModelTests: CoreDataTestCase {
playerModel.selectedFolderID = folder.id
await playerModel.prepareItemQueue()

XCTAssertEqual(playerModel.currentTime, 0)
XCTAssertEqual(playerModel.currentTime, 0, accuracy: 0.1)
await playerModel.seek(to: 3, accurately: true)
XCTAssertEqual(playerModel.currentTime, 3)
XCTAssertEqual(playerModel.currentTime, 3, accuracy: 0.1)

NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)

Expand All @@ -391,8 +391,8 @@ class PlayerModelTests: CoreDataTestCase {

await fulfillment(of: [mergeExpectation, saveExpectation], timeout: 1)

let lastPlayedOffset = PlaylistItem.getItem(id: item.id)?.lastPlayedOffset
XCTAssertEqual(lastPlayedOffset, 3)
let lastPlayedOffset = try XCTUnwrap(PlaylistItem.getItem(id: item.id)?.lastPlayedOffset)
XCTAssertEqual(lastPlayedOffset, 3, accuracy: 0.1)
}

/// Test having both an initial offset passed in and the playbackLeftOff preference being enabled
Expand Down Expand Up @@ -423,7 +423,7 @@ class PlayerModelTests: CoreDataTestCase {

XCTAssertEqual(playerModel.selectedItemID, items[1].id)
// Initial item takes precedence
XCTAssertEqual(playerModel.currentTime, initialItemOffset)
XCTAssertEqual(playerModel.currentTime, initialItemOffset, accuracy: 0.1)
}

// MARK: - Playback
Expand All @@ -448,7 +448,7 @@ class PlayerModelTests: CoreDataTestCase {
XCTAssertTrue(playerModel.isPlaying)

await playerModel.seek(to: 5, accurately: true)
XCTAssertEqual(playerModel.currentTime.rounded(), 5)
XCTAssertEqual(playerModel.currentTime, 5, accuracy: 0.1)

playerModel.pause()
XCTAssertFalse(playerModel.isPlaying)
Expand Down
Loading