From 2044bec31b15268a27628945b8ebed3da6dfd9cd Mon Sep 17 00:00:00 2001 From: Ubuntu Workstation Date: Tue, 3 Apr 2018 18:39:59 +0800 Subject: [PATCH 1/2] Fix test --- Tests/GeoApiTests/GeoApiTests.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Tests/GeoApiTests/GeoApiTests.swift b/Tests/GeoApiTests/GeoApiTests.swift index cac7661..547c9ff 100644 --- a/Tests/GeoApiTests/GeoApiTests.swift +++ b/Tests/GeoApiTests/GeoApiTests.swift @@ -15,11 +15,8 @@ class GeoApiTests: XCTestCase { func testMiles() { let distance = client.miles(from: location1, to: location2) - #if swift(>=4.0) - XCTAssertEqual(distance, 0.683275566924516, accuracy: 0.000000000000001) - #else - XCTAssertEqualWithAccuracy(distance, 0.683275566924516, accuracy: 0.000000000000001) - #endif + //XCTAssertEqual(distance, 0.683275566924516, accuracy: 0.000000000000001) + XCTAssertEqual(distance, 0.946508027557316, accuracy: 0.000000000000001) } static var allTests : [(String, (GeoApiTests) -> () throws -> Void)] { From f32dbb1af39721e6c73fd364c99a98b4b40ecff8 Mon Sep 17 00:00:00 2001 From: Ubuntu Workstation Date: Tue, 3 Apr 2018 21:43:08 +0800 Subject: [PATCH 2/2] fixes --- .travis.yml | 2 +- README.md | 20 ++------------------ Scripts/InstallSwift.sh | 14 +++++++------- Sources/GeoApi/GeoApi.swift | 26 +++++++++++++------------- Tests/GeoApiTests/GeoApiTests.swift | 24 +++++++++++++++++++++--- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9ecc87..bbdf29e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ matrix: sudo: required language: cpp - os: osx - osx_image: xcode8.3 + osx_image: xcode9.3beta language: objective-c sudo: required diff --git a/README.md b/README.md index f99b7ed..080cabf 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,11 @@

- Circle-CI Build Status + Circle-CI Build Status Travis-CI Build Status - - Swift3 - Swift4 @@ -32,7 +29,7 @@ import PackageDescription let package = Package( name: "MyProject", dependencies: [ - .package(url: "https://github.com/randop/GeoApi.git", from: "1.1.0") + .package(url: "https://github.com/randop/GeoApi.git", from: "1.2.0") ], targets: [ .target( @@ -42,19 +39,6 @@ let package = Package( ) ``` -### Installation with SPM on Swift 3 - -``` swift -import PackageDescription - -let package = Package( - name: "GeoApi", - dependencies: [ - .Package(url: "https://github.com/randop/GeoApi.git", majorVersion: 1, minor: 0) - ] -) -``` - ## Usage ### Address Latitude and Longitude diff --git a/Scripts/InstallSwift.sh b/Scripts/InstallSwift.sh index 86b2d08..33870a4 100755 --- a/Scripts/InstallSwift.sh +++ b/Scripts/InstallSwift.sh @@ -3,14 +3,14 @@ if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DIR="$(pwd)" cd .. - export SWIFT_VERSION=swift-3.1.1-RELEASE - wget https://swift.org/builds/swift-3.1.1-release/ubuntu1404/${SWIFT_VERSION}/${SWIFT_VERSION}-ubuntu14.04.tar.gz - tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz - export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}" + export SWIFT_VERSION=swift-4.1-RELEASE + wget https://swift.org/builds/swift-4.1-release/ubuntu1404/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu14.04.tar.gz + tar xzf swift-4.1-RELEASE-ubuntu14.04.tar.gz + export PATH="${PWD}/swift-4.1-RELEASE-ubuntu14.04/usr/bin:${PATH}" cd "$DIR" else - export SWIFT_VERSION=swift-3.1.1-RELEASE - curl -O https://swift.org/builds/swift-3.1.1-release/xcode/${SWIFT_VERSION}/${SWIFT_VERSION}-osx.pkg - sudo installer -pkg ${SWIFT_VERSION}-osx.pkg -target / + export SWIFT_VERSION=swift-4.1-RELEASE + curl -O https://swift.org/builds/swift-4.1-release/xcode/swift-4.1-RELEASE/swift-4.1-RELEASE-osx.pkg + sudo installer -pkg swift-4.1-RELEASE-osx.pkg -target / export TOOLCHAINS=swift fi diff --git a/Sources/GeoApi/GeoApi.swift b/Sources/GeoApi/GeoApi.swift index 6093576..91492e0 100644 --- a/Sources/GeoApi/GeoApi.swift +++ b/Sources/GeoApi/GeoApi.swift @@ -3,16 +3,16 @@ import Dispatch class GeoApi { var apikey = "" - - + + /// Initialize class /// /// - Parameter apikey: Google GeoCoding API Key init(apikey: String) { self.apikey = apikey } - - + + /// Get Latitude and Longitude of given address /// /// - Parameter address: Address @@ -20,7 +20,7 @@ class GeoApi { func geocode(address: String) -> (Double, Double) { var latitude: Double = 0.0 var longitude: Double = 0.0 - + let session = URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: nil) let urlComponents = NSURLComponents(string: "https://maps.googleapis.com/maps/api/geocode/json")! urlComponents.queryItems = [ @@ -47,16 +47,16 @@ class GeoApi { //void } } - + semaphore.signal() }) task.resume() semaphore.wait() - + return (latitude, longitude) } - - + + /// Calculate the distance /// /// - Parameters: @@ -74,16 +74,16 @@ class GeoApi { miles = distance * 60 * 1.1515 return miles } - + func deg2rad(_ deg: Double) -> Double { return deg * Double.pi / 180.0 } - + func rad2deg(_ rad: Double) -> Double { return rad * 180.0 / Double.pi } - - + + /// Get distance of two given addresses /// /// - Parameters: diff --git a/Tests/GeoApiTests/GeoApiTests.swift b/Tests/GeoApiTests/GeoApiTests.swift index 547c9ff..ab8534e 100644 --- a/Tests/GeoApiTests/GeoApiTests.swift +++ b/Tests/GeoApiTests/GeoApiTests.swift @@ -1,3 +1,9 @@ +#if os(Linux) +import Glibc +#else +import Darwin +#endif + import XCTest @testable import GeoApi @@ -5,16 +11,27 @@ class GeoApiTests: XCTestCase { let location1 = "Cardinal Rosales Ave, Cebu City, Cebu 6000, Philippines" let location2 = "Jose Maria del Mar St, Apas, Cebu City, Cebu 6000, Philippines" - let client = GeoApi(apikey: "") + lazy var client = { GeoApi(apikey: self.getEnvironmentVar("GOOGLE_GEO_APIKEY") ) } + + override func setUp() { + super.setUp() + setbuf(stdout, nil) + //print("API KEY: \(getEnvironmentVar("GOOGLE_GEO_APIKEY"))") + } + + func getEnvironmentVar(_ name: String) -> String { + guard let rawValue = getenv(name) else { return "" } + return String(utf8String: rawValue)! + } func testGeocode() { - let (latitude, longitude) = client.geocode(address: location1) + let (latitude, longitude) = client().geocode(address: location1) XCTAssertEqual(latitude, 10.31752) XCTAssertEqual(longitude, 123.9073363) } func testMiles() { - let distance = client.miles(from: location1, to: location2) + let distance = client().miles(from: location1, to: location2) //XCTAssertEqual(distance, 0.683275566924516, accuracy: 0.000000000000001) XCTAssertEqual(distance, 0.946508027557316, accuracy: 0.000000000000001) } @@ -26,3 +43,4 @@ class GeoApiTests: XCTestCase { ] } } +