1
我最近從iOS 5的升級到iOS 6,發現這個單元測試失敗如何比較NSNumber與十進制值?
失敗斷言
'3822.23073702318' 應等於 '3822.23073702318'
當我打印每個數字的原始值時,我會得到看起來相同的值
2012-10-23 20:01:42.970 HelloWorld[1573:c07] 1 3822.23073702318
2012-10-23 20:01:42.970 HelloWorld[1573:c07] 2 3822.23073702318
當我打印每個號碼的類型我得到什麼樣子一樣(可能我做這錯了嗎?)
2012-10-23 20:06:37.309 HelloWorld[1611:c07] 1 __NSCFNumber
2012-10-23 20:06:37.309 HelloWorld[1611:c07] 2 __NSCFNumber
這裏是完全成熟的實施是否有幫助
- (NSNumber *)kilometresBetweenPlace1:(CLLocationCoordinate2D)place1 andPlace2:(CLLocationCoordinate2D)place2
{
MKMapPoint start = MKMapPointForCoordinate(place1);
MKMapPoint finish = MKMapPointForCoordinate(place2);
double distance = MKMetersBetweenMapPoints(start, finish)/1600;
return [NSNumber numberWithDouble:distance];
}
檢查非整數的相等性總是風險,由於舍入誤差。你應該檢查一下,該值是否在一定範圍內。 – vikingosegundo
我確實看到一個ocunit方法「STAssertEqualsWithAccuracy」 - 有人用這個成功了嗎? –
@CodaFi爲什麼浮動值而不是雙倍?這不會削減一噸的準確性嗎? –