Skip to content

Commit

Permalink
Merge pull request #4822 from truongtho1603/fix/crash-maxEntryCountSet
Browse files Browse the repository at this point in the history
Update ChartData.swift
  • Loading branch information
pmairoldi authored May 25, 2022
2 parents 25d2f06 + b44cc74 commit d2ae284
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral
/// The DataSet object with the maximum number of entries or null if there are no DataSets.
@objc open var maxEntryCountSet: Element?
{
return self.max { $0.entryCount > $1.entryCount }
return self.max { $0.entryCount < $1.entryCount }
}
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/ChartsTests/ChartDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,18 @@ class ChartDataTests: XCTestCase {
XCTAssertTrue(data.dataSet(forLabel: SetLabels.badLabel, ignorecase: true) == nil)
XCTAssertTrue(data.dataSet(forLabel: SetLabels.badLabel, ignorecase: false) == nil)
}

func testMaxEntryCountSet() throws {
let dataSet1 = BarChartDataSet(entries: (0 ..< 4).map { BarChartDataEntry(x: Double($0), y: Double($0)) },
label: "data-set-1")
let dataSet2 = BarChartDataSet(entries: (0 ..< 3).map { BarChartDataEntry(x: Double($0), y: Double($0)) },
label: "data-set-2")
let dataSet3 = BarChartDataSet(entries: [BarChartDataEntry(x: 0, y: 0)],
label: "data-set-3")
let data = BarChartData(dataSets: [dataSet1, dataSet2, dataSet3])

let maxEntryCountSet = try XCTUnwrap(data.maxEntryCountSet as? BarChartDataSet)

XCTAssertEqual(maxEntryCountSet, dataSet1)
}
}

0 comments on commit d2ae284

Please sign in to comment.