PageRenderTime 64ms CodeModel.GetById 26ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/NSMutableArrayBlocksKitTest.m

http://github.com/zwaldowski/BlocksKit
Objective C | 84 lines | 65 code | 15 blank | 4 comment | 0 complexity | 3bfd0f37035b5aa101fdc5c448e3a4f2 MD5 | raw file
 1//
 2//  NSMutableArrayBlocksKitTest.m
 3//  BlocksKit Unit Tests
 4//
 5
 6#import "NSMutableArrayBlocksKitTest.h"
 7
 8@implementation NSMutableArrayBlocksKitTest {
 9	NSMutableArray *_subject;
10	NSInteger _total;
11}
12
13- (void)setUp {
14	_subject = [[NSMutableArray alloc] initWithObjects:@"1",@"22",@"333",nil];
15	_total = 0;
16}
17
18- (void)tearDown {
19	[_subject release];
20}  
21
22- (void)testSelect {
23	BKValidationBlock validationBlock = ^(id obj) {
24		_total += [obj length];
25		BOOL match = ([obj intValue] < 300) ? YES : NO;
26		return match;
27	};
28	[_subject performSelect:validationBlock];
29
30	GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
31	NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"22",nil];
32	GHAssertEqualObjects(_subject,target,@"selected items are %@",_subject);
33}
34
35- (void)testSelectedNone {
36	BKValidationBlock validationBlock = ^(id obj) {
37		_total += [obj length];
38		BOOL match = ([obj intValue] > 400) ? YES : NO;
39		return match;
40	};
41	[_subject performSelect:validationBlock];
42
43	GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
44	GHAssertEquals(_subject.count,(NSUInteger)0,@"no item is selected");
45}
46
47- (void)testReject {
48	BKValidationBlock validationBlock = ^(id obj) {
49		_total += [obj length];
50		BOOL match = ([obj intValue] > 300) ? YES : NO;
51		return match;
52	};
53	[_subject performReject:validationBlock];
54
55	GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
56	NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"22",nil];
57	GHAssertEqualObjects(_subject,target,@"not rejected items are %@",_subject);
58}
59
60- (void)testRejectedAll {
61	BKValidationBlock validationBlock = ^(id obj) {
62		_total += [obj length];
63		BOOL match = ([obj intValue] < 400) ? YES : NO;
64		return match;
65	};
66	[_subject performReject:validationBlock];
67
68	GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
69	GHAssertEquals(_subject.count,(NSUInteger)0,@"all items are rejected");
70}
71
72- (void)testMap {
73	BKTransformBlock transformBlock = ^id(id obj) {
74		_total += [obj length];
75		return [obj substringToIndex:1];
76	};
77	[_subject performMap:transformBlock];
78
79	GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
80	NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",nil];
81	GHAssertEqualObjects(_subject,target,@"transformed items are %@",_subject);
82}
83
84@end