Permalink
Browse files

Added a unit test to determine if 'conformToProtocol' was properly id…

…entifying a class conforming to a protocol via inheritance
  • Loading branch information...
1 parent 859ce82 commit 4863025296586f758fe6fd29a03044c414d1bc42 @aspitz aspitz committed Oct 4, 2012
@@ -0,0 +1,16 @@
+//
+// Expression2.h
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreParse/CoreParse.h>
+
+@interface Expression2 : NSObject <CPParseResult>
+
+@property (readwrite,assign) float value;
+
+@end
@@ -0,0 +1,41 @@
+//
+// Expression2.m
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "Expression2.h"
+#import "Term2.h"
+
+@implementation Expression2
+
+@synthesize value;
+
+- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree{
+ self = [self init];
+
+ if (nil != self){
+ NSArray *components = [syntaxTree children];
+ if ([components count] == 1){
+ NSObject *term2 = [components objectAtIndex:0];
+ if ([term2 isMemberOfClass:[Term2 class]]){
+ self.value = [(Term2 *)term2 value];
+ } else {
+ self.value = -1;
+ }
+ } else {
+ NSObject *term2 = [components objectAtIndex:2];
+ if ([term2 isMemberOfClass:[Term2 class]]){
+ self.value = [(Expression2 *)[components objectAtIndex:0] value] + [(Term2 *)term2 value];
+ } else {
+ self.value = -1;
+ }
+ }
+ }
+
+ return self;
+}
+
+@end
View
@@ -0,0 +1,14 @@
+//
+// RuleBase.h
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreParse/CoreParse.h>
+
+@interface RuleBase : NSObject <CPParseResult>
+
+@end
View
@@ -0,0 +1,21 @@
+//
+// RuleBase.m
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "RuleBase.h"
+
+@implementation RuleBase
+
+- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree{
+ self = [super init];
+ if (nil != self){
+ }
+
+ return self;
+}
+
+@end
View
@@ -0,0 +1,15 @@
+//
+// Term2.h
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "RuleBase.h"
+
+@interface Term2 : RuleBase
+
+@property (readwrite,assign) float value;
+
+@end
View
@@ -0,0 +1,24 @@
+//
+// Term2.m
+// CoreParse
+//
+// Created by Ayal Spitz on 10/4/12.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "Term2.h"
+
+@implementation Term2
+
+@synthesize value;
+
+- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree{
+ self = [super init];
+ if (nil != self){
+ [self setValue:[[(CPNumberToken *)[[syntaxTree children] objectAtIndex:0] number] floatValue]];
+ }
+
+ return self;
+}
+
+@end

0 comments on commit 4863025

Please sign in to comment.