1 つはクラス内のプロパティ、もう 1 つはテスト メソッド内の同等のオブジェクトの 2 つの配列を比較したいと考えています。
オブジェクトは個別に割り当てられるため、メモリの場所が異なるため、直接比較することはできません。
これを回避するために、オブジェクトに説明を実装して、そのプロパティを文字列でリストします: (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;
}
これら 2 つの配列に同じ値のオブジェクトがあることを比較するにはどうすればよいですか?