PNBarChartTests.m
3.55 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// PNBarChartTests.m
// PNChartDemo
//
// Created by Viktoras Laukevičius on 18/04/15.
// Copyright (c) 2015 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#define EXP_SHORTHAND
#import <Expecta.h>
#import "PNBarChart.h"
#import "PNBar.h"
@interface PNBarChartTests : XCTestCase
@property (nonatomic, strong) PNBarChart *barChart;
@end
@implementation PNBarChartTests
- (void)setUp
{
[super setUp];
CGRect frame = CGRectMake(10, 20, 320, 200);
self.barChart = [[PNBarChart alloc] initWithFrame:frame];
}
- (void)tearDown
{
self.barChart = nil;
[super tearDown];
}
- (void)testXAxisLabels
{
self.barChart.xLabels = @[@"TOne", @"TTwo", @"TThree", @"TFour"];
expect(self.barChart.subviews.count).equal(4);
for (NSUInteger idx = 0; idx < 4; idx++) {
UILabel *xAxisLabel = self.barChart.subviews[idx];
expect(xAxisLabel.text).to.equal(self.barChart.xLabels[idx]);
}
}
- (void)testYAxisLabels
{
self.barChart.yLabelFormatter = ^(CGFloat value) {
return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value];
};
self.barChart.yValues = @[@1, @10, @5, @4, @7];
NSArray *expectedResults = @[@10, @8, @6, @5, @3, @1];
for (NSUInteger idx = 0; idx < 4; idx++) {
UILabel *yAxisLabel = self.barChart.subviews[idx];
expect(yAxisLabel.text).to.equal([NSString stringWithFormat:@"Value %@", expectedResults[idx]]);
}
}
- (void)testLabelsVisibility
{
self.barChart.showLabel = NO;
self.barChart.yLabelFormatter = ^(CGFloat value) {
return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value];
};
self.barChart.xLabels = @[@"TOne", @"TTwo", @"TThree", @"TFour"];
self.barChart.yValues = @[@1, @10, @5, @4, @7];
expect(self.barChart.subviews.count).to.equal(0);
}
- (void)testChartBars
{
self.barChart.barBackgroundColor = [UIColor greenColor];
self.barChart.yLabelFormatter = ^(CGFloat value) {
return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value];
};
self.barChart.yValues = @[@1, @2, @3];
NSArray *strokeColour = @[[UIColor greenColor], [UIColor redColor], [UIColor purpleColor]];
self.barChart.strokeColors = strokeColour;
[self.barChart strokeChart];
for (NSUInteger idx = 0; idx < self.barChart.bars.count; idx++) {
PNBar *bar = self.barChart.bars[idx];
expect(bar.backgroundColor).to.equal([UIColor greenColor]);
expect(bar.barColor).to.equal(strokeColour[idx]);
}
}
- (void)testStrokeColor
{
self.barChart.yLabelFormatter = ^(CGFloat value) {
return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value];
};
self.barChart.yValues = @[@1, @2, @3];
self.barChart.strokeColor = [UIColor magentaColor];
self.barChart.strokeColors = @[[UIColor greenColor], [UIColor redColor]];
[self.barChart strokeChart];
for (NSUInteger idx = 0; idx < self.barChart.bars.count; idx++) {
PNBar *bar = self.barChart.bars[idx];
expect(bar.barColor).equal(self.barChart.strokeColor);
}
}
- (void)testMaxValue
{
self.barChart.yLabelFormatter = ^(CGFloat value) {
return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value];
};
self.barChart.yMaxValue = 8;
self.barChart.yValues = @[@10, @8, @7, @3];
NSArray *expectedResults = @[@8, @6, @4, @2];
for (NSUInteger idx = 0; idx < expectedResults.count; idx++) {
UILabel *yAxisLabel = self.barChart.subviews[idx];
expect(yAxisLabel.text).to.equal([NSString stringWithFormat:@"Value %@", expectedResults[idx]]);
}
}
@end