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
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
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 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 func isNeighbor(to cell: Cell) -> Bool { | |
let xDelta = abs(self.x - cell.x) | |
let yDelta = abs(self.y - cell.y) | |
switch (xDelta, yDelta) { | |
case (1, 1), (0, 1), (1, 0): | |
return true | |
default: | |
return false |
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
let firstCell = Cell(x: 10, y: 10, state: .dead) | |
let secondCell = Cell(x: 11, y: 11, state: .dead) | |
print(firstCell.isNeighbor(to: secondCell)) | |
// true - Adjacent row, adjacent column. |