나는 두 가지 기능을 정의하고있어 영향을하나 개의 단위 테스트는 다른
MKMapRect MKMapRectForCoordinateRegion(MKCoordinateRegion region)
{
CLLocationCoordinate2D center = region.center;
MKCoordinateSpan span = region.span;
CLLocationCoordinate2D topLeft =
CLLocationCoordinate2DMake(center.latitude - span.latitudeDelta/2.0,
center.longitude - span.longitudeDelta/2.0);
CLLocationCoordinate2D bottomRight =
CLLocationCoordinate2DMake(center.latitude - span.latitudeDelta/2.0,
center.longitude - span.longitudeDelta/2.0);
MKMapPoint mapPointTopLeft = MKMapPointForCoordinate(topLeft);
MKMapPoint mapPointBottomRight = MKMapPointForCoordinate(bottomRight);
double width = mapPointTopLeft.x - mapPointBottomRight.x;
double height = mapPointTopLeft.y - mapPointBottomRight.y;
return MKMapRectMake(mapPointTopLeft.x, mapPointTopLeft.y, width, height);
}
MKCoordinateRegion MKCoordinateRegionForSouthWestAndNorthEast(CLLocationCoordinate2D sw, CLLocationCoordinate2D ne)
{
MKCoordinateSpan span =
MKCoordinateSpanMake(ne.latitude - sw.latitude, ne.longitude - sw.longitude);
CLLocationCoordinate2D topLeft = CLLocationCoordinate2DMake(ne.latitude, sw.longitude);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(topLeft.latitude + span.latitudeDelta * 0.5, topLeft.longitude + span.longitudeDelta * 0.5);
return MKCoordinateRegionMake(center, span);
}
두 파일의 거의 전부입니다. XCTests 내 단위 테스트에서
:
- (void)testMKMapRectForCoordinateRegionAfterReverseConversion
{
CLLocationCoordinate2D fremont = CLLocationCoordinate2DMake(37.54827, -121.98857);
MKCoordinateRegion region = MKCoordinateRegionMake(fremont, MKCoordinateSpanMake(0.05, 0.05));
MKMapRect mapRect = MKMapRectForCoordinateRegion(region);
MKCoordinateRegion derivedRegion = MKCoordinateRegionForMapRect(mapRect);
double accuracy = 0.0001;
XCTAssertEqualWithAccuracy(region.center.latitude, derivedRegion.center.latitude,
accuracy, @"Latitude is equal");
XCTAssertEqualWithAccuracy(region.center.longitude, derivedRegion.center.longitude,
accuracy, @"Latitude is equal");
XCTAssertEqualWithAccuracy(region.span.latitudeDelta, derivedRegion.span.latitudeDelta,
accuracy, @"Latitude delta is equal");
XCTAssertEqualWithAccuracy(region.span.longitudeDelta, derivedRegion.span.longitudeDelta,
accuracy, @"Latitude delta is equal");
}
- (void)testMKCoordinateRegionForSouthWestAndNorthEast
{
CLLocationCoordinate2D taipeiWanHua = CLLocationCoordinate2DMake(25.02946, 121.49652);
CLLocationCoordinate2D taipeiSongShan = CLLocationCoordinate2DMake(25.06640, 121.56166);
/* When the following line is called, the first test fails */
MKCoordinateRegionForSouthWestAndNorthEast(taipeiWanHua, taipeiSongShan);
/* I have the rest of the lines in this test commented out */
}
지금,이 테스트 클래스 빈 설치 및 분해가 있습니다. 시험을 볼 때. 두 번째 테스트의 세 번째 줄이 테스트에 있으면 첫 번째 테스트가 실패합니다. 자세히 살펴보면 그것이 실패했을 때, 그 값이 여전히 주어진 정확도 비슷하지만 떨어지는 외부 있다는 있다고 보여줍니다
내가 두 번째 테스트 아웃의 세 번째 줄은, 첫 번째 테스트가 통과 것이라고 논평합니다. 왜 그런가요?
하는 BTW, 같은 일을 내가 첫 번째 테스트를 실행할 경우에도 발생합니다. =/ – huggie