-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChartDataTests.swift
69 lines (56 loc) · 2.8 KB
/
ChartDataTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// 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)
}
}