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