Skip to content

Commit

Permalink
add combined chart unit tests for iOS, tvOS (macOS only have build pr…
Browse files Browse the repository at this point in the history
…ocess)
  • Loading branch information
liuxuan30 committed Oct 14, 2017
1 parent 408eefa commit 0fc0a9f
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
B0D28C68BB9A958DC56EB214 /* DefaultValueFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D8F8163EE54D6D9E916B0 /* DefaultValueFormatter.swift */; };
B13C74B4FF705D7B595D01EF /* IAxisValueFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD9DF16AF59680A3BB49452 /* IAxisValueFormatter.swift */; };
B539114951455C35BADAE3F3 /* PieChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */; };
B6BF9A561F91993A00E62A5D /* CombinedChartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */; };
B6C9F450D937B87224D29D5C /* IFillFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 818AC6B12505B7C0A53D62F9 /* IFillFormatter.swift */; };
B6DCC229615EFE706F64A37D /* LineScatterCandleRadarRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923206233CA89FD03565FF87 /* LineScatterCandleRadarRenderer.swift */; };
B85DEB06B4C1AFFC8A0E3295 /* CircleShapeRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECE1B1623D3AF69CECAE8562 /* CircleShapeRenderer.swift */; };
Expand Down Expand Up @@ -264,6 +265,7 @@
B137428B41C143D5115726C4 /* Description.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Description.swift; path = Source/Charts/Components/Description.swift; sourceTree = "<group>"; };
B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = RadarChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift; sourceTree = "<group>"; };
B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = BubbleChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift; sourceTree = "<group>"; };
B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CombinedChartTests.swift; path = Tests/Charts/CombinedChartTests.swift; sourceTree = "<group>"; };
BA157EFF2F952192C11DF937 /* AnimatedMoveViewJob.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AnimatedMoveViewJob.swift; path = Source/Charts/Jobs/AnimatedMoveViewJob.swift; sourceTree = "<group>"; };
BA1A58428DC4780BAB4EAADC /* CandleStickChartView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = CandleStickChartView.swift; path = Source/Charts/Charts/CandleStickChartView.swift; sourceTree = "<group>"; };
BC19DC2434D65FFB446A61B7 /* XAxisRendererRadarChart.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XAxisRendererRadarChart.swift; path = Source/Charts/Renderers/XAxisRendererRadarChart.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -511,6 +513,7 @@
children = (
5C3F5E1A69EC06E86505F7B1 /* BarChartTests.swift */,
7AB9062A28AAB9469752A954 /* ChartUtilsTests.swift */,
B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */,
D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */,
064989451F5C99C7006E8BB3 /* Snapshot.swift */,
);
Expand Down Expand Up @@ -943,6 +946,7 @@
files = (
3B11556EB7DC034E2FC958E4 /* BarChartTests.swift in Sources */,
8E1192F7A7152E9DA92C56A9 /* ChartUtilsTests.swift in Sources */,
B6BF9A561F91993A00E62A5D /* CombinedChartTests.swift in Sources */,
2BF85BEA981B359A65E9BF67 /* LineChartTests.swift in Sources */,
064989461F5C99C7006E8BB3 /* Snapshot.swift in Sources */,
);
Expand Down
104 changes: 104 additions & 0 deletions Tests/Charts/CombinedChartTests.swift
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0fc0a9f

Please sign in to comment.