現在、緯度と経度の値を NSString として保持する単純なオブジェクトを使用しています。しかし、それらが等しいと主張しようとすると、このアプローチで失敗します
- (void) testLocationParseJson {
NSArray* items = //some array the represents the json returned from google ...
LocationParseJson* sut = [[LocationParseJson alloc] init];
Location* actualLocation = [sut parseJson:items];
NSString* actualLatitude = actualLocation.lat;
NSString* actualLongitude = actualLocation.lng;
STAssertEqualObjects(expectedLocation.lat, actualLocation.lat, @"The actual location latitude was %@", actualLocation.lat);
}
ここに表示されるエラーです
エラー: -[LocationParseJsonTest testLocationParseJson]: '41.6756668' は '41.6756668' と等しくなければなりません実際の場所の緯度は 41.6756668 でした
代わりに、「isEqual」を使用して AssertTrue アプローチを試しました
STAssertTrue([expectedLocation.lat isEqual: actualLocation.lat], @"The actual location latitude was %@", actualLocation.lat);
そして、私は同じエラーが発生します
エラー: -[LocationParseJsonTest testLocationParseJson] : "[expectedLocation.lat isEqual: actualLocation.lat]" は true である必要があります。実際の場所の緯度は 41.6756668 でした
これらの NSString 値を ocUnit で比較するにはどうすればよいですか? これは場所fyiの.hファイルです
@interface Location : NSObject {
NSString* lng;
NSString* lat;
}
@property (nonatomic, retain) NSString* lng;
@property (nonatomic, retain) NSString* lat;
@end