/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. #import "NSMutableArrayBlocksKitTest.h"
  6. @implementation NSMutableArrayBlocksKitTest {
  7. NSMutableArray *_subject;
  8. NSInteger _total;
  9. }
  10. - (void)setUp {
  11. _subject = [[NSMutableArray alloc] initWithObjects:@"1",@"22",@"333",nil];
  12. _total = 0;
  13. }
  14. - (void)tearDown {
  15. [_subject release];
  16. }
  17. - (void)testSelect {
  18. BKValidationBlock validationBlock = ^(id obj) {
  19. _total += [obj length];
  20. BOOL match = ([obj intValue] < 300) ? YES : NO;
  21. return match;
  22. };
  23. [_subject performSelect:validationBlock];
  24. GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
  25. NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"22",nil];
  26. GHAssertEqualObjects(_subject,target,@"selected items are %@",_subject);
  27. }
  28. - (void)testSelectedNone {
  29. BKValidationBlock validationBlock = ^(id obj) {
  30. _total += [obj length];
  31. BOOL match = ([obj intValue] > 400) ? YES : NO;
  32. return match;
  33. };
  34. [_subject performSelect:validationBlock];
  35. GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
  36. GHAssertEquals(_subject.count,(NSUInteger)0,@"no item is selected");
  37. }
  38. - (void)testReject {
  39. BKValidationBlock validationBlock = ^(id obj) {
  40. _total += [obj length];
  41. BOOL match = ([obj intValue] > 300) ? YES : NO;
  42. return match;
  43. };
  44. [_subject performReject:validationBlock];
  45. GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
  46. NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"22",nil];
  47. GHAssertEqualObjects(_subject,target,@"not rejected items are %@",_subject);
  48. }
  49. - (void)testRejectedAll {
  50. BKValidationBlock validationBlock = ^(id obj) {
  51. _total += [obj length];
  52. BOOL match = ([obj intValue] < 400) ? YES : NO;
  53. return match;
  54. };
  55. [_subject performReject:validationBlock];
  56. GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
  57. GHAssertEquals(_subject.count,(NSUInteger)0,@"all items are rejected");
  58. }
  59. - (void)testMap {
  60. BKTransformBlock transformBlock = ^id(id obj) {
  61. _total += [obj length];
  62. return [obj substringToIndex:1];
  63. };
  64. [_subject performMap:transformBlock];
  65. GHAssertEquals(_total,6,@"total length of \"122333\" is %d",_total);
  66. NSMutableArray *target = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",nil];
  67. GHAssertEqualObjects(_subject,target,@"transformed items are %@",_subject);
  68. }
  69. @end