Code Monkey home page Code Monkey logo

Comments (3)

eliekarouz avatar eliekarouz commented on July 28, 2024

Hi @beeth0ven , thanks for this proposal. I was thinking how you would be able to test effects/feedbacks?

from rxfeedback.swift.

beeth0ven avatar beeth0ven commented on July 28, 2024

Hi @eliekarouz, thanks for your interest.

Effects can be tested as before with TestScheduler:

  1. create TestScheduler
  2. create mocked effects
  3. create mocked events
  4. inject mocked effects and events to system
  5. assert output states

PlayCatch Test

let events = [
   "tm" : Event.throwToMachine,
   "th" : .throwToHuman,
]

let states = [
   "h" : State.humanHasIt,
   "m" : .machineHasIt
]

// 1. create `TestScheduler`
let scheduler = TestScheduler(initialClock: 0, resolution: resolution, simulateProcessingDelay: false)

//  2. create mocked effects
let mockedEffects: (PitchRequest) -> Observable<Event> = scheduler.mock(values: events) { _ -> String in
   return "----th"
};


// 3. create mocked events
let (
   inputEvents,
   expectedStates
   ) = (
   scheduler.parseEventsAndTimes(timeline: "------tm------tm------tm-------", values: events).first!,
   scheduler.parseEventsAndTimes(timeline: "h-----m---h---m---h---m---h----", values: states).first!
)

// 4. inject mocked effects and events to system
let observableSystem = ObservableSystem.create(
   initialState: State.humanHasIt,
   reduce: { (state: State, event: Event) -> State in
       switch event {
       case .throwToMachine:
           return .machineHasIt
       case .throwToHuman:
           return .humanHasIt
       }
},
   scheduler: scheduler
   )
   .reacted(request: { $0.machinePitching }, effects: mockedEffects)

let state = observableSystem.system([{ _ in scheduler.createHotObservable(inputEvents).asObservable() }])

let recordedState = scheduler.record(source: state)

scheduler.start()

// 5. assert output states
XCTAssertEqual(recordedState.events, expectedStates)

This example use MarbleTests which can be found in RxExample_iOSTests.

from rxfeedback.swift.

beeth0ven avatar beeth0ven commented on July 28, 2024

Hi there!

Long time no see, hoping every one is doing well. I missed all of you!

Things get evoluted after this proposal. I'm happy to see swift-composable-architecture use a similar pattern and become popular, that's pretty cool!

Then I tried to evolute this idea, and open source a library called love.dart 😄. Yeah it's written in dart since I developed flutter apps recently.

If you are still interested with this "operator pattern". Feel free to take a look. Feedback 😄 are also welcome!

Thank you!

Best Wishes!

from rxfeedback.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.