Permalink
Browse files

objcheck now uses selectors; no more arg extraction

  • Loading branch information...
1 parent 58f7fa2 commit f6b4e4d5aa08b6a73d23ac53dd223b27f77872c2 @mcandre committed Oct 16, 2011
Showing with 17 additions and 20 deletions.
  1. +1 −1 ObjCheck.h
  2. +2 −2 ObjCheck.m
  3. +2 −2 example.h
  4. +12 −15 example.m
View
2 ObjCheck.h
@@ -14,6 +14,6 @@
+ (NSArray *) genArray: (id(^)()) gen;
+ (NSString *) genString;
-+ forAll: (NSNumber*(^)(NSArray*)) property withGenerators: (NSArray *) generators;
++ forAll: (id) target withProperty: (SEL) property withGenerators: (NSArray *) generators;
@end
View
4 ObjCheck.m
@@ -65,7 +65,7 @@ + (NSString *) genString {
return s;
}
-+ forAll: (NSNumber*(^)(NSArray*)) property withGenerators: (NSArray *) generators {
++ forAll: (id) target withProperty: (SEL) property withGenerators: (NSArray *) generators {
int i, j;
for (i = 0; i < 100; i++) {
NSArray* values = [NSMutableArray array];
@@ -76,7 +76,7 @@ + (NSString *) genString {
values = [values arrayByAddingObject: value];
}
- NSNumber* propertyHolds = property(values);
+ NSNumber* propertyHolds = [target performSelector: property withArgs: values];
if(![propertyHolds boolValue]) {
printf("*** Failed!\n%s\n", [[values description] UTF8String]);
View
4 example.h
@@ -6,10 +6,10 @@
@interface Example: NSObject {}
-+ (NSNumber *) isEven: (NSArray *) args;
++ (NSNumber *) isEven: (NSNumber *) i;
+ (NSNumber *) genEven;
-+ (NSNumber *) reversible: (NSArray *) args;
++ (NSNumber *) reversible: (NSString *) s;
@end
View
27 example.m
@@ -24,9 +24,7 @@ - (NSString *) reverse {
@implementation Example
-+ (NSNumber *) isEven: (NSArray *) args {
- NSNumber* i = [args objectAtIndex: 0];
-
++ (NSNumber *) isEven: (NSNumber *) i {
BOOL b = [i intValue] % 2 == 0;
return [NSNumber numberWithBool: b];
@@ -42,12 +40,11 @@ + (NSNumber *) genEven {
return [NSNumber numberWithInt: i];
}
-+ (NSNumber *) reversible: (NSArray *) args {
- NSString* s = [args objectAtIndex: 0];
++ (NSNumber *) reversible: (NSString *) s {
NSString* r = [s reverse];
NSString* s2 = [r reverse];
- BOOL b = [s isEqualToString: s2];
+ BOOL b = [s isEqualToString: [[s reverse] reverse]];
return [NSNumber numberWithBool: b];
}
@@ -57,23 +54,23 @@ + (NSNumber *) reversible: (NSArray *) args {
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSArray* gs = [NSMutableArray array];
- gs = [gs arrayByAddingObject: ^() { return [ObjCheck genNum]; }];
+ NSMutableArray* gs = [NSMutableArray array];
+ [gs addObject: ^() { return [ObjCheck genNum]; }];
// Are all integers even?
- [ObjCheck forAll: ^(NSArray* args) { return [Example isEven: args]; } withGenerators: gs];
+ [ObjCheck forAll: [Example class] withProperty: @selector(isEven:) withGenerators: gs];
- NSArray* gs2 = [NSMutableArray array];
- gs2 = [gs2 arrayByAddingObject: ^() { return [Example genEven]; }];
+ NSMutableArray* gs2 = [NSMutableArray array];
+ [gs2 addObject: ^() { return [Example genEven]; }];
// Are all even integers even?
- [ObjCheck forAll: ^(NSArray* args) { return [Example isEven: args]; } withGenerators: gs2];
+ [ObjCheck forAll: [Example class] withProperty: @selector(isEven:) withGenerators: gs2];
- NSArray* gs3 = [NSMutableArray array];
- gs3 = [gs3 arrayByAddingObject: ^() { return [ObjCheck genString]; }];
+ NSMutableArray* gs3 = [NSMutableArray array];
+ [gs3 addObject: ^() { return [ObjCheck genString]; }];
// Are all strings reversible?
- [ObjCheck forAll: ^(NSArray* args) { return [Example reversible: args]; } withGenerators: gs3];
+ [ObjCheck forAll: [Example class] withProperty: @selector(reversible:) withGenerators: gs3];
[pool drain];

0 comments on commit f6b4e4d

Please sign in to comment.