PageRenderTime 75ms CodeModel.GetById 38ms app.highlight 26ms RepoModel.GetById 9ms app.codeStats 0ms

/Tests/NSMutableDictionaryBlocksKitTest.m

http://github.com/zwaldowski/BlocksKit
Objective C | 98 lines | 83 code | 11 blank | 4 comment | 0 complexity | 79f89a02a19e5caa68f90bf7490bc474 MD5 | raw file
 1//
 2//  NSMutableDictionaryBlocksKitTest.m
 3//  BlocksKit Unit Tests
 4//
 5
 6#import "NSMutableDictionaryBlocksKitTest.h"
 7
 8
 9@implementation NSMutableDictionaryBlocksKitTest {
10	NSMutableDictionary *_subject;
11	NSInteger _total;
12}
13
14- (void)setUp {
15	_subject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
16		[NSNumber numberWithInteger:1],@"1",
17		[NSNumber numberWithInteger:2],@"2",
18		[NSNumber numberWithInteger:3],@"3",
19		nil
20	];
21	_total = 0;
22}
23
24- (void)tearDown {
25	[_subject release];
26}  
27
28- (void)testSelect {
29	BKKeyValueValidationBlock validationBlock = ^(id key,id value) {
30		_total += [value intValue] + [key intValue];
31		BOOL select = [value intValue] < 3 ? YES : NO;
32		return select;
33	};
34	[_subject performSelect:validationBlock];
35	GHAssertEquals(_total,12,@"2*(1+2+3) = %d",_total);
36	NSMutableDictionary *target = [NSMutableDictionary dictionaryWithObjectsAndKeys:
37		[NSNumber numberWithInteger:1],@"1",
38		[NSNumber numberWithInteger:2],@"2",
39		nil
40	];
41	GHAssertEqualObjects(_subject,target,@"selected dictionary is %@",_subject);
42}
43
44- (void)testSelectedNone {
45	BKKeyValueValidationBlock validationBlock = ^(id key,id value) {
46		_total += [value intValue] + [key intValue];
47		BOOL select = [value intValue] > 4 ? YES : NO;
48		return select;
49	};
50	[_subject performSelect:validationBlock];
51	GHAssertEquals(_total,12,@"2*(1+2+3) = %d",_total);
52	GHAssertEquals(_subject.count,(NSUInteger)0,@"no item is selected");
53}
54
55- (void)testReject {
56	BKKeyValueValidationBlock validationBlock = ^(id key,id value) {
57		_total += [value intValue] + [key intValue];
58		BOOL reject = [value intValue] > 2 ? YES : NO;
59		return reject;
60	};
61	[_subject performReject:validationBlock];
62	GHAssertEquals(_total,12,@"2*(1+2+3) = %d",_total);
63	NSMutableDictionary *target = [NSMutableDictionary dictionaryWithObjectsAndKeys:
64		[NSNumber numberWithInteger:1],@"1",
65		[NSNumber numberWithInteger:2],@"2",
66		nil
67	];
68	GHAssertEqualObjects(_subject,target,@"dictionary after reject is %@",_subject);
69}
70
71- (void)testRejectedAll {
72	BKKeyValueValidationBlock validationBlock = ^(id key,id value) {
73		_total += [value intValue] + [key intValue];
74		BOOL reject = [value intValue] < 4 ? YES : NO;
75		return reject;
76	};
77	[_subject performReject:validationBlock];
78	GHAssertEquals(_total,12,@"2*(1+2+3) = %d",_total);
79	GHAssertEquals(_subject.count,(NSUInteger)0,@"all items are rejected");
80}
81
82- (void)testMap {
83	BKKeyValueTransformBlock transformBlock = ^id(id key,id value) {
84		_total += [value intValue] + [key intValue];
85		return [NSNumber numberWithInteger:_total];
86	};
87	[_subject performMap:transformBlock];
88	GHAssertEquals(_total,12,@"2*(1+2+3) = %d",_total);
89	NSMutableDictionary *target = [NSMutableDictionary dictionaryWithObjectsAndKeys:
90		[NSNumber numberWithInteger:2],@"1",
91		[NSNumber numberWithInteger:6],@"2",
92		[NSNumber numberWithInteger:12],@"3",
93		nil
94	];
95	GHAssertEqualObjects(_subject,target,@"transformed dictionary is %@",_subject);
96}
97
98@end