Merge pull request #191 from viktorasl/feature/unit-test-coverage
Unit test coverage
Showing
7 changed files
with
130 additions
and
40 deletions
This diff is collapsed. Click to expand it.
PNChartDemoTests/PNChartDemoTests.m
deleted
100644 → 0
| 1 | -// | ||
| 2 | -// PNChartDemoTests.m | ||
| 3 | -// PNChartDemoTests | ||
| 4 | -// | ||
| 5 | -// Created by kevin on 11/7/13. | ||
| 6 | -// Copyright (c) 2013年 kevinzhow. All rights reserved. | ||
| 7 | -// | ||
| 8 | - | ||
| 9 | -#import <XCTest/XCTest.h> | ||
| 10 | - | ||
| 11 | -@interface PNChartDemoTests : XCTestCase | ||
| 12 | - | ||
| 13 | -@end | ||
| 14 | - | ||
| 15 | -@implementation PNChartDemoTests | ||
| 16 | - | ||
| 17 | -- (void)setUp | ||
| 18 | -{ | ||
| 19 | - [super setUp]; | ||
| 20 | - // Put setup code here. This method is called before the invocation of each test method in the class. | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -- (void)tearDown | ||
| 24 | -{ | ||
| 25 | - // Put teardown code here. This method is called after the invocation of each test method in the class. | ||
| 26 | - [super tearDown]; | ||
| 27 | -} | ||
| 28 | - | ||
| 29 | -- (void)testExample | ||
| 30 | -{ | ||
| 31 | - XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | -@end |
| @@ -5,11 +5,13 @@ | @@ -5,11 +5,13 @@ | ||
| 5 | <key>CFBundleDevelopmentRegion</key> | 5 | <key>CFBundleDevelopmentRegion</key> |
| 6 | <string>en</string> | 6 | <string>en</string> |
| 7 | <key>CFBundleExecutable</key> | 7 | <key>CFBundleExecutable</key> |
| 8 | - <string>${EXECUTABLE_NAME}</string> | 8 | + <string>$(EXECUTABLE_NAME)</string> |
| 9 | <key>CFBundleIdentifier</key> | 9 | <key>CFBundleIdentifier</key> |
| 10 | - <string>Piner.${PRODUCT_NAME:rfc1034identifier}</string> | 10 | + <string>vila.$(PRODUCT_NAME:rfc1034identifier)</string> |
| 11 | <key>CFBundleInfoDictionaryVersion</key> | 11 | <key>CFBundleInfoDictionaryVersion</key> |
| 12 | <string>6.0</string> | 12 | <string>6.0</string> |
| 13 | + <key>CFBundleName</key> | ||
| 14 | + <string>$(PRODUCT_NAME)</string> | ||
| 13 | <key>CFBundlePackageType</key> | 15 | <key>CFBundlePackageType</key> |
| 14 | <string>BNDL</string> | 16 | <string>BNDL</string> |
| 15 | <key>CFBundleShortVersionString</key> | 17 | <key>CFBundleShortVersionString</key> |
PNChartTests/PNBarChartTests.m
0 → 100644
| 1 | +// | ||
| 2 | +// PNBarChartTests.m | ||
| 3 | +// PNChartDemo | ||
| 4 | +// | ||
| 5 | +// Created by Viktoras Laukevičius on 18/04/15. | ||
| 6 | +// Copyright (c) 2015 kevinzhow. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <UIKit/UIKit.h> | ||
| 10 | +#import <XCTest/XCTest.h> | ||
| 11 | +#define EXP_SHORTHAND | ||
| 12 | +#import <Expecta.h> | ||
| 13 | +#import "PNBarChart.h" | ||
| 14 | +#import "PNBar.h" | ||
| 15 | + | ||
| 16 | +@interface PNBarChartTests : XCTestCase | ||
| 17 | + | ||
| 18 | +@property (nonatomic, strong) PNBarChart *barChart; | ||
| 19 | + | ||
| 20 | +@end | ||
| 21 | + | ||
| 22 | +@implementation PNBarChartTests | ||
| 23 | + | ||
| 24 | +- (void)setUp | ||
| 25 | +{ | ||
| 26 | + [super setUp]; | ||
| 27 | + CGRect frame = CGRectMake(10, 20, 320, 200); | ||
| 28 | + self.barChart = [[PNBarChart alloc] initWithFrame:frame]; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +- (void)tearDown | ||
| 32 | +{ | ||
| 33 | + self.barChart = nil; | ||
| 34 | + [super tearDown]; | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +- (void)testXAxisLabels | ||
| 38 | +{ | ||
| 39 | + self.barChart.xLabels = @[@"TOne", @"TTwo", @"TThree", @"TFour"]; | ||
| 40 | + expect(self.barChart.subviews.count).equal(4); | ||
| 41 | + for (NSUInteger idx = 0; idx < 4; idx++) { | ||
| 42 | + UILabel *xAxisLabel = self.barChart.subviews[idx]; | ||
| 43 | + expect(xAxisLabel.text).to.equal(self.barChart.xLabels[idx]); | ||
| 44 | + } | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +- (void)testYAxisLabels | ||
| 48 | +{ | ||
| 49 | + self.barChart.yLabelFormatter = ^(CGFloat value) { | ||
| 50 | + return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value]; | ||
| 51 | + }; | ||
| 52 | + self.barChart.yValues = @[@1, @10, @5, @4, @7]; | ||
| 53 | + NSArray *expectedResults = @[@10, @8, @6, @5, @3, @1]; | ||
| 54 | + for (NSUInteger idx = 0; idx < 4; idx++) { | ||
| 55 | + UILabel *yAxisLabel = self.barChart.subviews[idx]; | ||
| 56 | + expect(yAxisLabel.text).to.equal([NSString stringWithFormat:@"Value %@", expectedResults[idx]]); | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +- (void)testLabelsVisibility | ||
| 61 | +{ | ||
| 62 | + self.barChart.showLabel = NO; | ||
| 63 | + self.barChart.yLabelFormatter = ^(CGFloat value) { | ||
| 64 | + return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value]; | ||
| 65 | + }; | ||
| 66 | + self.barChart.xLabels = @[@"TOne", @"TTwo", @"TThree", @"TFour"]; | ||
| 67 | + self.barChart.yValues = @[@1, @10, @5, @4, @7]; | ||
| 68 | + expect(self.barChart.subviews.count).to.equal(0); | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +- (void)testChartBars | ||
| 72 | +{ | ||
| 73 | + self.barChart.barBackgroundColor = [UIColor greenColor]; | ||
| 74 | + self.barChart.yLabelFormatter = ^(CGFloat value) { | ||
| 75 | + return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value]; | ||
| 76 | + }; | ||
| 77 | + self.barChart.yValues = @[@1, @2, @3]; | ||
| 78 | + NSArray *strokeColour = @[[UIColor greenColor], [UIColor redColor], [UIColor purpleColor]]; | ||
| 79 | + self.barChart.strokeColors = strokeColour; | ||
| 80 | + [self.barChart strokeChart]; | ||
| 81 | + for (NSUInteger idx = 0; idx < self.barChart.bars.count; idx++) { | ||
| 82 | + PNBar *bar = self.barChart.bars[idx]; | ||
| 83 | + expect(bar.backgroundColor).to.equal([UIColor greenColor]); | ||
| 84 | + expect(bar.barColor).to.equal(strokeColour[idx]); | ||
| 85 | + } | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +- (void)testStrokeColor | ||
| 89 | +{ | ||
| 90 | + self.barChart.yLabelFormatter = ^(CGFloat value) { | ||
| 91 | + return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value]; | ||
| 92 | + }; | ||
| 93 | + self.barChart.yValues = @[@1, @2, @3]; | ||
| 94 | + self.barChart.strokeColor = [UIColor magentaColor]; | ||
| 95 | + self.barChart.strokeColors = @[[UIColor greenColor], [UIColor redColor]]; | ||
| 96 | + [self.barChart strokeChart]; | ||
| 97 | + for (NSUInteger idx = 0; idx < self.barChart.bars.count; idx++) { | ||
| 98 | + PNBar *bar = self.barChart.bars[idx]; | ||
| 99 | + expect(bar.barColor).equal(self.barChart.strokeColor); | ||
| 100 | + } | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +- (void)testMaxValue | ||
| 104 | +{ | ||
| 105 | + self.barChart.yLabelFormatter = ^(CGFloat value) { | ||
| 106 | + return [NSString stringWithFormat:@"Value %zi", (NSUInteger)value]; | ||
| 107 | + }; | ||
| 108 | + self.barChart.yMaxValue = 8; | ||
| 109 | + self.barChart.yValues = @[@10, @8, @7, @3]; | ||
| 110 | + NSArray *expectedResults = @[@8, @6, @4, @2]; | ||
| 111 | + for (NSUInteger idx = 0; idx < expectedResults.count; idx++) { | ||
| 112 | + UILabel *yAxisLabel = self.barChart.subviews[idx]; | ||
| 113 | + expect(yAxisLabel.text).to.equal([NSString stringWithFormat:@"Value %@", expectedResults[idx]]); | ||
| 114 | + } | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +@end |
| @@ -2,3 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git' | @@ -2,3 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git' | ||
| 2 | 2 | ||
| 3 | platform :ios, '6.0' | 3 | platform :ios, '6.0' |
| 4 | pod 'UICountingLabel','~> 1.2.0' | 4 | pod 'UICountingLabel','~> 1.2.0' |
| 5 | + | ||
| 6 | +target :PNChartTests do | ||
| 7 | + pod 'Expecta' | ||
| 8 | +end |
| 1 | PODS: | 1 | PODS: |
| 2 | + - Expecta (0.3.2) | ||
| 2 | - UICountingLabel (1.2.0) | 3 | - UICountingLabel (1.2.0) |
| 3 | 4 | ||
| 4 | DEPENDENCIES: | 5 | DEPENDENCIES: |
| 6 | + - Expecta | ||
| 5 | - UICountingLabel (~> 1.2.0) | 7 | - UICountingLabel (~> 1.2.0) |
| 6 | 8 | ||
| 7 | SPEC CHECKSUMS: | 9 | SPEC CHECKSUMS: |
| 8 | - UICountingLabel: a55223a9357af71f833af76665164d2e3f3654b5 | 10 | + Expecta: 8c507baf13211207b1e9d0a741480600e6b4ed15 |
| 11 | + UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa | ||
| 9 | 12 | ||
| 10 | -COCOAPODS: 0.35.0 | 13 | +COCOAPODS: 0.36.4 |
-
Please register or login to post a comment