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
extension NetworkAdapter { | |
public func requestServiceSuccess(url: String, method: RequestMethod = .GET, success: SuccessCallback = nil, fail: FailCallback = nil){ | |
let path = "Sources/data/response.json" | |
let fileManager = FileManager() | |
if let content = fileManager.contents(atPath: path), | |
let successCallback = success { | |
successCallback(content) | |
} | |
} | |
public func requestServiceFail(url: String, method: RequestMethod = .GET, success: SuccessCallback = nil, fail: FailCallback = nil ) { |
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 MockUserActions: UserActionProtocol { | |
private var totalLogin: Int = 0 | |
private var totalRegister: Int = 0 | |
func login(nick: String, password: String) { | |
self.totalLogin += 1 | |
} | |
func register(email: String, nick: String, password: String) { | |
self.totalRegister += 1 |
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 UserActions: UserActionProtocol { | |
func login(nick: String, password: String) { | |
// consultando a mi servicio original | |
} | |
func register(email: String, nick: String, password: String) { | |
// registrando a mi servicio original | |
} | |
} |
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
protocol UserActionProtocol { | |
func login(nick: String, password: String) | |
func register(email: String, nick: String, password: String) | |
} |
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
// Implementación que retorna un contenido fijo a diferencia de la Función original | |
// Cobertura para el escenario satisfactorio o success | |
func getRemoteInfoSuccess(success: @escaping([String: Any]) -> Void, fail: @escaping(Error) -> Void ) { | |
// Definimos una variable como mock | |
let json: [String: Any] = { | |
"name": "Luke SkyWalker of Mocker" | |
} | |
success(json) | |
} |
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
// Función original | |
func getRemoteInfo(success: @escaping([String: Any]) -> Void, fail: @escaping(Error) -> Void ) { | |
let url = URL(string: "http://swapi.co/api/people/1/")! | |
var request = URLRequest(url: url) | |
request.httpMethod = "GET" | |
let sessionConf = URLSessionConfiguration.default | |
let urlSession = URLSession( | |
configuration: sessionConf, | |
delegate: nil, | |
delegateQueue: nil |
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
// Implementación que retorna un valor fijo a diferencia de la Función original | |
func randomNumber(min: Int, max: Int) -> Int { | |
return 10 | |
} | |
let myNumber = randomNumber(min: 5, max: 31) //retornará siempre 10 |
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
// Función original | |
func randomNumber(min: Int, max: Int) -> Int { | |
// implementación original | |
return min + Int(arc4random_uniform(UInt32(max - min + 1))) | |
} | |
let myNumber = randomNumber(min: 5, max: 31) //retorna un número aleatorio |
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 printFonts() { | |
let fontFamilyNames = UIFont.familyNames | |
for familyName in fontFamilyNames { | |
print("------------------------------") | |
print("Font Family Name = [\(familyName)]") | |
let names = UIFont.fontNames(forFamilyName: familyName) | |
print("Font Names = [\(names)]") | |
} | |
} |
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
import math | |
import pygame | |
import numpy as np | |
class Car(pygame.sprite.Sprite): | |
def __init__(self, surface): | |
self.bounded_rect = surface.get_rect() | |
super(Car, self).__init__() |