Skip to content

Commit ffd95e6

Browse files
committed
adds new tests, refactors old ones
1 parent 15bbea1 commit ffd95e6

File tree

1 file changed

+75
-47
lines changed

1 file changed

+75
-47
lines changed

EPMapExtensionsTests/EPMapViewTest.m

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@
1717
@implementation EPMapViewTest {
1818
EPMapView *_mapView;
1919
MKMapView *_innerMapView;
20+
NSArray *_testAnnotations;
21+
NSArray *_poiAnnotations;
2022
}
2123

2224
- (void)setUp
2325
{
2426
_mapView = [[EPMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
2527
_innerMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
28+
_testAnnotations = @[
29+
[[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
30+
addressDictionary:nil],
31+
[[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
32+
addressDictionary:nil],
33+
];
34+
_poiAnnotations = @[
35+
[[EPPointOfInterest alloc] initWithCoordinate:CLLocationCoordinate2DMake(46.12, 8.98)],
36+
];
2637
}
2738

2839
- (void)testMapViewInitializationWithFrame
@@ -47,15 +58,10 @@ - (void)testMapViewGetCenteredRegionWithNoAnnotationsInMap
4758
- (void)testMapViewGetCenteredRegionForAllAnnotations
4859
{
4960

50-
EPTestAnnotation *firstAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
51-
addressDictionary:nil];
52-
EPTestAnnotation *secondAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
53-
addressDictionary:nil];
61+
[_mapView addAnnotation:_testAnnotations[0]];
62+
[_mapView addAnnotation:_testAnnotations[1]];
5463

55-
[_mapView addAnnotation:firstAnnotation];
56-
[_mapView addAnnotation:secondAnnotation];
57-
58-
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08)/2, 7.67),
64+
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08) / 2, 7.67),
5965
MKCoordinateSpanMake(45.11 - 45.08, 0));
6066
MKCoordinateRegion centeredRegion = [_mapView centeredRegion];
6167

@@ -64,17 +70,11 @@ - (void)testMapViewGetCenteredRegionForAllAnnotations
6470

6571
- (void)testMapViewGetCenteredRegionForAnnotationConformingToProtocol
6672
{
67-
EPTestAnnotation *firstAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
68-
addressDictionary:nil];
69-
EPTestAnnotation *secondAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
70-
addressDictionary:nil];
71-
EPPointOfInterest *thirdAnnotation = [[EPPointOfInterest alloc] initWithCoordinate:CLLocationCoordinate2DMake(46.12, 8.98)];
72-
73-
[_mapView addAnnotation:firstAnnotation];
74-
[_mapView addAnnotation:secondAnnotation];
75-
[_mapView addAnnotation:thirdAnnotation];
73+
[_mapView addAnnotation:_testAnnotations[0]];
74+
[_mapView addAnnotation:_testAnnotations[1]];
75+
[_mapView addAnnotation:_poiAnnotations[0]];
7676

77-
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08)/2, 7.67),
77+
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08) / 2, 7.67),
7878
MKCoordinateSpanMake(45.11 - 45.08, 0));
7979
MKCoordinateRegion centeredRegion = [_mapView centeredRegionForAnnotationConformingToProtocol:@protocol(EPAnnotation)];
8080

@@ -83,15 +83,9 @@ - (void)testMapViewGetCenteredRegionForAnnotationConformingToProtocol
8383

8484
- (void)testMapViewGetCenteredRegionForAnnotationConformingProtocolReturningAnEmptyArray
8585
{
86-
EPTestAnnotation *firstAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
87-
addressDictionary:nil];
88-
EPTestAnnotation *secondAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
89-
addressDictionary:nil];
90-
EPPointOfInterest *thirdAnnotation = [[EPPointOfInterest alloc] initWithCoordinate:CLLocationCoordinate2DMake(46.12, 8.98)];
91-
92-
[_mapView addAnnotation:firstAnnotation];
93-
[_mapView addAnnotation:secondAnnotation];
94-
[_mapView addAnnotation:thirdAnnotation];
86+
[_mapView addAnnotation:_testAnnotations[0]];
87+
[_mapView addAnnotation:_testAnnotations[1]];
88+
[_mapView addAnnotation:_poiAnnotations[0]];
9589

9690
MKCoordinateRegion expectedCenteredRegion = [_mapView region];
9791
MKCoordinateRegion centeredRegion = [_mapView centeredRegionForAnnotationConformingToProtocol:nil];
@@ -100,18 +94,12 @@ - (void)testMapViewGetCenteredRegionForAnnotationConformingProtocolReturningAnEm
10094
}
10195

