Skip to content

Instantly share code, notes, and snippets.

View Serchinastico's full-sized avatar
👋

Sergio Gutiérrez Serchinastico

👋
View GitHub Profile
@Serchinastico
Serchinastico / DI.swift
Created September 13, 2017 09:49
Inyectando código
class SuperHeroDetailViewControllerTests: XCTestCase {
private let repository = MockSuperHeroesRepository()
/* ... */
private func openSuperHeroDetailViewController(_ superHeroName: String) {
let superHeroDetailViewController = ServiceLocator()
.provideSuperHeroDetailViewController(superHeroName) as! SuperHeroDetailViewController
superHeroDetailViewController.presenter = SuperHeroDetailPresenter(ui: superHeroDetailViewController,
@Serchinastico
Serchinastico / DI - Snapshot.swift
Created September 15, 2017 08:29
Doing dependency injection for our tests
class SuperHeroDetailViewControllerTests: XCTestCase {
private let repository = MockSuperHeroesRepository()
/* ... */
private func openSuperHeroDetailViewController(_ superHeroName: String) -> UIViewController {
let superHeroDetailViewController = ServiceLocator()
.provideSuperHeroDetailViewController(superHeroName) as! SuperHeroDetailViewController
superHeroDetailViewController.presenter = SuperHeroDetailPresenter(ui: superHeroDetailViewController,
@Serchinastico
Serchinastico / SuperHeroesControlsViewControllerTests.swift
Created September 27, 2017 17:13
Clase de test que muestra cómo usar KIF para interactuar con todo tipo de vistas
class SuperHeroesControlsViewControllerTests: AcceptanceTestCase {
func testShowsEmptyCaseIfThereAreNoSuperHeroes() {
openSuperHeroesViewController()
tester().tapView(withAccessibilityLabel: "Button")
tester().setValue(0, forSliderWithAccessibilityLabel: "Slider")
for _ in (0..<10) {
@Serchinastico
Serchinastico / SuperHeroControlsViewController.swift
Last active January 17, 2018 20:16
View controller sobre el que haremos las pruebas de las acciones con KIF
// --------------------------------------------- //
// -------------- VIEW CONTROLLER -------------- //
// --------------------------------------------- //
import UIKit
class SuperHeroControlsViewController: UIViewController {
var textField: UITextField!
var slider: UISlider!
@Serchinastico
Serchinastico / .gitconfig
Last active June 5, 2018 17:12
Alias for easier git rebase --onto
[alias]
# ronto stands for "rebase --onto". Uses the current branch to move it and updates the start-of-the-branch tag along
ronto = "!f() { \
git rebase --onto $1 __start__$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --abbrev-ref HEAD); \
git tag -d __start__$(git rev-parse --abbrev-ref HEAD); \
git tag __start__$(git rev-parse --abbrev-ref HEAD) $1; \
}; f"
# nb stands for "create branch". Creates a tag marking the start-of-the-branch
cb = "!f() { \
git tag __start__$1; \
@Serchinastico
Serchinastico / fizzbuzz.kt
Created September 11, 2018 09:13
Tail recursive FizzBuzz in kotlin
tailrec fun fizzbuzz(vararg args: Int) {
if (args.isEmpty()) return
val arg = args[0]
when {
arg % 15 == 0 -> print("FizzBuzz")
arg % 3 == 0 -> print("Fizz")
arg % 5 == 0 -> print("Buzz")
}
@Serchinastico
Serchinastico / sum.kt
Created September 11, 2018 13:07
Nullability exercise
fun sum1(a: Int?, b: Int?): Int {
b ?: return 0
return if (a != null) {
a + b
} else {
5 + b
}
}
@Serchinastico
Serchinastico / Product.kt
Created September 12, 2018 13:27
Classes exercise in kotlin
abstract class Product(
val id: String
) {
abstract val name: String
abstract var priceInEuros: Int
var priceInDollars: Int
get() = (priceInEuros * 1.06).toInt()
set(value) {
priceInEuros = (value / 1.06).toInt()
}
@Serchinastico
Serchinastico / interfaces.kt
Created September 12, 2018 13:28
Interfaces exercise in kotlin
interface Sellable {
var priceInEuros: Int
var priceInDollars: Int
get() = (priceInEuros * 1.06).toInt()
set(value) {
priceInEuros = (value / 1.06).toInt()
}
}
interface Describable {
@Serchinastico
Serchinastico / rocket_league.kt
Created September 14, 2018 14:19
Rocket League exercise
sealed class Vinyl {
object Skull : Vinyl()
data class Angels(val numberOfAngels: Int) : Vinyl()
data class Flowers(val numberOfFlowers: Int) : Vinyl()
data class Guns(val label: String) : Vinyl()
object Boots : Vinyl()
}
typealias Flag = Color