diff options
author | NicoleYarroch <nicole@livio.io> | 2019-03-11 09:29:55 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-03-11 09:29:55 -0400 |
commit | c3a6fb9b3054070644f49536b4b20bee9d1ea854 (patch) | |
tree | 0b06516d679e6c65f19b9a1a38d1c44fd2d75255 | |
parent | 22e8843f632d62932bb824729f51cfd68eddeb0c (diff) | |
download | sdl_ios-c3a6fb9b3054070644f49536b4b20bee9d1ea854.tar.gz |
Added conv. init to `SDLLocationCoordinate`
-rw-r--r-- | SmartDeviceLink/SDLLocationCoordinate.h | 19 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLocationCoordinate.m | 12 | ||||
-rw-r--r-- | SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationCoordinateSpec.m | 13 |
3 files changed, 38 insertions, 6 deletions
diff --git a/SmartDeviceLink/SDLLocationCoordinate.h b/SmartDeviceLink/SDLLocationCoordinate.h index 1bdf90672..abc0beefe 100644 --- a/SmartDeviceLink/SDLLocationCoordinate.h +++ b/SmartDeviceLink/SDLLocationCoordinate.h @@ -6,21 +6,30 @@ NS_ASSUME_NONNULL_BEGIN /** - Describes a coordinate on earth + * Describes a coordinate on earth */ @interface SDLLocationCoordinate : SDLRPCStruct /** - * Latitude of the location + * Convenience init for location coordinates * - * Required, Double -90 - 90 + * @param latitudeDegrees Latitude of the location + * @param longitudeDegrees Latitude of the location + * @return A SDLLocationCoordinate object + */ +- (instancetype)initWithLatitudeDegrees:(float)latitudeDegrees longitudeDegrees:(float)longitudeDegrees; + +/** + * Latitude of the location + * + * Required, Double -90 - 90 */ @property (copy, nonatomic) NSNumber<SDLFloat> *latitudeDegrees; /** - * Longitude of the location + * Latitude of the location * - * Required, Double -180 - 180 + * Required, Double -180 - 180 */ @property (copy, nonatomic) NSNumber<SDLFloat> *longitudeDegrees; diff --git a/SmartDeviceLink/SDLLocationCoordinate.m b/SmartDeviceLink/SDLLocationCoordinate.m index b0a733844..a5d1cdd3d 100644 --- a/SmartDeviceLink/SDLLocationCoordinate.m +++ b/SmartDeviceLink/SDLLocationCoordinate.m @@ -10,6 +10,18 @@ NS_ASSUME_NONNULL_BEGIN @implementation SDLLocationCoordinate +- (instancetype)initWithLatitudeDegrees:(float)latitudeDegrees longitudeDegrees:(float)longitudeDegrees { + self = [self init]; + if (!self) { + return nil; + } + + self.latitudeDegrees = @(latitudeDegrees); + self.longitudeDegrees = @(longitudeDegrees); + + return self; +} + - (void)setLongitudeDegrees:(NSNumber<SDLFloat> *)longitudeDegrees { [store sdl_setObject:longitudeDegrees forName:SDLRPCParameterNameLongitudeDegrees]; } diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationCoordinateSpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationCoordinateSpec.m index fbd001043..011c8f8e4 100644 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationCoordinateSpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationCoordinateSpec.m @@ -69,7 +69,18 @@ describe(@"Getter/Setter Tests", ^ { expect(testStruct.latitudeDegrees).to(beIdenticalTo(someLatitude)); }); }); - + + context(@"when init with initWithLatitudeDegrees:longitudeDegrees", ^{ + it(@"should get and set correctly", ^{ + float testLatitude = 34.5; + float testLongitude = 120.345; + SDLLocationCoordinate *testStruct = [[SDLLocationCoordinate alloc] initWithLatitudeDegrees:testLatitude longitudeDegrees:testLongitude]; + + expect(testStruct.latitudeDegrees).to(equal(testLatitude)); + expect(testStruct.longitudeDegrees).to(equal(testLongitude)); + }); + }); + context(@"when parameters are not set", ^{ beforeEach(^{ NSDictionary *initDict = @{ |