forked from ChartsOrg/Charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue with string comparison in ChartData for finding a data…
…set by its label (Fixes ChartsOrg#4274) ChartData::getDataSetByLabel has a bug where the string comparison is checking the same string against itself due to the functions parameter having the same name as a variable within the closures scope. This change renames the variable to fix the issue.
- Loading branch information
1 parent
1198f94
commit ba680ba
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// ChartDataTests.swift | ||
// ChartsTests | ||
// | ||
// Created by Peter Kaminski on 1/23/20. | ||
// | ||
|
||
import XCTest | ||
@testable import Charts | ||
|
||
class ChartDataTests: XCTestCase { | ||
|
||
var data: ScatterChartData! | ||
|
||
private enum SetLabels { | ||
static let one = "label1" | ||
static let two = "label2" | ||
static let three = "label3" | ||
static let badLabel = "Bad label" | ||
} | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
let setCount = 5 | ||
let range: UInt32 = 32 | ||
let values1 = (0..<setCount).map { (i) -> ChartDataEntry in | ||
let val = Double(arc4random_uniform(range) + 3) | ||
return ChartDataEntry(x: Double(i), y: val) | ||
} | ||
let values2 = (0..<setCount).map { (i) -> ChartDataEntry in | ||
let val = Double(arc4random_uniform(range) + 3) | ||
return ChartDataEntry(x: Double(i), y: val) | ||
} | ||
let values3 = (0..<setCount).map { (i) -> ChartDataEntry in | ||
let val = Double(arc4random_uniform(range) + 3) | ||
return ChartDataEntry(x: Double(i), y: val) | ||
} | ||
|
||
let set1 = ScatterChartDataSet(entries: values1, label: SetLabels.one) | ||
let set2 = ScatterChartDataSet(entries: values2, label: SetLabels.two) | ||
let set3 = ScatterChartDataSet(entries: values3, label: SetLabels.three) | ||
|
||
data = ScatterChartData(dataSets: [set1, set2, set3]) | ||
} | ||
|
||
func testGetDataSetByLabelCaseSensitive() { | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.one, ignorecase: false)?.label == SetLabels.one) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.two, ignorecase: false)?.label == SetLabels.two) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.three, ignorecase: false)?.label == SetLabels.three) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.one.uppercased(), ignorecase: false) == nil) | ||
} | ||
|
||
func testGetDataSetByLabelIgnoreCase() { | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.one, ignorecase: true)?.label == SetLabels.one) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.two, ignorecase: true)?.label == SetLabels.two) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.three, ignorecase: true)?.label == SetLabels.three) | ||
|
||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.one.uppercased(), ignorecase: true)?.label == SetLabels.one) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.two.uppercased(), ignorecase: true)?.label == SetLabels.two) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.three.uppercased(), ignorecase: true)?.label == SetLabels.three) | ||
} | ||
|
||
func testGetDataSetByLabelNilWithBadLabel() { | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.badLabel, ignorecase: true) == nil) | ||
XCTAssertTrue(data.getDataSetByLabel(SetLabels.badLabel, ignorecase: false) == nil) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters