Permalink
Browse files

added all array method and tests

  • Loading branch information...
1 parent b624b53 commit 01b22209fc73d2c26c95db954ebded350c8afd54 @acburk committed Feb 11, 2012
Showing with 31 additions and 0 deletions.
  1. +1 −0 SOCQ/SOCQ+NSArray.h
  2. +9 −0 SOCQ/SOCQ+NSArray.m
  3. +21 −0 SOCQTests/SOCQTestsArrays.m
View
@@ -15,5 +15,6 @@
- (NSArray*)skip:(NSUInteger)inSkip take:(NSUInteger)inTake;
- (NSArray*)where:(BOOL(^)(id obj))check;
- (BOOL)any:(BOOL(^)(id obj))check;
+- (BOOL)all:(BOOL(^)(id obj))check;
@end
View
@@ -57,5 +57,14 @@ - (BOOL)any:(BOOL(^)(id obj))check {
return NO;
}
+- (BOOL)all:(BOOL(^)(id obj))check {
+ for (int i = 0; i < [self count]; i++) {
+ if (!check([self objectAtIndex:i]))
+ return NO;
+ }
+
+ return YES;
+}
+
@end
@@ -199,5 +199,26 @@ - (void)testAnySome {
return [obj length] == 4;
}], @"Statement should be true");
}
+- (void)testAnyAll {
+ STAssertTrue([testArray any:^BOOL(id obj) {
+ return [obj length] >= 1;
+ }], @"Statement should be true");
+}
+#pragma mark - any Tests
+- (void)testAllNone {
+ STAssertFalse([testArray all:^BOOL(id obj) {
+ return [obj length] >= 10;
+ }], @"Statement should be false");
+}
+- (void)testAllSome {
+ STAssertFalse([testArray all:^BOOL(id obj) {
+ return [obj length] >= 4;
+ }], @"Statement should be false");
+}
+- (void)testAllAll {
+ STAssertTrue([testArray all:^BOOL(id obj) {
+ return [obj length] >= 1;
+ }], @"Statement should be true");
+}
@end

0 comments on commit 01b2220

Please sign in to comment.