10296
- (void)testMapViewGetCenteredRegionForAnnotationOfKindOfClass
103-
{
104-
EPTestAnnotation *firstAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
105-
addressDictionary:nil];
106-
EPTestAnnotation *secondAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
107-
addressDictionary:nil];
108-
EPPointOfInterest *thirdAnnotation = [[EPPointOfInterest alloc] initWithCoordinate:CLLocationCoordinate2DMake(46.12, 8.98)];
97+
{
98+
[_mapView addAnnotation:_testAnnotations[0]];
99+
[_mapView addAnnotation:_testAnnotations[1]];
100+
[_mapView addAnnotation:_poiAnnotations[0]];
109101

110-
[_mapView addAnnotation:firstAnnotation];
111-
[_mapView addAnnotation:secondAnnotation];
112-
[_mapView addAnnotation:thirdAnnotation];
113-
114-
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08)/2, 7.67),
102+
MKCoordinateRegion expectedCenteredRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake((45.11 + 45.08) / 2, 7.67),
115103
MKCoordinateSpanMake(45.11 - 45.08, 0));
116104
MKCoordinateRegion centeredRegion = [_mapView centeredRegionForAnnotationOfKindOfClass:[EPTestAnnotation class]];
117105

@@ -120,21 +108,61 @@ - (void)testMapViewGetCenteredRegionForAnnotationOfKindOfClass
120108

121109
- (void)testMapViewGetCenteredRegionForAnnotationOfKindOfClassReturningAnEmptyArray
122110
{
123-
EPTestAnnotation *firstAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.11, 7.67)
124-
addressDictionary:nil];
125-
EPTestAnnotation *secondAnnotation = [[EPTestAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.08, 7.67)
126-
addressDictionary:nil];
127-
EPPointOfInterest *thirdAnnotation = [[EPPointOfInterest alloc] initWithCoordinate:CLLocationCoordinate2DMake(46.12, 8.98)];
128-
129-
[_mapView addAnnotation:firstAnnotation];
130-
[_mapView addAnnotation:secondAnnotation];
131-
[_mapView addAnnotation:thirdAnnotation];
111+
[_mapView addAnnotation:_testAnnotations[0]];
112+
[_mapView addAnnotation:_testAnnotations[1]];
113+
[_mapView addAnnotation:_poiAnnotations[0]];
132114

133115
MKCoordinateRegion expectedCenteredRegion = [_mapView region];
134116
MKCoordinateRegion centeredRegion = [_mapView centeredRegionForAnnotationOfKindOfClass:nil];
135117

136118
STAssertTrue(EPCoordinateRegionIsEqual(centeredRegion, expectedCenteredRegion), @"centered region should be centered around expectedCenteredRegion");
137119
}
138120

121+
- (void)testMapViewGetVisibleAnnotation
122+
{
123+
[_mapView addAnnotation:_testAnnotations[0]];
124+
[_mapView addAnnotation:_testAnnotations[1]];
125+
[_mapView addAnnotation:_poiAnnotations[0]];
126+
127+
[_mapView setRegion:[_mapView centeredRegion]];
128+
129+
STAssertTrue([_mapView visibleAnnotations] == 3, @"the visibleAnnotation within the visible mapView region should be 3");
130+
}
131+
132+
- (void)testMapViewGetVisibleAnnotationConformingToProtocol
133+
{
134+
[_mapView addAnnotation:_testAnnotations[0]];
135+
[_mapView addAnnotation:_testAnnotations[1]];
136+
[_mapView addAnnotation:_poiAnnotations[0]];
137+
138+
[_mapView setRegion:[_mapView centeredRegion]];
139+
140+
STAssertTrue([_mapView visibleAnnotationsConformingToProtocol:@protocol(EPAnnotation)] == 2,
141+
@"the visibleAnnotation within the visible mapView region should be 2");
142+
}
143+
144+
- (void)testMapViewGetVisibleAnnotationConformingToProtocolReturningAnEmptySet
145+
{
146+
[_mapView addAnnotation:_testAnnotations[0]];
147+
[_mapView addAnnotation:_testAnnotations[1]];
148+
[_mapView addAnnotation:_poiAnnotations[0]];
149+
150+
[_mapView setRegion:[_mapView centeredRegion]];
151+
152+
STAssertTrue([_mapView visibleAnnotationsConformingToProtocol:nil] == 0,
153+
@"the visibleAnnotation within the visible mapView region should be 0");
154+
}
155+
156+
- (void)testMapViewGetVisibleAnnotationConformingToRootProtocol
157+
{
158+
[_mapView addAnnotation:_testAnnotations[0]];
159+
[_mapView addAnnotation:_testAnnotations[1]];
160+
[_mapView addAnnotation:_poiAnnotations[0]];
161+
162+
[_mapView setRegion:[_mapView centeredRegion]];
163+
164+
STAssertTrue([_mapView visibleAnnotationsConformingToProtocol:@protocol(MKAnnotation)] == 3,
165+
@"the visibleAnnotation within the visible mapView region should be 3");
166+
}
139167

140168
@end

0 commit comments

Comments
 (0)