我想比較兩個數組的等效對象,其中一個屬性在我的類中,另一個在我的測試方法中。比較兩個陣列的等效對象與Kiwi(Sentesting)套件
我無法直接比較,因爲對象將被分開分配,因此具有不同的內存位置。
爲了解決這個問題,我實現我的目標字符串中,列出其屬性的描述:(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初始化與字節KWValue和物鏡-C型,並將其值與
- (id)initWithBytes:(const void *)bytes objCType:(const char *)anObjCType {
if ((self = [super init])) {
objCType = anObjCType;
value = [[NSValue alloc] initWithBytes:bytes objCType:anObjCType];
}
return self;
}
如何可以比較這兩個陣列具有等價的值的對象?
完美,謝謝。歡迎來到SO! – quantumpotato
謝謝,很高興我能幫上忙。 – Sticktron