1

最近 iOS 5 から iOS 6 にアップグレードしたところ、この単体テストが失敗することがわかりました

- (void)testCalculatesDistanceBetweenTwoPoints
{
    self.sut = [[DistanceCalculator alloc] init];
    CLLocationCoordinate2D start = {.latitude = 34.32, .longitude = 99.13};
    CLLocationCoordinate2D finish = {.latitude = 105.94, .longitude = 27.73};
    NSNumber *distance = [self.sut kilometresBetweenPlace1:start andPlace2:finish];
    NSNumber *expected = [NSNumber numberWithDouble:3822.23073702318];
    STAssertEqualObjects(distance, expected, @"");
}

失敗したアサート

「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];
}
4

1 に答える 1

0

この議論に従うかもしれない人のために-これが私が最終的に得たものです

- (void)testCalculatesDistanceBetweenTwoPoints
{
    double accuracy = 0.00000000001;
    self.sut = [[DistanceCalculator alloc] init];
    CLLocationCoordinate2D start = {.latitude = 34.32, .longitude = 99.13};
    CLLocationCoordinate2D finish = {.latitude = 105.94, .longitude = 27.73};
    NSNumber *distance = [self.sut kilometresBetweenPlace1:start andPlace2:finish];
    NSNumber *expected = [NSNumber numberWithDouble:3822.23073702318];
    STAssertEqualsWithAccuracy([distance doubleValue], [expected doubleValue], accuracy, @"");
}
于 2012-10-24T02:10:48.560 に答える