average.lua 592 B

123456789101112131415
  1. describe('average', function()
  2. it('errors when its parent errors', function()
  3. local _, onError = observableSpy(Rx.Observable.throw():average())
  4. expect(#onError).to.equal(1)
  5. end)
  6. it('produces a single value representing the average of the values produced by the source', function()
  7. expect(Rx.Observable.fromRange(3, 9, 2):average()).to.produce(6)
  8. expect(Rx.Observable.fromTable({-1, 0, 1}):average()).to.produce(0)
  9. end)
  10. it('produces nothing if there are no values to average', function()
  11. expect(Rx.Observable.empty():average()).to.produce.nothing()
  12. end)
  13. end)