我想比较两个数组的等效对象,一个是我的类中的属性,另一个是我的测试方法中的属性。
我无法直接比较,因为对象将被单独分配,因此具有不同的内存位置。
为了解决这个问题,我在我的对象上实现了描述,以在字符串中列出它的属性:(vel 是一个 CGPoint)
- (NSString *)description {
return [NSString stringWithFormat:@"vel:%.5f%.5f",vel.x,vel.y];
}
我测试:
NSLog(@"moveArray description: %@",[moveArray description]);
NSLog(@"currentMoves description: %@", [p.currentMoves description]);
[[theValue([moveArray description]) should] equal:theValue([p.currentMoves description])];
我的 NSLog 的产量:
Project[13083:207] moveArray description: (
"vel:0.38723-0.92198"
)
Project[13083:207] currentMoves description: (
"vel:0.38723-0.92198"
)
但是我的测试失败了:
/ProjectPath/ObjectTest.m:37: error: -[ObjectTest example] : 'Object should pass test' [FAILED], expected subject to equal <9086b104>, got <7099e004>
theValue 用字节和 Objective-C 类型初始化 KWValue,并用
- (id)initWithBytes:(const void *)bytes objCType:(const char *)anObjCType {
if ((self = [super init])) {
objCType = anObjCType;
value = [[NSValue alloc] initWithBytes:bytes objCType:anObjCType];
}
return self;
}
我如何比较这两个数组具有等效值的对象?