Viktoras Laukevičius

Added partial bar chart test coverage

... ... @@ -21,7 +21,9 @@
0AF7A880182AA9F6003645C4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0AF7A87F182AA9F6003645C4 /* Images.xcassets */; };
0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF7A8AE182AAEEF003645C4 /* PCChartViewController.m */; };
5C728F7B8AACCC0864A63B26 /* libPods-PNChartTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B0A0D7DDAB496680487BF1E5 /* libPods-PNChartTests.a */; };
6E984E561AE2AF2D00E817A0 /* PNChartTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E984E551AE2AF2D00E817A0 /* PNChartTests.m */; };
6E984E5D1AE2B00600E817A0 /* PNBarChartTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E984E5C1AE2B00600E817A0 /* PNBarChartTests.m */; };
6E984E5E1AE2B03800E817A0 /* PNBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 91177EC9198DFAC400017E27 /* PNBar.m */; };
6E984E5F1AE2B03E00E817A0 /* PNBarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 91177ECB198DFAC400017E27 /* PNBarChart.m */; };
91177ED8198DFAC400017E27 /* PNBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 91177EC9198DFAC400017E27 /* PNBar.m */; };
91177EDA198DFAC400017E27 /* PNBarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 91177ECB198DFAC400017E27 /* PNBarChart.m */; };
91177EDC198DFAC400017E27 /* PNCircleChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 91177ECD198DFAC400017E27 /* PNCircleChart.m */; };
... ... @@ -75,7 +77,7 @@
4D54B84CA1CAEB2BBBC9DCFA /* Pods-PNChartTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNChartTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PNChartTests/Pods-PNChartTests.release.xcconfig"; sourceTree = "<group>"; };
6E984E511AE2AF2D00E817A0 /* PNChartTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PNChartTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6E984E541AE2AF2D00E817A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6E984E551AE2AF2D00E817A0 /* PNChartTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNChartTests.m; sourceTree = "<group>"; };
6E984E5C1AE2B00600E817A0 /* PNBarChartTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBarChartTests.m; sourceTree = "<group>"; };
91177EC8198DFAC400017E27 /* PNBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBar.h; sourceTree = "<group>"; };
91177EC9198DFAC400017E27 /* PNBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBar.m; sourceTree = "<group>"; };
91177ECA198DFAC400017E27 /* PNBarChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBarChart.h; sourceTree = "<group>"; };
... ... @@ -215,8 +217,8 @@
6E984E521AE2AF2D00E817A0 /* PNChartTests */ = {
isa = PBXGroup;
children = (
6E984E551AE2AF2D00E817A0 /* PNChartTests.m */,
6E984E531AE2AF2D00E817A0 /* Supporting Files */,
6E984E5C1AE2B00600E817A0 /* PNBarChartTests.m */,
);
path = PNChartTests;
sourceTree = "<group>";
... ... @@ -456,7 +458,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6E984E561AE2AF2D00E817A0 /* PNChartTests.m in Sources */,
6E984E5F1AE2B03E00E817A0 /* PNBarChart.m in Sources */,
6E984E5E1AE2B03800E817A0 /* PNBar.m in Sources */,
6E984E5D1AE2B00600E817A0 /* PNBarChartTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...
//
// 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
... ...
//
// PNChartTests.m
// PNChartTests
//
// Created by Viktoras Laukevičius on 18/04/15.
// Copyright (c) 2015 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@interface PNChartTests : XCTestCase
@end
@implementation PNChartTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
@end