Archived
1

Added/Corrected Tests (see previous commits)

This commit is contained in:
Kim Wittenburg
2014-04-23 03:11:54 +02:00
parent 2163f24509
commit 8605a6ac7b
2 changed files with 43 additions and 36 deletions

View File

@@ -40,6 +40,13 @@
[testExpression setString:@"abc"]; [testExpression setString:@"abc"];
XCTAssertEqual([testExpression numberOfSymbols], 1); XCTAssertEqual([testExpression numberOfSymbols], 1);
// abc // abc
[testExpression setString:@""];
XCTAssertEqual([testExpression numberOfSymbols], 0);
//
[testExpression setString:@"1234"];
XCTAssertEqual([testExpression numberOfSymbols], 1);
} }
- (void)testInvalidMutatingRange { - (void)testInvalidMutatingRange {

View File

@@ -8,7 +8,7 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "MPRange.h" #import "MPRangePath.h"
@interface MPRangeTests : XCTestCase @interface MPRangeTests : XCTestCase
@@ -17,79 +17,79 @@
@implementation MPRangeTests @implementation MPRangeTests
- (void)testInitialization { - (void)testInitialization {
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndex:1] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndex:1] length:5];
XCTAssertEqualObjects(range.location, [[NSIndexPath alloc] initWithIndex:1]); XCTAssertEqualObjects(rangePath.location, [[NSIndexPath alloc] initWithIndex:1]);
XCTAssertEqual(range.length, 5); XCTAssertEqual(rangePath.length, 5);
range = [[MPRange alloc] initWithRange:NSMakeRange(3, 2)]; rangePath = [[MPRangePath alloc] initWithRange:NSMakeRange(3, 2)];
XCTAssertEqualObjects(range.location, [[NSIndexPath alloc] initWithIndex:3]); XCTAssertEqualObjects(rangePath.location, [[NSIndexPath alloc] initWithIndex:3]);
XCTAssertEqual(range.length, 2); XCTAssertEqual(rangePath.length, 2);
range = [MPRange emptyRange]; rangePath = [MPRangePath emptyRangePath];
XCTAssertEqualObjects(range.location, [[NSIndexPath alloc] init]); XCTAssertEqualObjects(rangePath.location, [[NSIndexPath alloc] init]);
XCTAssertEqual(range.length, 0); XCTAssertEqual(rangePath.length, 0);
} }
- (void)testMaxRange { - (void)testMaxRange {
NSUInteger indexes[] = {5, 2, 7, 3}; NSUInteger indexes[] = {5, 2, 7, 3};
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5];
NSUInteger expectedIndexes[] = {5, 2, 7, 8}; NSUInteger expectedIndexes[] = {5, 2, 7, 8};
XCTAssertEqualObjects([range maxRange], [[NSIndexPath alloc] initWithIndexes:expectedIndexes length:4]); XCTAssertEqualObjects([rangePath maxRangePath], [[NSIndexPath alloc] initWithIndexes:expectedIndexes length:4]);
} }
- (void)testRangeAtLastIndex { - (void)testRangeAtLastIndex {
NSUInteger indexes[] = {5, 2, 7, 3}; NSUInteger indexes[] = {5, 2, 7, 3};
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5];
XCTAssertTrue(NSEqualRanges(range.rangeAtLastIndex, NSMakeRange(3, 5))); XCTAssertTrue(NSEqualRanges(rangePath.rangeAtLastIndex, NSMakeRange(3, 5)));
} }
- (void)testEquality { - (void)testEquality {
NSUInteger indexes[] = {5, 2, 7, 3}; NSUInteger indexes[] = {5, 2, 7, 3};
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5];
NSUInteger otherIndexes[] = {5, 2, 7, 3}; NSUInteger otherIndexes[] = {5, 2, 7, 3};
MPRange *otherRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:otherIndexes length:4] length:5]; MPRangePath *otherRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:otherIndexes length:4] length:5];
NSUInteger yetOtherIndexes[] = {5, 2, 6, 3}; NSUInteger yetOtherIndexes[] = {5, 2, 6, 3};
MPRange *yetAnotherRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:yetOtherIndexes length:4] length:5]; MPRangePath *yetAnotherRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:yetOtherIndexes length:4] length:5];
XCTAssertTrue([range isEqual:otherRange]); XCTAssertTrue([rangePath isEqual:otherRange]);
XCTAssertFalse([range isEqual:yetAnotherRange]); XCTAssertFalse([rangePath isEqual:yetAnotherRange]);
} }
- (void)testCopying { - (void)testCopying {
NSUInteger indexes[] = {5, 2, 7, 3}; NSUInteger indexes[] = {5, 2, 7, 3};
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5];
MPRange *copy = [range copy]; MPRangePath *copy = [rangePath copy];
XCTAssertNotEqual(range, copy); XCTAssertNotEqual(rangePath, copy);
XCTAssertEqualObjects(range, copy); XCTAssertEqualObjects(rangePath, copy);
} }
- (void)testContainsRange { - (void)testContainsRange {
NSUInteger indexes[] = {5, 2, 7, 3}; NSUInteger indexes[] = {5, 2, 7, 3};
MPRange *range = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5]; MPRangePath *rangePath = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:indexes length:4] length:5];
NSUInteger shorterPathIndexes[] = {5, 2}; NSUInteger shorterPathIndexes[] = {5, 2};
MPRange *shorterPathRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:shorterPathIndexes length:2] length:5]; MPRangePath *shorterPathRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:shorterPathIndexes length:2] length:5];
NSUInteger longerPathIndexes[] = {5, 2, 7, 3, 5}; NSUInteger longerPathIndexes[] = {5, 2, 7, 3, 5};
MPRange *longerPathRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:longerPathIndexes length:5] length:5]; MPRangePath *longerPathRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:longerPathIndexes length:5] length:5];
NSUInteger differentPathIndexes[] = {5, 3, 7, 3}; NSUInteger differentPathIndexes[] = {5, 3, 7, 3};
MPRange *differentPathRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:differentPathIndexes length:4] length:5]; MPRangePath *differentPathRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:differentPathIndexes length:4] length:5];
NSUInteger equalRangeIndexes[] = {5, 2, 7, 3}; NSUInteger equalRangeIndexes[] = {5, 2, 7, 3};
MPRange *equalRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:equalRangeIndexes length:4] length:5]; MPRangePath *equalRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:equalRangeIndexes length:4] length:5];
NSUInteger containedRangeIndexes[] = {5, 2, 7, 4}; NSUInteger containedRangeIndexes[] = {5, 2, 7, 4};
MPRange *containedRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:containedRangeIndexes length:4] length:2]; MPRangePath *containedRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:containedRangeIndexes length:4] length:2];
NSUInteger largerRangeIndexes[] = {5, 2, 7, 4}; NSUInteger largerRangeIndexes[] = {5, 2, 7, 4};
MPRange *largerRange = [[MPRange alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:largerRangeIndexes length:4] length:7]; MPRangePath *largerRange = [[MPRangePath alloc] initWithLocation:[[NSIndexPath alloc] initWithIndexes:largerRangeIndexes length:4] length:7];
XCTAssertFalse([range containsRange:shorterPathRange]); XCTAssertFalse([rangePath containsRangePath:shorterPathRange]);
XCTAssertTrue([range containsRange:longerPathRange]); XCTAssertTrue([rangePath containsRangePath:longerPathRange]);
XCTAssertFalse([range containsRange:differentPathRange]); XCTAssertFalse([rangePath containsRangePath:differentPathRange]);
XCTAssertTrue([range containsRange:equalRange]); XCTAssertTrue([rangePath containsRangePath:equalRange]);
XCTAssertTrue([range containsRange:containedRange]); XCTAssertTrue([rangePath containsRangePath:containedRange]);
XCTAssertFalse([range containsRange:largerRange]); XCTAssertFalse([rangePath containsRangePath:largerRange]);
} }
@end @end