Permalink
Browse files

Some assertions to make sure operators are correctly defined

  • Loading branch information...
1 parent 39ba9ce commit 0aad7165e418d7b209460c1fde684ef42632725f @davedelong committed Dec 16, 2011
Showing with 11 additions and 0 deletions.
  1. +11 −0 DDMathParser/_DDOperatorInfo.m
View
11 DDMathParser/_DDOperatorInfo.m
@@ -49,6 +49,17 @@ + (NSArray *)infosForOperatorFunction:(NSString *)operator {
}
[value addObject:info];
}
+
+ // this is to make sure all of the operators are defined correctly
+ for (NSString *functionName in _operatorLookup) {
+ NSArray *operatorInfos = [_operatorLookup objectForKey:functionName];
+ _DDOperatorInfo *baseInfo = [operatorInfos lastObject];
+ for (_DDOperatorInfo *info in operatorInfos) {
+ NSAssert([info precedence] == [baseInfo precedence], @"mismatched operator precedences");
+ NSAssert([info arity] == [baseInfo arity], @"mismatched operator arity");
+ NSAssert([info defaultAssociativity] == [baseInfo defaultAssociativity], @"mismatched operator associativity");
+ }
+ }
});
return [_operatorLookup objectForKey:operator];
}

0 comments on commit 0aad716

Please sign in to comment.