Authored by Hal Mueller

added another unit test to exercise the coordinate calculation bug

... ... @@ -30,7 +30,6 @@
WithLocation:initialCenter];
NSLog(@"contentView %@ mapView %@", contentView, mapView);
[contentView addSubview:mapView];
[NSThread sleepForTimeInterval:3.0];
}
-(void)tearDown {
... ... @@ -83,27 +82,28 @@
- (void)testMarkerCreation
{
CLLocationCoordinate2D markerPosition;
#define kNumberRows 1
#define kNumberColumns 5
#define kSpacing 2.0
NSUInteger nRows = 1;
NSUInteger nColumns = 8;
double columnSpacing = 2.0;
UIImage *markerImage = [UIImage imageNamed:@"marker-red.png"];
STAssertNotNil(markerImage, @"marker image did not load");
markerPosition.latitude = initialCenter.latitude - ((kNumberRows - 1)/2.0 * kSpacing);
STAssertNotNil(markerImage, @"testMarkerCreation marker image did not load");
markerPosition.latitude = initialCenter.latitude - ((nRows - 1)/2.0 * columnSpacing);
int i, j;
for (i = 0; i < kNumberRows; i++) {
markerPosition.longitude = initialCenter.longitude - ((kNumberColumns - 1)/2.0 * kSpacing);
for (j = 0; j < kNumberColumns; j++) {
markerPosition.longitude += kSpacing;
for (i = 0; i < nRows; i++) {
markerPosition.longitude = initialCenter.longitude - ((nColumns - 1)/2.0 * columnSpacing);
for (j = 0; j < nColumns; j++) {
markerPosition.longitude += columnSpacing;
NSLog(@"%f %f", markerPosition.latitude, markerPosition.longitude);
RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:markerImage];
STAssertNotNil(newMarker, @"testMarkerCreation marker creation failed");
#ifdef DEBUG
[newMarker setLatlon:markerPosition];
#endif
[mapView.contents.markerManager addMarker:newMarker
AtLatLong:markerPosition];
}
markerPosition.latitude += kSpacing;
markerPosition.latitude += columnSpacing;
}
#ifdef DEBUG
... ... @@ -116,6 +116,48 @@
screenPosition.y, screenPosition.x);
}
#endif
}
- (void)testMarkerCoordinates
{
CLLocationCoordinate2D markerPosition;
NSUInteger nColumns = 8;
double columnSpacing = 2.0;
UIImage *markerImage = [UIImage imageNamed:@"marker-red.png"];
markerPosition.latitude = initialCenter.latitude;
markerPosition.longitude = initialCenter.longitude - ((nColumns - 1)/2.0 * columnSpacing);
int j;
NSMutableArray *testMarkers = [NSMutableArray arrayWithCapacity:nColumns];
for (j = 0; j < nColumns; j++) {
markerPosition.longitude += columnSpacing;
NSLog(@"%f %f", markerPosition.latitude, markerPosition.longitude);
RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:markerImage];
[testMarkers addObject:newMarker];
#ifdef DEBUG
[newMarker setLatlon:markerPosition];
#endif
[mapView.contents.markerManager addMarker:newMarker
AtLatLong:markerPosition];
}
STAssertGreaterThan(columnSpacing, 0.0, @"this test requires positive columnSpacing");
#ifdef DEBUG
RMMarkerManager *mangler = [[mapView contents] markerManager];
[[mapView contents] moveBy:CGSizeMake(-5.0, 0.0)];
for (j = 1; j < nColumns; j++) {
RMMarker *leftMarker = [testMarkers objectAtIndex:j - 1];
RMMarker *rightMarker = [testMarkers objectAtIndex:j];
CGPoint leftScreenPosition = [mangler getMarkerScreenCoordinate:leftMarker];
CGPoint rightScreenPosition = [mangler getMarkerScreenCoordinate:rightMarker];
STAssertLessThan(leftScreenPosition.x, rightScreenPosition.x,
@"screen position calculation failed: left (%f, %f) right (%f, %f) mapped to left (%f, %f) right (%f, %f)",
leftMarker.latlon.longitude, leftMarker.latlon.latitude,
rightMarker.latlon.longitude, rightMarker.latlon.latitude,
leftScreenPosition.x, leftScreenPosition.y, rightScreenPosition.x, rightScreenPosition.y);
}
#endif
}
@end
... ...