Permalink
Browse files

Added some more tests.

  • Loading branch information...
1 parent 3517544 commit fc25291d81668a77ec39ee7f1ac5f1f25aa35387 Zac White committed Oct 14, 2009
Showing with 55 additions and 3 deletions.
  1. +5 −2 ARKitDemo/Classes/ARCoordinate.m
  2. +1 −1 ARKitDemo/Classes/ARKitDemoAppDelegate.m
  3. +4 −0 ARKitDemo/LogicTests.h
  4. +45 −0 ARKitDemo/LogicTests.m
@@ -27,7 +27,7 @@ + (ARCoordinate *)coordinateWithRadialDistance:(double)newRadialDistance inclina
}
- (NSUInteger)hash{
- return [self.title hash];
+ return ([self.title hash] ^ [self.subtitle hash]) + (int)(self.radialDistance + self.inclination + self.azimuth);
}
- (BOOL)isEqual:(id)other {
@@ -44,7 +44,10 @@ - (BOOL)isEqualToCoordinate:(ARCoordinate *)otherCoordinate {
BOOL equal = self.radialDistance == otherCoordinate.radialDistance;
equal = equal && self.inclination == otherCoordinate.inclination;
equal = equal && self.azimuth == otherCoordinate.azimuth;
- equal = equal && [self.title isEqualToString:otherCoordinate.title];
+
+ if (self.title && otherCoordinate.title || self.title && !otherCoordinate.title || !self.title && otherCoordinate.title) {
+ equal = equal && [self.title isEqualToString:otherCoordinate.title];
+ }
return equal;
}
@@ -22,7 +22,7 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
viewController.delegate = self;
- //viewController.scaleViewsBasedOnDistance = YES;
+ viewController.scaleViewsBasedOnDistance = YES;
viewController.minimumScaleFactor = .5;
viewController.rotateViewsBasedOnPerspective = YES;
@@ -26,6 +26,10 @@
@end
+@interface LogicTests (ARCoordinateTests)
+- (void)testCoordinateEqual;
+@end
+
@interface LogicTests (ARViewControllerTests)
- (void)testViewportContainsCenter;
@end
@@ -25,6 +25,51 @@ @implementation LogicTests (ARGeoCoordinateTests)
@implementation LogicTests (ARCoordinateTests)
+
+- (void)testCoordinateEqual {
+
+ ARCoordinate *coordinate1 = [[ARCoordinate alloc] init];
+ ARCoordinate *coordinate2 = [[ARCoordinate alloc] init];
+
+ coordinate1.azimuth = coordinate2.azimuth = 10.0;
+ coordinate1.inclination = coordinate2.inclination = 10.0;
+ coordinate1.radialDistance = coordinate2.radialDistance = 10.0;
+ coordinate1.title = coordinate2.title = @"Testing";
+
+ STAssertTrue([coordinate1 isEqualToCoordinate:coordinate2], @"Coordinates with the same values aren't equal.");
+
+ STAssertTrue([coordinate1 isEqualToCoordinate:coordinate2] == [coordinate2 isEqualToCoordinate:coordinate1], @"Coordinate 1 == Coordinate 2 but Coordinate 2 != Coordinate 1");
+
+ coordinate1.title = @"";
+ coordinate2.title = @"a";
+
+ STAssertFalse([coordinate1 isEqualToCoordinate:coordinate2], @"Coordinates with different titles are considered equal.");
+
+ coordinate1.title = nil;
+ coordinate2.title = @"a";
+
+ STAssertFalse([coordinate1 isEqualToCoordinate:coordinate2], @"Coordaintes with one nil title are considered equal.");
+
+ coordinate1.title = nil;
+ coordinate2.title = nil;
+
+ STAssertTrue([coordinate1 isEqualToCoordinate:coordinate2], @"Coordinates with nil titles aren't equal.");
+}
+
+- (void)testCoordinateFactor {
+ ARCoordinate *coordinate1 = [ARCoordinate coordinateWithRadialDistance:10.0
+ inclination:10.0
+ azimuth:10.0];
+
+ STAssertNotNil(coordinate1, @"Coordinate factor method failed to create an instance.");
+
+ ARCoordinate *coordinate2 = [ARCoordinate coordinateWithRadialDistance:10.0
+ inclination:10.0
+ azimuth:10.0];
+
+ STAssertTrue([coordinate1 isEqualToCoordinate:coordinate2], @"Coordinate factor method doesn't create equal instances.");
+}
+
@end
#pragma mark -

0 comments on commit fc25291

Please sign in to comment.