Note that there are some explanatory texts on larger screens.

plurals
  1. POOne unit test affects another
    primarykey
    data
    text
    <p>I'm defining two functions:</p> <p>In <strong>mkgeometry_additions.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;MapKit/MapKit.h&gt; MKMapRect MKMapRectForCoordinateRegion(MKCoordinateRegion region); MKCoordinateRegion MKCoordinateRegionForSouthWestAndNorthEast(CLLocationCoordinate2D sw, CLLocationCoordinate2D ne); </code></pre> <p>In <strong>mkgeometry_additions.m</strong> (.m, even though they're c functions)</p> <pre><code>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); } </code></pre> <p>That's pretty much the entirety of the two files.</p> <p>In my unit test with XCTests:</p> <pre><code>- (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 */ } </code></pre> <p>Now, I have empty setup and teardown for this test class. When I run the test. The first test fails if the third line of the second test is in the test. A closer look shows that when it fails, it's that the values are still similar but falling outside of the given accuracy: <img src="https://i.stack.imgur.com/vIg1q.png" alt="enter image description here"></p> <p>If I commented that third line of the second test out, the first test would pass. Why is that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload