-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for horizontal bar chart, including default tests and …
…drawValues and drawValuesAboveBars default data entries included positive and negative values
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// | ||
// HorizontalBarChartTests.swift | ||
// ChartsTests | ||
// | ||
// Created by Xuan Liu on 2019/3/20. | ||
// | ||
|
||
import XCTest | ||
import FBSnapshotTestCase | ||
@testable import Charts | ||
|
||
class HorizontalBarChartTests: FBSnapshotTestCase | ||
{ | ||
|
||
override func setUp() | ||
{ | ||
super.setUp() | ||
// Set to `true` to re-capture all snapshots | ||
self.recordMode = false | ||
} | ||
|
||
override func tearDown() | ||
{ | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
super.tearDown() | ||
} | ||
|
||
//MARK: Prepare | ||
func setupCustomValuesDataEntries(values: [Double]) -> [ChartDataEntry] | ||
{ | ||
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))) | ||
} | ||
return entries | ||
} | ||
|
||
func setupStackedvaluesDataEntries() -> [ChartDataEntry] | ||
{ | ||
var entries: [ChartDataEntry] = Array() | ||
entries.append(BarChartDataEntry(x: 0, yValues: [28, 50, 60, 30, 42], icon: UIImage(named: "icon"))) | ||
entries.append(BarChartDataEntry(x: 1, yValues: [-20, -36, -52, -40, -15], icon: UIImage(named: "icon"))) | ||
entries.append(BarChartDataEntry(x: 2, yValues: [10, 30, 40, 90, 72], icon: UIImage(named: "icon"))) | ||
entries.append(BarChartDataEntry(x: 3, yValues: [-40, -50, -30, -60, -20], icon: UIImage(named: "icon"))) | ||
entries.append(BarChartDataEntry(x: 4, yValues: [10, 40, 60, 45, 62], icon: UIImage(named: "icon"))) | ||
return entries | ||
} | ||
|
||
func setupDefaultValuesDataEntries() -> [ChartDataEntry] | ||
{ | ||
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] | ||
return setupCustomValuesDataEntries(values: values) | ||
} | ||
|
||
func setupDefaultDataSet(chartDataEntries: [ChartDataEntry]) -> BarChartDataSet | ||
{ | ||
let dataSet = BarChartDataSet(entries: chartDataEntries, label: "Bar chart unit test data") | ||
dataSet.drawIconsEnabled = false | ||
dataSet.iconsOffset = CGPoint(x: 0, y: -10.0) | ||
return dataSet | ||
} | ||
|
||
func setupDefaultStackedDataSet(chartDataEntries: [ChartDataEntry]) -> BarChartDataSet | ||
{ | ||
let dataSet = BarChartDataSet(entries: chartDataEntries, label: "Stacked bar chart unit test data") | ||
dataSet.drawIconsEnabled = false | ||
dataSet.iconsOffset = CGPoint(x: 0, y: -10.0) | ||
dataSet.colors = Array(arrayLiteral:NSUIColor(red: 46/255.0, green: 204/255.0, blue: 113/255.0, alpha: 1.0), | ||
NSUIColor(red: 241/255.0, green: 196/255.0, blue: 15/255.0, alpha: 1.0), | ||
NSUIColor(red: 231/255.0, green: 76/255.0, blue: 60/255.0, alpha: 1.0), | ||
NSUIColor(red: 52/255.0, green: 152/255.0, blue: 219/255.0, alpha: 1.0) | ||
) | ||
return dataSet | ||
} | ||
|
||
func setupDefaultChart(dataSets: [BarChartDataSet]) -> BarChartView | ||
{ | ||
let data = BarChartData(dataSets: dataSets) | ||
data.barWidth = 0.85 | ||
|
||
let chart = HorizontalBarChartView(frame: CGRect(x: 0, y: 0, width: 480, height: 350)) | ||
chart.backgroundColor = NSUIColor.clear | ||
chart.data = data | ||
return chart | ||
} | ||
|
||
//MARK: Start Test | ||
func testDefaultValues() | ||
{ | ||
let dataEntries = setupDefaultValuesDataEntries() | ||
let dataSet = setupDefaultDataSet(chartDataEntries: dataEntries) | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testHidesValues() | ||
{ | ||
let dataEntries = setupDefaultValuesDataEntries() | ||
let dataSet = setupDefaultDataSet(chartDataEntries: dataEntries) | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
dataSet.drawValuesEnabled = false | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testNotDrawValueAboveBars() | ||
{ | ||
let dataEntries = setupDefaultValuesDataEntries() | ||
let dataSet = setupDefaultDataSet(chartDataEntries: dataEntries) | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
chart.drawValueAboveBarEnabled = false | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testStackedDrawValues() | ||
{ | ||
let dataEntries = setupStackedvaluesDataEntries() | ||
let dataSet = setupDefaultStackedDataSet(chartDataEntries: dataEntries) | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testStackedNotDrawValues() | ||
{ | ||
let dataEntries = setupStackedvaluesDataEntries() | ||
let dataSet = setupDefaultStackedDataSet(chartDataEntries: dataEntries) | ||
dataSet.drawValuesEnabled = false | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
|
||
func testStackedNotDrawValuesAboveBars() | ||
{ | ||
let dataEntries = setupStackedvaluesDataEntries() | ||
let dataSet = setupDefaultStackedDataSet(chartDataEntries: dataEntries) | ||
let chart = setupDefaultChart(dataSets: [dataSet]) | ||
chart.drawValueAboveBarEnabled = false | ||
chart.notifyDataSetChanged() | ||
FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) | ||
} | ||
} |
Binary file added
BIN
+47.2 KB
...64/ChartsTests.HorizontalBarChartTests/testDefaultValues_iOS_375.0_667.0@2x.png
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
+38.5 KB
...s_64/ChartsTests.HorizontalBarChartTests/testHidesValues_iOS_375.0_667.0@2x.png
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
+52.1 KB
...sTests.HorizontalBarChartTests/testNotDrawValueAboveBars_iOS_375.0_667.0@2x.png
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
+50.1 KB
...hartsTests.HorizontalBarChartTests/testStackedDrawValues_iOS_375.0_667.0@2x.png
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
+50.5 KB
...orizontalBarChartTests/testStackedNotDrawValuesAboveBars_iOS_375.0_667.0@2x.png
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
+38.1 KB
...tsTests.HorizontalBarChartTests/testStackedNotDrawValues_iOS_375.0_667.0@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.