Skip to content

Commit

Permalink
fix: Change method name to sortedByGreatest() (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Jul 8, 2024
1 parent 7291099 commit 094cf72
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
1 change: 1 addition & 0 deletions CareKitEssentials.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
LastSwiftMigration = 9999;
LastSwiftUpdateCheck = 1540;
LastUpgradeCheck = 1540;
ORGANIZATIONNAME = "Network Reconnaissance Lab";
TargetAttributes = {
70C422CE2C3B6C7600E6DC51 = {
CreatedOnToolsVersion = 15.4;
Expand Down
30 changes: 22 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,36 @@ let package = Package(
products: [
.library(
name: "CareKitEssentials",
targets: ["CareKitEssentials"])
targets: ["CareKitEssentials"]
)
],
dependencies: [
.package(url: "https://github.com/cbaker6/CareKit.git",
.upToNextMajor(from: "3.0.0-beta.12"))
.package(
url: "https://github.com/cbaker6/CareKit.git",
.upToNextMajor(from: "3.0.0-beta.12")
)
],
targets: [
.target(
name: "CareKitEssentials",
dependencies: [
.product(name: "CareKit", package: "CareKit"),
.product(name: "CareKitStore", package: "CareKit"),
.product(name: "CareKitUI", package: "CareKit")
]),
.product(
name: "CareKit",
package: "CareKit"
),
.product(
name: "CareKitStore",
package: "CareKit"
),
.product(
name: "CareKitUI",
package: "CareKit"
)
]
),
.testTarget(
name: "CareKitEssentialsTests",
dependencies: ["CareKitEssentials"])
dependencies: ["CareKitEssentials"]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// CareKitEssentials
//
// Created by Corey Baker on 7/7/24.
// Copyright © 2024 Network Reconnaissance Lab. All rights reserved.
//

import CareKitStore
Expand All @@ -11,8 +12,8 @@ import Foundation
public extension Sequence where Element: OCKAnyOutcome {

/**
Returns the `OCKAnyOutcome` sorted in order from newest to oldest with respect to a given `KeyPath`.
When necessary, can specify a cutoff value for the respective `KeyPath` to be less than or equal to.
Returns the `OCKAnyOutcome` sorted in order from greatest to lowest with respect to a given `KeyPath`.
When necessary, can specify a max value for the respective `KeyPath` to be less than or equal to.
- parameter keyPath: An optional `Comparable` `KeyPath` to sort the `OCKAnyOutcome`'s by.
- parameter lessThanEqualTo: The value that the `keyPath` of all `OCKAnyOutcome`'s should
Expand All @@ -21,7 +22,7 @@ public extension Sequence where Element: OCKAnyOutcome {
- throws: An error when the `keyPath` cannot be unwrapped for any of the `OCKAnyOutcome` values
in the array.
*/
func sortedNewestToOldest<V>(
func sortedByGreatest<V>(
_ keyPath: KeyPath<Element, V?>,
lessThanEqualTo value: V? = nil
) throws -> [Element] where V: Comparable {
Expand Down Expand Up @@ -52,15 +53,15 @@ public extension Sequence where Element: OCKAnyOutcome {
}

/**
Returns the `OCKAnyOutcome` sorted in order from newest to oldest with respect to a given `KeyPath`.
When necessary, can specify a cutoff value for the respective `KeyPath` to be less than or equal to.
Returns the `OCKAnyOutcome` sorted in order from greatest to lowest with respect to a given `KeyPath`.
When necessary, can specify a max value for the respective `KeyPath` to be less than or equal to.
- parameter keyPath: A `Comparable` `KeyPath` to sort the `OCKAnyOutcome`'s by.
- parameter lessThanEqualTo: The value that the `keyPath` of all `OCKAnyOutcome`'s should
be less than or equal to. If this value is `nil`, the
- returns: Returns an array of `OCKAnyOutcome` sorted from newest to oldest with respect to `keyPath`.
*/
func sortedNewestToOldest<V>(
func sortedByGreatest<V>(
_ keyPath: KeyPath<Element, V>,
lessThanEqualTo value: V? = nil
) -> [Element] where V: Comparable {
Expand Down
14 changes: 7 additions & 7 deletions Tests/CareKitEssentialsTests/OCKOutcomeExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ final class OCKOutcomeExtensionsTests: XCTestCase {

// Test sorted properly
XCTAssertNotEqual(firstOutcome, secondOutcome)
let sortedByCreatedDate = try outcomes.sortedNewestToOldest(
let sortedByCreatedDate = try outcomes.sortedByGreatest(
\.createdDate
)
XCTAssertEqual(sortedByCreatedDate.count, 2)
XCTAssertEqual(sortedByCreatedDate.first, secondOutcome)
XCTAssertEqual(sortedByCreatedDate.last, firstOutcome)

// Test lessThanKeyPath
let sortedByCreatedDate2 = try outcomes.sortedNewestToOldest(
let sortedByCreatedDate2 = try outcomes.sortedByGreatest(
\.createdDate,
lessThanEqualTo: firstDate
)
XCTAssertEqual(sortedByCreatedDate2.count, 1)
XCTAssertEqual(sortedByCreatedDate2.first, firstOutcome)
let sortedByCreatedDate3 = try outcomes.sortedNewestToOldest(
let sortedByCreatedDate3 = try outcomes.sortedByGreatest(
\.createdDate,
lessThanEqualTo: secondDate
)
Expand All @@ -49,7 +49,7 @@ final class OCKOutcomeExtensionsTests: XCTestCase {
XCTAssertEqual(sortedByCreatedDate3.last, firstOutcome)

// Test KeyPath of nil should throw error
XCTAssertThrowsError(try outcomes.sortedNewestToOldest(
XCTAssertThrowsError(try outcomes.sortedByGreatest(
\.updatedDate
))
}
Expand All @@ -74,21 +74,21 @@ final class OCKOutcomeExtensionsTests: XCTestCase {

// Test sorted properly
XCTAssertNotEqual(firstOutcome, secondOutcome)
let sortedByOccurrenceIndex = outcomes.sortedNewestToOldest(
let sortedByOccurrenceIndex = outcomes.sortedByGreatest(
\.taskOccurrenceIndex
)
XCTAssertEqual(sortedByOccurrenceIndex.count, 2)
XCTAssertEqual(sortedByOccurrenceIndex.first, secondOutcome)
XCTAssertEqual(sortedByOccurrenceIndex.last, firstOutcome)

// Test lessThanKeyPath
let sortedByOccurrenceIndex2 = outcomes.sortedNewestToOldest(
let sortedByOccurrenceIndex2 = outcomes.sortedByGreatest(
\.taskOccurrenceIndex,
lessThanEqualTo: firstIndex
)
XCTAssertEqual(sortedByOccurrenceIndex2.count, 1)
XCTAssertEqual(sortedByOccurrenceIndex2.first, firstOutcome)
let sortedByOccurrenceIndex3 = outcomes.sortedNewestToOldest(
let sortedByOccurrenceIndex3 = outcomes.sortedByGreatest(
\.taskOccurrenceIndex,
lessThanEqualTo: secondIndex
)
Expand Down

0 comments on commit 094cf72

Please sign in to comment.