forked from BlocksKit/BlocksKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSMutableSetBlocksKitTest.m
More file actions
82 lines (71 loc) · 2.44 KB
/
Copy pathNSMutableSetBlocksKitTest.m
File metadata and controls
82 lines (71 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// NSMutableSetBlocksKitTest.m
// BlocksKit Unit Tests
//
// Contributed by Kai Wu.
//
#import <XCTest/XCTest.h>
#import <BlocksKit/NSMutableSet+BlocksKit.h>
@interface NSMutableSetBlocksKitTest : XCTestCase
@end
@implementation NSMutableSetBlocksKitTest {
NSMutableSet *_subject;
NSInteger _total;
}
- (void)setUp {
_subject = [NSMutableSet setWithArray:@[ @"1", @"22", @"333"]];;
_total = 0;
}
- (void)testSelect {
BOOL(^validationBlock)(id) = ^(NSString *obj) {
_total += [obj length];
BOOL match = ([obj intValue] < 300) ? YES : NO;
return match;
};
[_subject bk_performSelect:validationBlock];
XCTAssertEqual(_total,(NSInteger)6,@"total length of \"122333\" is %ld", (long)_total);
NSMutableSet *target = [NSMutableSet setWithArray:@[ @"1", @"22" ]];
XCTAssertEqualObjects(_subject,target,@"selected items are %@",_subject);
}
- (void)testSelectedNone {
BOOL(^validationBlock)(id) = ^(NSString *obj) {
_total += [obj length];
BOOL match = ([obj intValue] > 400) ? YES : NO;
return match;
};
[_subject bk_performSelect:validationBlock];
XCTAssertEqual(_total,(NSInteger)6,@"total length of \"122333\" is %ld", (long)_total);
XCTAssertEqual(_subject.count,(NSUInteger)0,@"no item is selected");
}
- (void)testReject {
BOOL(^validationBlock)(id) = ^(NSString *obj) {
_total += [obj length];
BOOL match = ([obj intValue] > 300) ? YES : NO;
return match;
};
[_subject bk_performReject:validationBlock];
XCTAssertEqual(_total,(NSInteger)6,@"total length of \"122333\" is %ld", (long)_total);
NSMutableSet *target = [NSMutableSet setWithArray:@[ @"1", @"22" ]];
XCTAssertEqualObjects(_subject,target,@"not rejected items are %@",_subject);
}
- (void)testRejectedAll {
BOOL(^validationBlock)(id) = ^(NSString *obj) {
_total += [obj length];
BOOL match = ([obj intValue] < 400) ? YES : NO;
return match;
};
[_subject bk_performReject:validationBlock];
XCTAssertEqual(_total,(NSInteger)6,@"total length of \"122333\" is %ld", (long)_total);
XCTAssertEqual(_subject.count,(NSUInteger)0,@"all items are rejected");
}
- (void)testMap {
id(^transformBlock)(id) = ^(NSString *obj) {
_total += [obj length];
return [obj substringToIndex:1];
};
[_subject bk_performMap:transformBlock];
XCTAssertEqual(_total,(NSInteger)6,@"total length of \"122333\" is %ld", (long)_total);
NSMutableSet *target = [NSMutableSet setWithArray:@[ @"1", @"2", @"3" ]];
XCTAssertEqualObjects(_subject,target,@"transformed items are %@",_subject);
}
@end