PageRenderTime 65ms CodeModel.GetById 41ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/NSMutableIndexSetBlocksKitTest.m

http://github.com/zwaldowski/BlocksKit
Objective C | 74 lines | 60 code | 10 blank | 4 comment | 1 complexity | ab9540bfb98c136ee5d967d17dcddcc8 MD5 | raw file
 1//
 2//  NSMutableIndexSetBlocksKitTest.m
 3//  BlocksKit Unit Tests
 4//
 5
 6#import "NSMutableIndexSetBlocksKitTest.h"
 7
 8
 9@implementation NSMutableIndexSetBlocksKitTest {
10	NSMutableIndexSet *_subject;
11	NSMutableArray *_target;
12}
13
14- (void)setUp {
15	_target = [[NSMutableArray alloc] initWithObjects:@"0",@"0",@"0",@"0",nil];
16	_subject = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(1, 3)];
17}
18
19- (void)tearDown {
20	[_target release];
21	[_subject release];
22}
23
24- (void)testSelect {
25	__block NSMutableString *order = [NSMutableString string];
26	BKIndexValidationBlock indexValidationBlock = ^(NSUInteger index) {
27		[order appendFormat:@"%d",index];
28		BOOL match = index < 3 ? YES : NO; //1,2
29		return match;
30	};
31	[_subject performSelect:indexValidationBlock];
32	GHAssertEqualStrings(order,@"123",@"the index loop order is %@",order);
33	NSMutableIndexSet *target = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(1,2)];
34	GHAssertEqualObjects(_subject,target,@"the selected index set is %@",_subject);
35}
36
37- (void)testSelectedNone {
38	__block NSMutableString *order = [NSMutableString string];
39	BKIndexValidationBlock indexValidationBlock = ^(NSUInteger index) {
40		[order appendFormat:@"%d",index];
41		BOOL match = index == 0 ? YES : NO;
42		return match;
43	};
44	[_subject performSelect:indexValidationBlock];
45	GHAssertEqualStrings(order,@"123",@"the index loop order is %@",order);
46	GHAssertEquals(_subject.count,(NSUInteger)0,@"no index found");
47}
48
49- (void)testReject {
50	__block NSMutableString *order = [NSMutableString string];
51	BKIndexValidationBlock indexValidationBlock = ^(NSUInteger index) {
52		[order appendFormat:@"%d",index];
53		BOOL match = [[_target objectAtIndex:index] isEqual: @"0"] ? YES : NO;
54		return match;
55	};
56	[_subject performReject:indexValidationBlock];
57	GHAssertEqualStrings(order,@"123",@"the index loop order is %@",order);
58	GHAssertEquals(_subject.count,(NSUInteger)0,@"all indexes are rejected");
59}
60
61- (void)testRejectedNone {
62	__block NSMutableString *order = [NSMutableString string];
63	BKIndexValidationBlock indexValidationBlock = ^(NSUInteger index) {
64		[order appendFormat:@"%d",index];
65		BOOL match = [[_target objectAtIndex:index] isEqual: @"0"] ? NO : YES;
66		return match;
67	};
68	[_subject performReject:indexValidationBlock];
69	GHAssertEqualStrings(order,@"123",@"the index loop order is %@",order);
70	NSMutableIndexSet *target = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(1,3)];
71	GHAssertEqualObjects(_subject,target,@"the rejected index set is %@",_subject);
72}
73
74@end