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
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; |
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 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) |
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
struct AppReducer { | |
fileprivate let nearbyPlacesService: NearbyPlacesService | |
fileprivate let disposeBag = DisposeBag() | |
init(_ nearbyPlacesService: NearbyPlacesService) { | |
self.nearbyPlacesService = nearbyPlacesService | |
} | |
func reduce(action: Action, state: FetchedPlacesState?) -> FetchedPlacesState { |
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
struct FetchPlacesAction: Action {} | |
struct SetPlacesAction: Action, Equatable { | |
let places: LocationPlaces | |
static func == (lhs: SetPlacesAction, rhs: SetPlacesAction) -> Bool { | |
return lhs.places == rhs.places | |
} | |
} |
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
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): |
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 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() |
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
struct UserLocationServiceMock: UserLocationDatasource { | |
let location = CLLocation.init(latitude: -23.5666151, longitude: -46.6463977) | |
func getUserLocation() -> Observable<CLLocation> { | |
return Observable.from(optional: location) | |
} | |
} |
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 PlacesApiMock: PlacesDatasource { | |
var requestedLatitude: Double? | |
var requestedLongitude: Double? | |
func placesAround(latitude: Double, longitude: Double) -> Observable<LocationPlaces> { | |
requestedLatitude = latitude | |
requestedLongitude = longitude | |
return Observable.of(LocationPlaces()) |
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
struct NearbyPlacesService { | |
private let placesDatasource: PlacesDatasource | |
private let userLocationDatasource: UserLocationDatasource | |
init(userLocationDatasource: UserLocationDatasource, | |
placesDatasource: PlacesDatasource) { | |
self.userLocationDatasource = userLocationDatasource | |
self.placesDatasource = placesDatasource | |
} |
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
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, |
NewerOlder