Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devGayuru' into devGayuru
Browse files Browse the repository at this point in the history
  • Loading branch information
gayuru committed Oct 20, 2019
2 parents d551a69 + 5c2a9db commit 7a72a71
Showing 1 changed file with 79 additions and 15 deletions.
94 changes: 79 additions & 15 deletions Travo-App/Travo-AppTests/Travo_RestRequest_Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,96 @@
//

import XCTest
import Alamofire
import SwiftyJSON

class Travo_RestRequest_Test: XCTestCase {

class Travo_RestRequest_Test: XCTestCase, Refresh {
func updateUI() {
// Leave empty
}
var request:RestRequest = RestRequest.init(lat: "", lng: "")

let categoryExample:String = "bar"
let lat:String = "-37.813629"
let lng:String = "144.963058"
let examplePlace:Place = Place.init(name: "testPlace", desc: "testDesc", location: "testLocation", address: "testAddr", imageURL: "testImg", openTime: "testTime", starRating: 3, weatherCondition: 250, categoryBelonging: ["bar"])
let examplePlaceAlt:Place = Place.init(name: "testPlaceAlt", desc: "testDescAlt", location: "testLocationAlt", address: "testAddrAlt", imageURL: "testImgAlt", openTime: "testTimeAlt", starRating: 4, weatherCondition: 250, categoryBelonging: ["bar"])



override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()

request.delegate = self
request.updateLocation(lat: lat, lng: lng)
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
request = RestRequest.init(lat: "", lng: "")
}

func testSortPlaces() {
/* Pre Condition : Request Places Array has 2 values
* Array[0] has a lower rating than Array[1]
* Both Place objects belong to the same category that is being sorted
*/
request.updatePlaceArr(place: examplePlace, weather: examplePlace.weatherCondition)
request.updatePlaceArr(place: examplePlaceAlt, weather: examplePlaceAlt.weatherCondition)

// Action : sorts the Array from Highest to Lowest Ratings
let sortedPlaces:[Place] = request.sortPopularity(category: categoryExample)

func testNumberOfPlaces() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.

// Expected Result: Place with Higher Rating has a lower Index that the other
XCTAssert(sortedPlaces[0].name != examplePlace.name &&
sortedPlaces[0].starRating >= sortedPlaces[1].starRating &&
sortedPlaces[0].starRating == examplePlaceAlt.starRating &&
sortedPlaces[1].starRating == examplePlace.starRating)
}

func testInsertPlace() {
/* Pre Condition : Request Place Array has 0 values
* RestRequest is initialized in the the header
*/

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
// Action : inserts a valid Place into the Place Array
request.updatePlaceArr(place: examplePlace, weather: examplePlace.weatherCondition)

// Expected Result: Place Array contains 1 Place object and it is the object inserted
XCTAssert(request.places.count == 1 &&
request.places[0].name == examplePlace.name)
}

func testParsePlaceJSON() {
/* Pre Condition : Request Place Array has 0 values
* RestRequest is initialized in the the header
* Valid JSON containing basic key value pairs for a place
*/
let jsonDictionary:[String:Any] = ["name":"location"]

// Action : convert [String:Any] into a JSON Object
let json = JSON(jsonDictionary)
// Action : decomposes JSON into Place Object
let placeObject = request.getPlaceObject(p: json)

// Expected Result: Place Object Created with Given Values
XCTAssert(placeObject.name == "location")
}

func testFailedParsePlaceJSON() {
/* Pre Condition : Request Place Array has 0 values
* RestRequest is initialized in the the header
* Invalid JSON containing junk key value pairs for a place
*/
let jsonDictionary:[String:Any] = ["junk":10000]

// Action : convert [String:Any] into a JSON Object
let json = JSON(jsonDictionary)
// Action : decomposes JSON into Place Object
let placeObject = request.getPlaceObject(p: json)

// Expected Result: Place Object Created with Default Values for safety
XCTAssert(placeObject.name == "Place name" &&
placeObject.desc == "No available description" &&
placeObject.starRating == 0.0)
}

}

0 comments on commit 7a72a71

Please sign in to comment.