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 / 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())
@fabiothiroki
fabiothiroki / NearbyPlacesService.swift
Created January 23, 2018 01:51
NearbyPlaces Service
struct NearbyPlacesService {
private let placesDatasource: PlacesDatasource
private let userLocationDatasource: UserLocationDatasource
init(userLocationDatasource: UserLocationDatasource,
placesDatasource: PlacesDatasource) {
self.userLocationDatasource = userLocationDatasource
self.placesDatasource = placesDatasource
}
@fabiothiroki
fabiothiroki / PlacesService.swift
Created January 19, 2018 01:15
Places Service Inicial Implementation
struct PlacesService {
private let provider: MoyaProvider<PlacesApi>
init(provider: MoyaProvider<PlacesApi>) {
self.provider = provider
}
func placesAround(latitude: Double, longitude: Double) -> Observable<LocationPlaces> {
return self.provider.rx.request(.recommended(latitude: latitude,