This file contains hidden or 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
import Foundation | |
import XCTest | |
class Vehicle { | |
private var wheels = [Wheel]() | |
func add(_ wheel : Wheel) { | |
wheels.append(wheel) | |
} | |
} |
This file contains hidden or 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 testsForVehicle: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
} | |
func testVehicleIsNotRetained() { | |
var sut: Vehicle? = Vehicle() | |
let wheel1 = Wheel(vehicle: sut!) | |
sut!.add(wheel1) |
This file contains hidden or 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 Vehicle { | |
private var wheels = [Wheel]() | |
func add(_ wheel : Wheel) { | |
wheels.append(wheel) | |
} | |
} | |
class Wheel { | |
private var vehicle : Vehicle |
This file contains hidden or 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
print("Hello"[::-1]) |
This file contains hidden or 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
struct Pizza { | |
let id: Int | |
let size: Int | |
let type: PizzaType | |
let doughType: DoughType | |
let hasExtraIngredients: Bool | |
let extraIngredients: [String: Int] //Where the key is the ingredient and the value is the amount | |
let isBaked: Bool | |
let isDelivered: Bool | |
} |
This file contains hidden or 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
enum Pizza { | |
case preparePizza(id: Int, size: Int?, type: PizzaType, doughType: DoughType) | |
case addedExtras(id: Int, extras: [String:Int]) | |
case bakedPizza(id: Int) | |
case deliveredPizza(id: Int) | |
init(id: Int, size: Int?, type: PizzaType, doughType: DoughType) { | |
self = .preparePizza(id: id, size: size, type: type, doughType: doughType) | |
} | |
} |
This file contains hidden or 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
var isDelivered: Bool { | |
switch self { | |
case .preparePizza(id: _, size: _, type: _, doughType: _): | |
return false | |
case .addedExtras(id: _, extras: _): | |
return false | |
case .bakedPizza(id: _): | |
return false | |
case .deliveredPizza(id: _): | |
return true |
This file contains hidden or 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
mutating func addExtras(id: Int, extras: [String:Int]) { | |
switch self { | |
case .preparePizza(id: let id, size: _, type: _, doughType: _): | |
self = .addedExtras(id: id, extras: extras) | |
case .addedExtras(id: let id, extras: _): | |
self = .addedExtras(id: id, extras: extras) | |
case .bakedPizza(id: let id): | |
print("Cannot add extras to Piza \(id) at this phase") | |
case .deliveredPizza(id: _): | |
print("Pizza \(id) must be baked before delivery") |
This file contains hidden or 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
var napolitana = Pizza(id: 0, size: 8, type: .napolitana, doughType: .thin) | |
print(napolitana.currentState) | |
napolitana.bakePizza() | |
print(napolitana.currentState) | |
napolitana.deliverPizza() | |
print(napolitana.currentState) |
This file contains hidden or 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
var csrf = require('csurf'); | |
var app = express(); | |
app.use(csrf()); | |
app.use(function(req, res, next) { | |
res.locals._csrf = req.csrfToken(); | |
next(); | |
}); |
OlderNewer