-
-
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.
fix #1830. credit from ChartsOrg/Charts#2049 (#2874)
* fix #1830. credit from ChartsOrg/Charts#2049 * add combined chart unit tests for iOS, tvOS (macOS only have build process) * use iterater rather than index
- Loading branch information
Showing
10 changed files
with
134 additions
and
20 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
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
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,104 @@ | ||
// | ||
// CombinedChartTests.swift | ||
// ChartsTests | ||
// | ||
// Created by Xuan Liu on 14/10/2017. | ||
// | ||
|
||
import XCTest | ||
import FBSnapshotTestCase | ||
@testable import Charts | ||
|
||
class CombinedChartTests: FBSnapshotTestCase | ||
{ | ||
var chart: CombinedChartView! | ||
var lineDataSet: LineChartDataSet! | ||
var barDataSet: BarChartDataSet! | ||
|
||
override func setUp() | ||
{ | ||
super.setUp() | ||
|
||
// Set to `true` to re-capture all snapshots | ||
self.recordMode = false | ||
|
||
// Sample data | ||
let combinedData = CombinedChartData() | ||
combinedData.barData = generateBarData() | ||
combinedData.lineData = generateLineData() | ||
chart = CombinedChartView(frame: CGRect(x: 0, y: 0, width: 480, height: 350)) | ||
chart.backgroundColor = NSUIColor.clear | ||
chart.leftAxis.axisMinimum = 0.0 | ||
chart.rightAxis.axisMinimum = 0.0 | ||
chart.data = combinedData | ||
} | ||
|
||
func generateBarData() -> BarChartData | ||
{ | ||
let values: [Double] = [8, 104, 81, 93, 52, 44, 97, 101, 75, 28, | ||
76, 25, 20, 13, 52, 44, 57, 23, 45, 91, | ||
99, 14, 84, 48, 40, 71, 106, 41, 45, 61] | ||
|
||
var entries: [ChartDataEntry] = Array() | ||
|
||
for (i, value) in values.enumerated() | ||
{ | ||
entries.append(BarChartDataEntry(x: Double(i), y: value, icon: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil))) | ||
} | ||
|
||
barDataSet = BarChartDataSet(values: entries, label: "Bar chart unit test data") | ||
barDataSet.drawIconsEnabled = false | ||
|
||
let data = BarChartData(dataSet: barDataSet) | ||
data.barWidth = 0.85 | ||
return data | ||
} | ||
|
||
func generateLineData() -> LineChartData | ||
{ | ||
let values: [Double] = [0, 254, 81, 93, 52, 44, 97, 101, 75, 28, | ||
76, 25, 20, 13, 52, 44, 57, 23, 45, 91, | ||
99, 14, 84, 48, 40, 71, 106, 41, 45, 61] | ||
|
||
var entries: [ChartDataEntry] = Array() | ||
|
||
for (i, value) in values.enumerated() | ||
{ | ||
entries.append(ChartDataEntry(x: Double(i), y: value, icon: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil))) | ||
} | ||
|
||
lineDataSet = LineChartDataSet(values: entries, label: "Line chart unit test data") | ||
lineDataSet.drawIconsEnabled = false | ||
return LineChartData(dataSet: lineDataSet) | ||
} | ||
|
||
override func tearDown() | ||
{ | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
super.tearDown() | ||
} | ||
|
||
func testDefaultAxisDependency() | ||
{ | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testLeftRightAxisDependency() | ||
{ | ||
lineDataSet.axisDependency = .left | ||
barDataSet.axisDependency = .right | ||
chart.data?.notifyDataChanged() | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testAllRightAxisDependency() | ||
{ | ||
lineDataSet.axisDependency = .right | ||
barDataSet.axisDependency = .right | ||
chart.data?.notifyDataChanged() | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.2 KB
...hartsTests.CombinedChartTests/testAllRightAxisDependency_tvOS_1920.0_1080.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.2 KB
...ChartsTests.CombinedChartTests/testDefaultAxisDependency_tvOS_1920.0_1080.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.7 KB
...artsTests.CombinedChartTests/testLeftRightAxisDependency_tvOS_1920.0_1080.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.