Kevin

Merge pull request #191 from viktorasl/feature/unit-test-coverage

Unit test coverage
This diff is collapsed. Click to expand it.
//
// PNChartDemoTests.m
// PNChartDemoTests
//
// Created by kevin on 11/7/13.
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import <XCTest/XCTest.h>
@interface PNChartDemoTests : XCTestCase
@end
@implementation PNChartDemoTests
- (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
{
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}
@end
/* Localized versions of Info.plist keys */
... ... @@ -5,11 +5,13 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>Piner.${PRODUCT_NAME:rfc1034identifier}</string>
<string>vila.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
... ...
//
// 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
... ...
... ... @@ -2,3 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '6.0'
pod 'UICountingLabel','~> 1.2.0'
target :PNChartTests do
pod 'Expecta'
end
\ No newline at end of file
... ...
PODS:
- Expecta (0.3.2)
- UICountingLabel (1.2.0)
DEPENDENCIES:
- Expecta
- UICountingLabel (~> 1.2.0)
SPEC CHECKSUMS:
UICountingLabel: a55223a9357af71f833af76665164d2e3f3654b5
Expecta: 8c507baf13211207b1e9d0a741480600e6b4ed15
UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa
COCOAPODS: 0.35.0
COCOAPODS: 0.36.4
... ...