Skip to content

Instantly share code, notes, and snippets.

View fabiothiroki's full-sized avatar
👋

Fabio Hiroki fabiothiroki

👋
View GitHub Profile
package br.com.quintoandar.classifier;
import lombok.val;
import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.DefaultDataset;
import net.sf.javaml.core.Instance;
import net.sf.javaml.distance.CosineDistance;
import net.sf.javaml.tools.InstanceTools;
import org.junit.Test;
@fabiothiroki
fabiothiroki / UserLocationServiceFinal.swift
Created January 3, 2018 01:41
Final version of UserLocationService
import CoreLocation
import RxSwift
protocol LocationManager {
var delegate: CLLocationManagerDelegate? { get set }
func requestWhenInUseAuthorization()
func requestLocation()
}
extension CLLocationManager: LocationManager {}
@fabiothiroki
fabiothiroki / UserLocationServiceSpec.swift
Last active March 9, 2018 22:57
UserLocationService tests
func testShouldProvideLocation() {
let mockLocation = CLLocation.init(latitude: -23.5666151, longitude: -46.6463977)
let locationStream = userLocationService.getUserLocation()
locationStream.subscribe(onNext: { (location) in
XCTAssertEqual(mockLocation, location)
}, onError: { (_) in
XCTFail("Should not return error")
}).disposed(by: disposeBag)
@fabiothiroki
fabiothiroki / AppReducerSpec.swift
Created February 12, 2018 19:04
Reducer tests
class AppReducerSpec: XCTestCase {
func testShouldReturnInitialState() {
let newState = reducer.reduce(action: FetchPlacesAction(), state: nil)
XCTAssertEqual(newState, FetchedPlacesState(places: .loading))
}
func testShouldChangeStateAfterSuccessfulRequest() {
let places = LocationPlaces()
let action = SetPlacesAction.init(places: places)
struct AppReducer {
fileprivate let nearbyPlacesService: NearbyPlacesService
fileprivate let disposeBag = DisposeBag()
init(_ nearbyPlacesService: NearbyPlacesService) {
self.nearbyPlacesService = nearbyPlacesService
}
func reduce(action: Action, state: FetchedPlacesState?) -> FetchedPlacesState {
struct FetchPlacesAction: Action {}
struct SetPlacesAction: Action, Equatable {
let places: LocationPlaces
static func == (lhs: SetPlacesAction, rhs: SetPlacesAction) -> Bool {
return lhs.places == rhs.places
}
}
enum Result {
case loading
case failed
case finished(LocationPlaces)
}
extension Result: Equatable {
static func == (lhs: Result, rhs: Result) -> Bool {
switch (lhs, rhs) {
case (.loading, .loading):
@fabiothiroki
fabiothiroki / NearbyPlacesServiceSpec.swift
Created January 23, 2018 21:52
NearbyPlacesServiceSpec
class NearbyPlacesServiceSpec: XCTestCase {
private var container: Container!
private var placesDatasource: PlacesApiMock!
private var userLocationDatasource: UserLocationServiceMock!
private var nearbyPlacesService: NearbyPlacesService!
private let disposeBag = DisposeBag()
override func setUp() {
super.setUp()
@fabiothiroki
fabiothiroki / UserLocationServiceMock.swift
Last active January 23, 2018 21:47
User Location Service Mock
struct UserLocationServiceMock: UserLocationDatasource {
let location = CLLocation.init(latitude: -23.5666151, longitude: -46.6463977)
func getUserLocation() -> Observable<CLLocation> {
return Observable.from(optional: location)
}
}
@fabiothiroki
fabiothiroki / PlacesApiMock.swift
Created January 23, 2018 01:58
Places Api Mock
class PlacesApiMock: PlacesDatasource {
var requestedLatitude: Double?
var requestedLongitude: Double?
func placesAround(latitude: Double, longitude: Double) -> Observable<LocationPlaces> {
requestedLatitude = latitude
requestedLongitude = longitude
return Observable.of(LocationPlaces())