Skip to content

Commit

Permalink
improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lmillan1 committed Jul 19, 2024
1 parent 60e1ad9 commit 87fe319
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions Tests/CareKitEssentialsTests/CareTaskProgressStrategyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ final class CareTaskProgressStrategyTests: XCTestCase {
func testAveragingOutcomeValues() async throws {
let ten = 10.0
let twenty = 20.0
let thirty = 30.0

let outcomeValues = [
OCKOutcomeValue(ten),
OCKOutcomeValue(twenty),
OCKOutcomeValue(thirty)
OCKOutcomeValue(twenty)
]

let event = OCKAnyEvent.mock(
Expand All @@ -30,18 +28,20 @@ final class CareTaskProgressStrategyTests: XCTestCase {
)

let progress = event.computeProgress(by: .averagingOutcomeValues())
let expectedValue = (ten + twenty + thirty) / 3
let expectedValue = (ten + twenty) / Double(outcomeValues.count)

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
}

func testmedianOutcomeValues() async throws {
func testMedianOutcomeValues() async throws {
let ten = 10.0
let twenty = 20.0
let thirty = 30.0

let outcomeValues = [
OCKOutcomeValue(twenty),
OCKOutcomeValue(ten),
OCKOutcomeValue(twenty)
OCKOutcomeValue(thirty)
]

let event = OCKAnyEvent.mock(
Expand All @@ -52,16 +52,12 @@ final class CareTaskProgressStrategyTests: XCTestCase {
)

let progress = event.computeProgress(by: .medianOutcomeValues())
let sortedValues = outcomeValues
.compactMap { $0.doubleValue }
.sorted()
let index = outcomeValues.count / 2
let expectedValue = (sortedValues[index] + sortedValues[index - 1]) / 2.0
let expectedValue = twenty

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
}

func teststreakOutcomeValues() async throws {
func testStreakOutcomeValues() async throws {
let ten = 10.0
let twenty = 20.0
let thirty = 30.0
Expand Down

0 comments on commit 87fe319

Please sign in to comment.