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

Upgrade dependency swift algorithms #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"repositoryURL": "https://github.com/apple/swift-algorithms",
"state": {
"branch": null,
"revision": "bb3bafeca0e164ece3403a9de646b7d38c07dd49",
"version": "0.0.2"
"revision": "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version": "1.0.0"
}
},
{
"package": "swift-numerics",
"repositoryURL": "https://github.com/apple/swift-numerics",
"state": {
"branch": null,
"revision": "6b24333510e9044cf4716a07bed65eeed6bc6393",
"version": "0.0.8"
"revision": "0a5bc04095a675662cf24757cc0640aa2204253b",
"version": "1.0.2"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
targets: ["Charts"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-algorithms", from: "0.0.1")
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0")
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ open class ChartDataSet: ChartBaseDataSet
rounding: ChartDataSetRounding) -> Int
{
var closest = partitioningIndex { $0.x >= xValue }
guard closest < endIndex else { return -1 }
if closest == endIndex && rounding != .up
{
closest = endIndex - 1
}
guard closest < endIndex && closest >= startIndex else { return -1 }

let closestXValue = self[closest].x

Expand Down
23 changes: 22 additions & 1 deletion Tests/ChartsTests/ChartDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,28 @@ class ChartDataTests: XCTestCase {
let res = set.entriesForXValue(Double(1621860300))
let res2 = set.entriesForXValue(Double(1621860310))

XCTAssertTrue(res?.advanced(by: 1) == res2)
XCTAssertTrue(res.first == set[slowMatch!])
XCTAssertTrue(res2.first == nil)

let up = set.entryIndex(x: set.last!.x + 1, closestToY: .nan, rounding: .up)

XCTAssertTrue(up == -1)

let upClosest = set.entryIndex(x: set.last!.x + 1 , closestToY: .nan, rounding: .closest)

XCTAssertTrue(upClosest == set.endIndex - 1)

let down = set.entryIndex(x: set.last!.x + 1, closestToY: .nan, rounding: .down)

XCTAssertTrue(down == set.endIndex - 1)

let minDown = set.entryIndex(x: set.first!.x - 1, closestToY: .nan, rounding: .down)

XCTAssertTrue(minDown == -1)

let minUp = set.entryIndex(x: set.first!.x - 1, closestToY: .nan, rounding: .up)

XCTAssertTrue(minUp == 0)

let closestIdx = set.entryIndex(x: Double(1621860310), closestToY: .nan, rounding: .closest)

Expand Down