This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public init(x: Int, y: Int, state: State) { | |
self.x = x | |
self.y = y | |
self.state = state | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Cell { | |
public let x: Int | |
public let y: Int | |
public var state: State | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum State { | |
case alive | |
case dead | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testRetrieveProductsValidResponse() { | |
// we have a locally stored product list in JSON format to test against. | |
let testBundle = Bundle(forClass: type(of: self)) | |
let filepath = testBundle.pathForResource("products", ofType: "txt") | |
let data = Data(contentsOfFile: filepath!) | |
let urlResponse = HTTPURLResponse(url: URL(string: "https://anyurl.doesntmatter.com")!, statusCode: 200, httpVersion: nil, headerFields: nil) | |
// setup our mock response with the above data and fake response. | |
MockSession.mockResponse = (data, urlResponse: urlResponse, error: nil) | |
let requestsClass = RequestManager() | |
// All our network calls are in here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockTask: URLSessionDataTask { | |
typealias Response = (data: Data?, URLResponse: URLResponse?, error: Error?) | |
var mockResponse: Response | |
let completionHandler: ((Data?, URLResponse?, Error?) -> Void)? | |
init(response: Response, completionHandler: ((Data?, URLResponse?, Error?) -> Void)?) { | |
self.mockResponse = response | |
self.completionHandler = completionHandler | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockSession: URLSession { | |
var completionHandler: ((Data, URLResponse, Error) -> Void)? | |
static var mockResponse: (data: Data?, URLResponse: URLResponse?, error: Error?) | |
override class var shared: URLSession { | |
return MockSession() | |
} | |